]> source.dussan.org Git - jgit.git/commitdiff
[error prone] suppress AmbiguousMethodReference in AnyObjectId 67/147267/2
authorMatthias Sohn <matthias.sohn@sap.com>
Thu, 8 Aug 2019 13:09:46 +0000 (15:09 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 8 Aug 2019 21:39:23 +0000 (23:39 +0200)
Move the implementation of the static equals() method to a new method
and suppress the error. Deprecate the old method to signal that we
intend to remove it in the next major release.

See https://errorprone.info/bugpattern/AmbiguousMethodReference

Change-Id: I5e29c97f4db3e11770be589a6ccd785e2c9ac7f2
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
22 files changed:
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/VerifyReftable.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java
org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/api/RevertCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/KetchReplica.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/LagCheck.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/RemoteGitReplica.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/ketch/StageBuilder.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/ReftableBatchRefUpdate.java
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/UnpackedObjectCache.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/AnyObjectId.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectIdSubclassMap.java
org.eclipse.jgit/src/org/eclipse/jgit/lib/RefUpdate.java
org.eclipse.jgit/src/org/eclipse/jgit/notes/NoteMapMerger.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceiveCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/TrackingRefUpdate.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkFetchConnection.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/WalkPushConnection.java
org.eclipse.jgit/src/org/eclipse/jgit/util/RefMap.java

index af4cc1cb9b36aa79947ee571e1b1ea29263fb30a..e89cf0fb8336bffa11900a0936c633b854ce58e9 100644 (file)
@@ -728,7 +728,7 @@ public class TestRepository<R extends Repository> implements AutoCloseable {
                ThreeWayMerger merger = MergeStrategy.RECURSIVE.newMerger(db, true);
                merger.setBase(parent.getTree());
                if (merger.merge(head, commit)) {
-                       if (AnyObjectId.equals(head.getTree(), merger.getResultTreeId()))
+                       if (AnyObjectId.isEqual(head.getTree(), merger.getResultTreeId()))
                                return null;
                        tick(1);
                        org.eclipse.jgit.lib.CommitBuilder b =
index b38de14af9c0399c0bf2e36a5078479dc9afdd9a..15b6ff9a9a26347078433b2afa61458b55e107b2 100644 (file)
@@ -189,7 +189,7 @@ class VerifyReftable extends TextBuiltin {
                        return;
                }
 
-               if (!AnyObjectId.equals(exp.getObjectId(), act.getObjectId())) {
+               if (!AnyObjectId.isEqual(exp.getObjectId(), act.getObjectId())) {
                        throw die(String.format("expected %s to be %s, found %s",
                                        exp.getName(),
                                        id(exp.getObjectId()),
@@ -197,7 +197,8 @@ class VerifyReftable extends TextBuiltin {
                }
 
                if (exp.getPeeledObjectId() != null
-                               && !AnyObjectId.equals(exp.getPeeledObjectId(), act.getPeeledObjectId())) {
+                               && !AnyObjectId.isEqual(exp.getPeeledObjectId(),
+                                               act.getPeeledObjectId())) {
                        throw die(String.format("expected %s to be %s, found %s",
                                        exp.getName(),
                                        id(exp.getPeeledObjectId()),
index bfa30d5b4b07f3729ee15e0fece920f4ab470d8c..5a5ae1d7a34fb6920f2220322de790064214c583 100644 (file)
@@ -976,7 +976,7 @@ public class DfsGarbageCollectorTest {
                                rw.markStart(rw.parseCommit(ref.getObjectId()));
                        }
                        for (RevCommit next; (next = rw.next()) != null;) {
-                               if (AnyObjectId.equals(next, id)) {
+                               if (AnyObjectId.isEqual(next, id)) {
                                        return true;
                                }
                        }
index 4969305de013663859f69324c59a47864d80247d..e3972207f75a759141b3599c0d8b8ba53aa238d0 100644 (file)
@@ -89,8 +89,8 @@ public class RevObjectTest extends RevWalkTestCase {
                assertEquals(a1.hashCode(), a2.hashCode());
                assertEquals(b1.hashCode(), b2.hashCode());
 
-               assertTrue(AnyObjectId.equals(a1, a2));
-               assertTrue(AnyObjectId.equals(b1, b2));
+               assertTrue(AnyObjectId.isEqual(a1, a2));
+               assertTrue(AnyObjectId.isEqual(b1, b2));
        }
 
        @Test
index 65b72f7d951b67eb423bd1b7b40f44cadc3ade6f..c9dd547b4930e74c004e79c83a0077dfde00bc48 100644 (file)
@@ -157,8 +157,8 @@ public class CherryPickCommand extends GitCommand<CherryPickResult> {
                                merger.setCommitNames(new String[] { "BASE", ourName, //$NON-NLS-1$
                                                cherryPickName });
                                if (merger.merge(newHead, srcCommit)) {
-                                       if (AnyObjectId.equals(newHead.getTree().getId(), merger
-                                                       .getResultTreeId()))
+                                       if (AnyObjectId.isEqual(newHead.getTree().getId(),
+                                                       merger.getResultTreeId()))
                                                continue;
                                        DirCacheCheckout dco = new DirCacheCheckout(repo,
                                                        newHead.getTree(), repo.lockDirCache(),
index 593874c12176c766151e22ed3e51b0fe85fd3523..0dacd4dfbf6b11fe7d0c705fe4ef45c085580ab7 100644 (file)
@@ -575,7 +575,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
                        ObjectId headId = getHead().getObjectId();
                        // getHead() checks for null
                        assert headId != null;
-                       if (!AnyObjectId.equals(headId, newParents.get(0)))
+                       if (!AnyObjectId.isEqual(headId, newParents.get(0)))
                                checkoutCommit(headId.getName(), newParents.get(0));
 
                        // Use the cherry-pick strategy if all non-first parents did not
index 46e0df7263a33c40d49a0613e9f631917e4f7ae5..ddd60b6fa2faba7adec303ad1db7b6b0d52f394c 100644 (file)
@@ -175,8 +175,8 @@ public class RevertCommand extends GitCommand<RevCommit> {
                                                + "This reverts commit " + srcCommit.getId().getName() //$NON-NLS-1$
                                                + ".\n"; //$NON-NLS-1$
                                if (merger.merge(headCommit, srcParent)) {
-                                       if (AnyObjectId.equals(headCommit.getTree().getId(), merger
-                                                       .getResultTreeId()))
+                                       if (AnyObjectId.isEqual(headCommit.getTree().getId(),
+                                                       merger.getResultTreeId()))
                                                continue;
                                        DirCacheCheckout dco = new DirCacheCheckout(repo,
                                                        headCommit.getTree(), repo.lockDirCache(),
index a0176d7d2e5910f6d987b3880a850fa267ffb045..0e8377dd02c67b26ab1954cd0bb507081c263f6d 100644 (file)
@@ -345,7 +345,7 @@ public abstract class KetchReplica {
        }
 
        private static boolean equals(@Nullable ObjectId a, LogIndex b) {
-               return a != null && b != null && AnyObjectId.equals(a, b);
+               return a != null && b != null && AnyObjectId.isEqual(a, b);
        }
 
        /**
@@ -749,7 +749,7 @@ public abstract class KetchReplica {
                                Ref oldRef = remote.remove(name);
                                ObjectId oldId = getId(oldRef);
                                ObjectId newId = tw.getObjectId(0);
-                               if (!AnyObjectId.equals(oldId, newId)) {
+                               if (!AnyObjectId.isEqual(oldId, newId)) {
                                        delta.add(new ReceiveCommand(oldId, newId, name));
                                }
                        }
index c09d872f0a0d3de066a6560be85bbea59e26fd45..53fd198006da57543cbbf195ac225217719b1ee8 100644 (file)
@@ -106,7 +106,7 @@ class LagCheck implements AutoCloseable {
                        return UNKNOWN;
                }
 
-               if (AnyObjectId.equals(remoteId, ObjectId.zeroId())) {
+               if (AnyObjectId.isEqual(remoteId, ObjectId.zeroId())) {
                        // Replica does not have the txnAccepted reference.
                        return LAGGING;
                }
index 3c9b187c47ebfe5b122c94a4a68947359f5df3fe..4bed575f264545a0b1a79140845f91691092bebc 100644 (file)
@@ -200,7 +200,7 @@ public class RemoteGitReplica extends KetchReplica {
        private static boolean isExpectedValue(Map<String, Ref> adv,
                        RemoteRefUpdate u) {
                Ref r = adv.get(u.getRemoteName());
-               if (!AnyObjectId.equals(getId(r), u.getExpectedOldObjectId())) {
+               if (!AnyObjectId.isEqual(getId(r), u.getExpectedOldObjectId())) {
                        ((RemoteCommand) u).cmd.setResult(LOCK_FAILURE);
                        return false;
                }
index ae82dced21a8e15fc40d2dd6d26c51605d181c7b..815984deb2e681e214425896ae54744a95e05736 100644 (file)
@@ -138,7 +138,7 @@ public class StageBuilder {
                try (RevWalk rw = new RevWalk(git);
                                TreeWalk tw = new TreeWalk(rw.getObjectReader());
                                ObjectInserter ins = git.newObjectInserter()) {
-                       if (AnyObjectId.equals(oldTree, ObjectId.zeroId())) {
+                       if (AnyObjectId.isEqual(oldTree, ObjectId.zeroId())) {
                                tw.addTree(new EmptyTreeIterator());
                        } else {
                                tw.addTree(rw.parseTree(oldTree));
index 47ac4ec72eb4080774b9f32776a04341788d59c2..07fd00f149a5cafeb90e514687c89898484178cb 100644 (file)
@@ -252,7 +252,7 @@ public class ReftableBatchRefUpdate extends BatchRefUpdate {
 
        private static boolean matchOld(ReceiveCommand cmd, @Nullable Ref ref) {
                if (ref == null) {
-                       return AnyObjectId.equals(ObjectId.zeroId(), cmd.getOldId())
+                       return AnyObjectId.isEqual(ObjectId.zeroId(), cmd.getOldId())
                                        && cmd.getOldSymref() == null;
                } else if (ref.isSymbolic()) {
                        return ref.getTarget().getName().equals(cmd.getOldSymref());
@@ -368,7 +368,7 @@ public class ReftableBatchRefUpdate extends BatchRefUpdate {
                        String name = cmd.getRefName();
                        ObjectId newId = cmd.getNewId();
                        String newSymref = cmd.getNewSymref();
-                       if (AnyObjectId.equals(ObjectId.zeroId(), newId)
+                       if (AnyObjectId.isEqual(ObjectId.zeroId(), newId)
                                        && newSymref == null) {
                                refs.add(new ObjectIdRef.Unpeeled(NEW, name, null));
                                continue;
index 967754a627a39adc5bd1e891fc077afdcfdbe963..ea0d2690536b7112136da386188a7b0554d8bf27 100644 (file)
@@ -112,7 +112,7 @@ class UnpackedObjectCache {
                                if (obj == null)
                                        break;
 
-                               if (AnyObjectId.equals(obj, toFind))
+                               if (AnyObjectId.isEqual(obj, toFind))
                                        return true;
 
                                if (++i == ids.length())
@@ -132,7 +132,7 @@ class UnpackedObjectCache {
                                                continue;
                                }
 
-                               if (AnyObjectId.equals(obj, toAdd))
+                               if (AnyObjectId.isEqual(obj, toAdd))
                                        return true;
 
                                if (++i == ids.length())
index 791829b429e5c486bcf783a1b50591950689501b..4252e4138401a1e6a3e275fb38c0fc42a2269703 100644 (file)
@@ -60,19 +60,37 @@ import org.eclipse.jgit.util.NB;
 public abstract class AnyObjectId implements Comparable<AnyObjectId> {
 
        /**
-        * Compare to object identifier byte sequences for equality.
+        * Compare two object identifier byte sequences for equality.
         *
         * @param firstObjectId
         *            the first identifier to compare. Must not be null.
         * @param secondObjectId
         *            the second identifier to compare. Must not be null.
         * @return true if the two identifiers are the same.
+        * @deprecated use {@link #isEqual(AnyObjectId, AnyObjectId)} instead
         */
+       @Deprecated
+       @SuppressWarnings("AmbiguousMethodReference")
        public static boolean equals(final AnyObjectId firstObjectId,
                        final AnyObjectId secondObjectId) {
-               if (firstObjectId == secondObjectId)
-                       return true;
+               return isEqual(firstObjectId, secondObjectId);
+       }
 
+       /**
+        * Compare two object identifier byte sequences for equality.
+        *
+        * @param firstObjectId
+        *            the first identifier to compare. Must not be null.
+        * @param secondObjectId
+        *            the second identifier to compare. Must not be null.
+        * @return true if the two identifiers are the same.
+        * @since 5.4
+        */
+       public static boolean isEqual(final AnyObjectId firstObjectId,
+                       final AnyObjectId secondObjectId) {
+               if (firstObjectId == secondObjectId) {
+                       return true;
+               }
                // We test word 3 first since the git file-based ODB
                // uses the first byte of w1, and we use w2 as the
                // hash code, one of those probably came up with these
@@ -80,7 +98,6 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> {
                // Therefore the first two words are very likely to be
                // identical. We want to break away from collisions as
                // quickly as possible.
-               //
                return firstObjectId.w3 == secondObjectId.w3
                                && firstObjectId.w4 == secondObjectId.w4
                                && firstObjectId.w5 == secondObjectId.w5
@@ -276,9 +293,9 @@ public abstract class AnyObjectId implements Comparable<AnyObjectId> {
         *            the other id to compare to. May be null.
         * @return true only if both ObjectIds have identical bits.
         */
-       @SuppressWarnings("NonOverridingEquals")
+       @SuppressWarnings({ "NonOverridingEquals", "AmbiguousMethodReference" })
        public final boolean equals(AnyObjectId other) {
-               return other != null ? equals(this, other) : false;
+               return other != null ? isEqual(this, other) : false;
        }
 
        /** {@inheritDoc} */
index cd57bda82e8cc98ce5d22605f838f9106ba1d94d..470275beb15ad573cc249b9e8ffd653b31cb1d02 100644 (file)
@@ -103,8 +103,9 @@ public class ObjectIdSubclassMap<V extends ObjectId>
                V obj;
 
                while ((obj = tbl[i]) != null) {
-                       if (AnyObjectId.equals(obj, toFind))
+                       if (AnyObjectId.isEqual(obj, toFind)) {
                                return obj;
+                       }
                        i = (i + 1) & msk;
                }
                return null;
@@ -162,7 +163,7 @@ public class ObjectIdSubclassMap<V extends ObjectId>
                V obj;
 
                while ((obj = tbl[i]) != null) {
-                       if (AnyObjectId.equals(obj, newValue))
+                       if (AnyObjectId.isEqual(obj, newValue))
                                return obj;
                        i = (i + 1) & msk;
                }
index 78416276667fc9c6f1eb3bbd6287a5b7d99ef571..33c7070331b29d80b8a180abbf16a7dfb49e7644 100644 (file)
@@ -753,7 +753,7 @@ public abstract class RefUpdate {
                        if (expValue != null) {
                                final ObjectId o;
                                o = oldValue != null ? oldValue : ObjectId.zeroId();
-                               if (!AnyObjectId.equals(expValue, o)) {
+                               if (!AnyObjectId.isEqual(expValue, o)) {
                                        return Result.LOCK_FAILURE;
                                }
                        }
index 325ff4f2685611558a7bce3b32f498c52ace34c3..ba7223b8f07ba876e1ca06f8c3dc6afc23c2e86f 100644 (file)
@@ -295,14 +295,14 @@ public class NoteMapMerger {
        private static boolean sameNote(Note a, Note b) {
                if (a == null && b == null)
                        return true;
-               return a != null && b != null && AnyObjectId.equals(a, b);
+               return a != null && b != null && AnyObjectId.isEqual(a, b);
        }
 
        private static boolean sameContent(Note a, Note b) {
                if (a == null && b == null)
                        return true;
                return a != null && b != null
-                               && AnyObjectId.equals(a.getData(), b.getData());
+                               && AnyObjectId.isEqual(a.getData(), b.getData());
        }
 
        private static InMemoryNoteBucket addIfNotNull(InMemoryNoteBucket result,
index d61aeb04d26907010e54b306ab6ae9bd3f2493a1..a9a995cd3fd100f8cccf93b36587a20a36287972 100644 (file)
@@ -429,7 +429,7 @@ public class ReceiveCommand {
                this.newId = ObjectId.zeroId();
                this.newSymref = newSymref;
                this.name = name;
-               if (AnyObjectId.equals(ObjectId.zeroId(), oldId)) {
+               if (AnyObjectId.isEqual(ObjectId.zeroId(), oldId)) {
                        type = Type.CREATE;
                } else if (newSymref != null) {
                        type = Type.UPDATE;
@@ -468,7 +468,7 @@ public class ReceiveCommand {
                this.name = name;
                if (oldSymref == null) {
                        type = Type.CREATE;
-               } else if (!AnyObjectId.equals(ObjectId.zeroId(), newId)) {
+               } else if (!AnyObjectId.isEqual(ObjectId.zeroId(), newId)) {
                        type = Type.UPDATE;
                } else {
                        type = Type.DELETE;
@@ -750,7 +750,7 @@ public class ReceiveCommand {
        public void updateType(RevWalk walk) throws IOException {
                if (typeIsCorrect)
                        return;
-               if (type == Type.UPDATE && !AnyObjectId.equals(oldId, newId)) {
+               if (type == Type.UPDATE && !AnyObjectId.isEqual(oldId, newId)) {
                        RevObject o = walk.parseAny(oldId);
                        RevObject n = walk.parseAny(newId);
                        if (!(o instanceof RevCommit)
index ba2a673a181a3eefbcb0c55a0707ac9b12675af9..550a9ef3720397c4b47d0378e8dfbb5f167d63f6 100644 (file)
@@ -175,7 +175,7 @@ public class TrackingRefUpdate {
                private RefUpdate.Result decode(ReceiveCommand.Result status) {
                        switch (status) {
                        case OK:
-                               if (AnyObjectId.equals(oldObjectId, newObjectId))
+                               if (AnyObjectId.isEqual(oldObjectId, newObjectId))
                                        return RefUpdate.Result.NO_CHANGE;
                                switch (getType()) {
                                case CREATE:
index 2bb58144babae03975e5ab552d447964ce03f38b..b289e421779a52aba4a7112a60fddbe3174b2c3a 100644 (file)
@@ -657,7 +657,7 @@ class WalkFetchConnection extends BaseFetchConnection {
                }
 
                ObjectId act = inserter.insert(type, raw);
-               if (!AnyObjectId.equals(id, act)) {
+               if (!AnyObjectId.isEqual(id, act)) {
                        throw new TransportException(MessageFormat.format(
                                        JGitText.get().incorrectHashFor, id.name(), act.name(),
                                        Constants.typeString(type),
index 4c754252a3dff0927a3a2ed43dc891d3f3acdce5..d9103f8b2720fc4bf0cc0a38ac1ca57843375c7e 100644 (file)
@@ -165,7 +165,7 @@ class WalkPushConnection extends BaseConnection implements PushConnection {
                                continue;
                        }
 
-                       if (AnyObjectId.equals(ObjectId.zeroId(), u.getNewObjectId()))
+                       if (AnyObjectId.isEqual(ObjectId.zeroId(), u.getNewObjectId()))
                                deleteCommand(u);
                        else
                                updates.add(u);
index d7a4c2535a861e46ea7041731681b6d8ea363d4d..9663e3cef564a697321d7db7c02c0c144a3e30a2 100644 (file)
@@ -443,8 +443,10 @@ public class RefMap extends AbstractMap<String, Ref> {
                                        if (r.getName().equals(ref.getName())) {
                                                final ObjectId a = r.getObjectId();
                                                final ObjectId b = ref.getObjectId();
-                                               if (a != null && b != null && AnyObjectId.equals(a, b))
+                                               if (a != null && b != null
+                                                               && AnyObjectId.isEqual(a, b)) {
                                                        return true;
+                                               }
                                        }
                                }
                        }