Make toString(), hashCode(), equals() and friends final in AutoValue classes

Developers usually don't look at the classes that AutoValue generates,
but at the hand-written classes. If the hand-written classes implement
toString(), hashCode(), equals() etc, AutoValue doesn't override them.
To make this more clear to readers of the hand-written classes
ErrorProne suggests to make these methods final.

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

Enable this check at ERROR severity to prevent future occurrences.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I972e8e8f9339b811c78157abef771b8c32be079c
This commit is contained in:
Edwin Kempin
2019-07-01 16:10:57 +02:00
committed by David Pursehouse
parent 5a355d20c9
commit c2d0a910a5
15 changed files with 26 additions and 25 deletions

View File

@@ -193,7 +193,7 @@ public abstract class ExternalId implements Serializable {
}
@Override
public String toString() {
public final String toString() {
return get();
}
@@ -441,7 +441,7 @@ public abstract class ExternalId implements Serializable {
* that was loaded from Git can be equal with an external ID that was created from code.
*/
@Override
public boolean equals(Object obj) {
public final boolean equals(Object obj) {
if (!(obj instanceof ExternalId)) {
return false;
}
@@ -453,7 +453,7 @@ public abstract class ExternalId implements Serializable {
}
@Override
public int hashCode() {
public final int hashCode() {
return Objects.hash(key(), accountId(), email(), password());
}
@@ -471,7 +471,7 @@ public abstract class ExternalId implements Serializable {
* </pre>
*/
@Override
public String toString() {
public final String toString() {
Config c = new Config();
writeToConfig(c);
return c.toText();