Error Prone: Increase severity of NonOverridingEquals to ERROR

Error Prone reports the warning on several classes:

   [NonOverridingEquals] equals method doesn't override Object.equals;
   if this is a type-specific helper for a method that does override
   Object.equals, either inline it into the callers or rename it to
   avoid ambiguity.

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

Most of these are in the public API, so we can't rename or inline them
without breaking the API. FileSnapshot is not part of the public API,
but clients may be using it anyway, so we also shouldn't change that.

Suppress all the warnings instead. Having the check at severity ERROR
will at least make sure we don't introduce any new occurrences.

Change-Id: I92345c11256f06b4fa03ccc13337f72af5a43591
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
David Pursehouse 2019-06-16 16:28:02 +09:00
parent 13696b8d8c
commit 430be89307
5 changed files with 12 additions and 1 deletions

View File

@ -274,6 +274,7 @@ public final int hashCode() {
* the other id to compare to. May be null.
* @return true only if both LongObjectIds have identical bits.
*/
@SuppressWarnings("NonOverridingEquals")
public final boolean equals(AnyLongObjectId other) {
return other != null ? equals(this, other) : false;
}

View File

@ -317,6 +317,7 @@ public void waitUntilNotRacy() throws InterruptedException {
* the other snapshot.
* @return true if the two snapshots share the same information.
*/
@SuppressWarnings("NonOverridingEquals")
public boolean equals(FileSnapshot other) {
return lastModified == other.lastModified && size == other.size
&& Objects.equals(fileKey, other.fileKey);

View File

@ -276,6 +276,7 @@ public final int hashCode() {
* the other id to compare to. May be null.
* @return true only if both ObjectIds have identical bits.
*/
@SuppressWarnings("NonOverridingEquals")
public final boolean equals(AnyObjectId other) {
return other != null ? equals(this, other) : false;
}

View File

@ -88,6 +88,7 @@ public abstract class FileMode {
public static final FileMode TREE = new FileMode(TYPE_TREE,
Constants.OBJ_TREE) {
@Override
@SuppressWarnings("NonOverridingEquals")
public boolean equals(int modeBits) {
return (modeBits & TYPE_MASK) == TYPE_TREE;
}
@ -97,6 +98,7 @@ public boolean equals(int modeBits) {
public static final FileMode SYMLINK = new FileMode(TYPE_SYMLINK,
Constants.OBJ_BLOB) {
@Override
@SuppressWarnings("NonOverridingEquals")
public boolean equals(int modeBits) {
return (modeBits & TYPE_MASK) == TYPE_SYMLINK;
}
@ -106,6 +108,7 @@ public boolean equals(int modeBits) {
public static final FileMode REGULAR_FILE = new FileMode(0100644,
Constants.OBJ_BLOB) {
@Override
@SuppressWarnings("NonOverridingEquals")
public boolean equals(int modeBits) {
return (modeBits & TYPE_MASK) == TYPE_FILE && (modeBits & 0111) == 0;
}
@ -115,6 +118,7 @@ public boolean equals(int modeBits) {
public static final FileMode EXECUTABLE_FILE = new FileMode(0100755,
Constants.OBJ_BLOB) {
@Override
@SuppressWarnings("NonOverridingEquals")
public boolean equals(int modeBits) {
return (modeBits & TYPE_MASK) == TYPE_FILE && (modeBits & 0111) != 0;
}
@ -124,6 +128,7 @@ public boolean equals(int modeBits) {
public static final FileMode GITLINK = new FileMode(TYPE_GITLINK,
Constants.OBJ_COMMIT) {
@Override
@SuppressWarnings("NonOverridingEquals")
public boolean equals(int modeBits) {
return (modeBits & TYPE_MASK) == TYPE_GITLINK;
}
@ -133,6 +138,7 @@ public boolean equals(int modeBits) {
public static final FileMode MISSING = new FileMode(TYPE_MISSING,
Constants.OBJ_BAD) {
@Override
@SuppressWarnings("NonOverridingEquals")
public boolean equals(int modeBits) {
return modeBits == 0;
}
@ -165,6 +171,7 @@ public static final FileMode fromBits(int bits) {
return new FileMode(bits, Constants.OBJ_BAD) {
@Override
@SuppressWarnings("NonOverridingEquals")
public boolean equals(int a) {
return bits == a;
}
@ -206,6 +213,7 @@ private FileMode(int mode, int expType) {
* a int.
* @return true if the mode bits represent the same mode as this object
*/
@SuppressWarnings("NonOverridingEquals")
public abstract boolean equals(int modebits);
/**

View File

@ -60,7 +60,7 @@ java_package_configuration(
"-Xep:MutableConstantField:ERROR",
"-Xep:NarrowingCompoundAssignment:WARN",
"-Xep:NonAtomicVolatileUpdate:ERROR",
"-Xep:NonOverridingEquals:WARN",
"-Xep:NonOverridingEquals:ERROR",
"-Xep:NullableConstructor:ERROR",
"-Xep:NullablePrimitive:ERROR",
"-Xep:NullableVoid:ERROR",