]> source.dussan.org Git - jgit.git/commitdiff
[errorprone] Fix pattern CatchFail 18/1194018/3
authorMatthias Sohn <matthias.sohn@sap.com>
Sun, 28 Apr 2024 22:29:30 +0000 (00:29 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Mon, 29 Apr 2024 13:20:39 +0000 (15:20 +0200)
See https://errorprone.info/bugpattern/CatchFail

Change-Id: If1c637a420c4e669a5bdbe4abcefc5c3a2b3a43b

org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/FileResolverTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ThreadSafeProgressMonitorTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackHandleDeletedPackFileTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FileUtilsTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java
tools/BUILD

index 8d25c2e3954568bbf61d48a31469a38665817167..34c871ab06ffb51e23fe1779b03d1fd3f84d7494 100644 (file)
@@ -88,7 +88,7 @@ public class FileResolverTest extends LocalDiskRepositoryTestCase {
                try {
                        resolver.open(null, name).close();
                } catch (ServiceNotEnabledException e) {
-                       fail("did not honor export-all flag");
+                       throw new AssertionError("did not honor export-all flag", e);
                }
 
                FileUtils.createNewFile(export);
@@ -99,7 +99,7 @@ public class FileResolverTest extends LocalDiskRepositoryTestCase {
                try {
                        resolver.open(null, name).close();
                } catch (ServiceNotEnabledException e) {
-                       fail("did not honor git-daemon-export-ok");
+                       throw new AssertionError("did not honor git-daemon-export-ok", e);
                }
        }
 
index 987c98e232628970d2120b06796a777e595b2796..02e3a2e06fbc152e26f0cc9d29cd8ff8eb7c6ce5 100644 (file)
@@ -2650,7 +2650,9 @@ public class RebaseCommandTest extends RepositoryTestCase {
                        assertEquals("1111111", firstLine.getCommit().name());
                        assertEquals("pick", firstLine.getAction().toToken());
                } catch (Exception e) {
-                       fail("Valid parsable RebaseTodoLine that has been commented out should allow to change the action, but failed");
+                       throw new AssertionError(
+                                       "Valid parsable RebaseTodoLine that has been commented out should allow to change the action, but failed",
+                                       e);
                }
 
                assertEquals("2222222", steps.get(1).getCommit().name());
index 703d68b37c948d5b51a3701212915939b7d90de7..61801106afaf7162c4854f3e98dd9af80dae0a6b 100644 (file)
@@ -218,7 +218,7 @@ public class DirCacheBuilderTest extends RepositoryTestCase {
                try {
                        b.commit();
                } catch (ReceivedEventMarkerException e) {
-                       fail("unexpected IndexChangedEvent");
+                       throw new AssertionError("unexpected IndexChangedEvent", e);
                }
        }
 
index 7eab1dcb09a50d1b561b4f105900f0aa0b53fe3b..953d624bfe9cf44e76653cbd66c8c1eaf14710dd 100644 (file)
@@ -209,7 +209,8 @@ public class LockFileTest extends RepositoryTestCase {
                        lock.unlock();
                        lock.unlock();
                } catch (Throwable e) {
-                       fail("unlock should be noop if not locked at all.");
+                       throw new AssertionError(
+                                       "unlock should be noop if not locked at all.", e);
                }
        }
 }
index e21ff580bd5e5d68b84e9e3e48bd2c85e2676ccf..a5a6ce5d763d206ead313c87069807b36eb6a228 100644 (file)
@@ -125,7 +125,7 @@ public class ThreadSafeProgressMonitorTest {
                try {
                        assertTrue("latch released", cdl.await(1000, TimeUnit.MILLISECONDS));
                } catch (InterruptedException ie) {
-                       fail("Did not expect to be interrupted");
+                       throw new AssertionError("Did not expect to be interrupted", ie);
                }
        }
 
index 417ce61df2e929ee693893ffce89d4cbf1795f62..118eb984d08f011e5b0851bd603ad3a7d07697c1 100644 (file)
@@ -9,10 +9,9 @@
  */
 package org.eclipse.jgit.transport;
 
-import static org.junit.Assert.fail;
 import static org.eclipse.jgit.lib.Constants.HEAD;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.util.Arrays;
 import java.util.Collection;
@@ -107,7 +106,8 @@ public class UploadPackHandleDeletedPackFileTest
 
                                                pack.getPackFile().create(packExt).delete();
                                        } catch (Exception e) {
-                                               fail("GC or pack file removal failed");
+                                               throw new AssertionError(
+                                                               "GC or pack file removal failed", e);
                                        }
 
                                        return up;
index 2b1fb2ef04b36f1d92e7d43a3ddda039ff040c8b..5106540227e944b857366c56d50a214e20e6b76e 100644 (file)
@@ -74,7 +74,9 @@ public class FileUtilsTest {
                try {
                        FileUtils.delete(f, FileUtils.SKIP_MISSING);
                } catch (IOException e) {
-                       fail("deletion of non-existing file must not fail with option SKIP_MISSING");
+                       throw new AssertionError(
+                                       "deletion of non-existing file must not fail with option SKIP_MISSING",
+                                       e);
                }
        }
 
@@ -108,7 +110,9 @@ public class FileUtilsTest {
                try {
                        FileUtils.delete(d, FileUtils.RECURSIVE | FileUtils.SKIP_MISSING);
                } catch (IOException e) {
-                       fail("recursive deletion of non-existing directory must not fail with option SKIP_MISSING");
+                       throw new AssertionError(
+                                       "recursive deletion of non-existing directory must not fail with option SKIP_MISSING",
+                                       e);
                }
        }
 
index 1231aefee04c64fb39206045e5952fd77671c3a1..b7490f0b1f0039549e27a755c7c4ebf3c1e1c98d 100644 (file)
@@ -157,7 +157,7 @@ public class HookTest extends RepositoryTestCase {
                        git.commit().setMessage("commit")
                                        .setHookOutputStream(new PrintStream(out)).call();
                } catch (AbortedByHookException e) {
-                       fail("unexpected hook failure");
+                       throw new AssertionError("unexpected hook failure", e);
                }
                assertEquals("unexpected hook output",
                                "test pre-commit\ntest commit-msg .git/COMMIT_EDITMSG\ntest post-commit\n",
index 90db119b4c6213d2cbe04100b4e96058f0237035..22f6cf35711d27ca6dfc41d7a60654dc4f18d3e1 100644 (file)
@@ -76,7 +76,7 @@ java_package_configuration(
         "-Xep:CannotMockFinalClass:ERROR",
         "-Xep:CanonicalDuration:ERROR",
         "-Xep:CatchAndPrintStackTrace:WARN",
-        "-Xep:CatchFail:WARN",
+        "-Xep:CatchFail:ERROR",
         "-Xep:ChainedAssertionLosesContext:ERROR",
         "-Xep:ChainingConstructorIgnoresParameter:ERROR",
         "-Xep:CharacterGetNumericValue:ERROR",