From a21d6a35c5a88b41c0d0bceff77a81008ef2c6d3 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Wed, 20 Sep 2023 08:23:42 -0700 Subject: [PATCH] Remove DiffNotApplicableException Let any IndexOutOfBoundsExceptions propagate, and handle RuntimeException in DiffApplier. See discussion in https://github.com/google/error-prone/pull/4086. PiperOrigin-RevId: 566971731 --- .../apply/DescriptionBasedDiff.java | 2 +- .../com/google/errorprone/apply/Diff.java | 6 +--- .../google/errorprone/apply/DiffApplier.java | 2 +- .../apply/DiffNotApplicableException.java | 32 ------------------- 4 files changed, 3 insertions(+), 39 deletions(-) delete mode 100644 check_api/src/main/java/com/google/errorprone/apply/DiffNotApplicableException.java diff --git a/check_api/src/main/java/com/google/errorprone/apply/DescriptionBasedDiff.java b/check_api/src/main/java/com/google/errorprone/apply/DescriptionBasedDiff.java index 8f9b5827be75..1c11b94ea06b 100644 --- a/check_api/src/main/java/com/google/errorprone/apply/DescriptionBasedDiff.java +++ b/check_api/src/main/java/com/google/errorprone/apply/DescriptionBasedDiff.java @@ -109,7 +109,7 @@ public void handleFix(Fix fix) { } @Override - public void applyDifferences(SourceFile sourceFile) throws DiffNotApplicableException { + public void applyDifferences(SourceFile sourceFile) { if (!importsToAdd.isEmpty() || !importsToRemove.isEmpty()) { ImportStatements importStatements = ImportStatements.create(compilationUnit, importOrganizer); importStatements.addAll(importsToAdd); diff --git a/check_api/src/main/java/com/google/errorprone/apply/Diff.java b/check_api/src/main/java/com/google/errorprone/apply/Diff.java index 5e469350ea48..56b287d6891d 100644 --- a/check_api/src/main/java/com/google/errorprone/apply/Diff.java +++ b/check_api/src/main/java/com/google/errorprone/apply/Diff.java @@ -25,10 +25,6 @@ public interface Diff { /** Gets the name of the file this difference applies to */ String getRelevantFileName(); - /** - * Applies this difference to the supplied {@code sourceFile}. - * - * @throws DiffNotApplicableException if the diff could not be applied to the source file - */ + /** Applies this difference to the supplied {@code sourceFile}. */ void applyDifferences(SourceFile sourceFile); } diff --git a/check_api/src/main/java/com/google/errorprone/apply/DiffApplier.java b/check_api/src/main/java/com/google/errorprone/apply/DiffApplier.java index 386d79d18759..525a07d7a810 100644 --- a/check_api/src/main/java/com/google/errorprone/apply/DiffApplier.java +++ b/check_api/src/main/java/com/google/errorprone/apply/DiffApplier.java @@ -123,7 +123,7 @@ public void run() { if (completed % 100 == 0) { logger.log(Level.INFO, String.format("Completed %d files in %s", completed, stopwatch)); } - } catch (IOException | DiffNotApplicableException e) { + } catch (IOException | RuntimeException e) { logger.log(Level.WARNING, "Failed to apply diff to file " + diff.getRelevantFileName(), e); diffsFailedPaths.add(diff.getRelevantFileName()); } finally { diff --git a/check_api/src/main/java/com/google/errorprone/apply/DiffNotApplicableException.java b/check_api/src/main/java/com/google/errorprone/apply/DiffNotApplicableException.java deleted file mode 100644 index b4ef8ad600c1..000000000000 --- a/check_api/src/main/java/com/google/errorprone/apply/DiffNotApplicableException.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2011 The Error Prone Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.errorprone.apply; - -/** Exception thrown if a {@link Diff} could not be applied by a {@link DiffApplier} */ -public class DiffNotApplicableException extends RuntimeException { - public DiffNotApplicableException(String msg) { - super(msg); - } - - public DiffNotApplicableException(String msg, Throwable cause) { - super(msg, cause); - } - - public DiffNotApplicableException(Throwable cause) { - super(cause); - } -}