Skip to content

Commit

Permalink
#138 Simplify HierarchyChecker for abstract supers
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Apr 3, 2016
1 parent c919b46 commit 392faa1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
12 changes: 1 addition & 11 deletions src/main/java/nl/jqno/equalsverifier/HierarchyChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package nl.jqno.equalsverifier;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import nl.jqno.equalsverifier.internal.ClassAccessor;
import nl.jqno.equalsverifier.internal.Formatter;
import nl.jqno.equalsverifier.internal.ObjectAccessor;
Expand Down Expand Up @@ -83,7 +82,6 @@ private void checkSuperclass() {
}
}

@SuppressFBWarnings(value = "RV_RETURN_VALUE_IGNORED", justification = "We only want to see if it throws an exception.")
private void safelyCheckSuperProperties(ObjectAccessor<T> referenceAccessor) {
T reference = referenceAccessor.get();
Object equalSuper = getEqualSuper(reference);
Expand All @@ -92,20 +90,12 @@ private void safelyCheckSuperProperties(ObjectAccessor<T> referenceAccessor) {
ObjectAccessor.of(shallowCopy).shallowScramble(config.getPrefabValues(), typeTag);

try {
reference.equals(equalSuper);
equalSuper.equals(reference);
equalSuper.hashCode();
checkSuperProperties(reference, equalSuper, shallowCopy);
}
catch (AbstractMethodError ignored) {
// In this case, we'll assume all super properties hold.
// The problems we test for, can never occur anyway if you can't instantiate a super instance.
return;
}
catch (Exception ignored) {
// Ignore any other exceptions; they will come up again in the following checks.
}

checkSuperProperties(reference, equalSuper, shallowCopy);
}

private void checkSuperProperties(T reference, Object equalSuper, T shallow) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,13 @@ abstract static class AbstractHashCodeDelegator {

abstract int theAnswer();

@Override public boolean equals(Object obj) { return defaultEquals(this, obj); }
@Override public boolean equals(Object obj) {
if (!(obj instanceof AbstractHashCodeDelegator)) {
return false;
}
AbstractHashCodeDelegator other = (AbstractHashCodeDelegator)obj;
return i == other.i;
}

@Override
public int hashCode() {
Expand Down

0 comments on commit 392faa1

Please sign in to comment.