From 9b2fe85c0279f4d5ac69f07ddcd48566c3555405 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Mon, 27 May 2024 18:22:29 +0200 Subject: [PATCH] PatchApplier.Result.Error: mark fields final Fields of an Error instance shouldn't be modifiable after its creation. Adapt tests which were setting hh to null to skip asserting it. Change-Id: I0f55c1d5cd529aa510029054e6f05bd2637d1bca --- .../org/eclipse/jgit/patch/PatchApplierTest.java | 14 ++++++-------- .../src/org/eclipse/jgit/patch/PatchApplier.java | 6 +++--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java index eec403a976..5507f8572d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/patch/PatchApplierTest.java @@ -373,10 +373,9 @@ public class PatchApplierTest { assertEquals(result.getErrors().size(), 1); PatchApplier.Result.Error error = result.getErrors().get(0); - error.hh = null; // We don't assert the hunk header as it is a - // complex object with lots of internal state. - assertEquals(error, new PatchApplier.Result.Error( - "cannot apply hunk", "allowconflict", null, true)); + assertEquals("cannot apply hunk", error.msg); + assertEquals("allowconflict", error.oldFileName); + assertTrue(error.isGitConflict()); verifyChange(result, "allowconflict", true, 1); } @@ -388,10 +387,9 @@ public class PatchApplierTest { assertEquals(result.getErrors().size(), 1); PatchApplier.Result.Error error = result.getErrors().get(0); - error.hh = null; // We don't assert the hunk header as it is a - // complex object with lots of internal state. - assertEquals(error, new PatchApplier.Result.Error( - "cannot apply hunk", "ConflictOutOfBounds", null, true)); + assertEquals("cannot apply hunk", error.msg); + assertEquals("ConflictOutOfBounds", error.oldFileName); + assertTrue(error.isGitConflict()); verifyChange(result, "ConflictOutOfBounds", true, 1); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/patch/PatchApplier.java b/org.eclipse.jgit/src/org/eclipse/jgit/patch/PatchApplier.java index 1a98d79f99..cb6cc6efa7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/patch/PatchApplier.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/patch/PatchApplier.java @@ -177,12 +177,12 @@ public class PatchApplier { // TODO(ms): rename this class in next major release @SuppressWarnings("JavaLangClash") public static class Error { - String msg; + final String msg; - String oldFileName; + final String oldFileName; @Nullable - HunkHeader hh; + final HunkHeader hh; final boolean isGitConflict; -- 2.39.5