Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import java.util.Objects;

class HashCodeMismatchedFieldsCheckSampleNonCompiling {

// "undefinedField" cannot be resolved: the field-read collector must bail out on the unknown
// identifier symbol instead of assuming it is unrelated state, and must not report an issue here.
static class UnresolvedIdentifier {
private final long id;

UnresolvedIdentifier(long id) {
this.id = id;
}

@Override
public boolean equals(Object other) {
return other instanceof UnresolvedIdentifier that && id == that.id;
}

@Override
public int hashCode() { // No issue - "undefinedField" cannot be resolved, so the scan bails out
return Objects.hash(id, undefinedField);
}
}

// A call to an unresolvable method must also make the scan bail out rather than treat it as a
// harmless side-effect-free helper.
static class UnresolvedHelperCall {
private final long id;
private final int version;

UnresolvedHelperCall(long id, int version) {
this.id = id;
this.version = version;
}

@Override
public boolean equals(Object other) {
return other instanceof UnresolvedHelperCall that && id == that.id && unresolvedHelper();
}

@Override
public int hashCode() { // No issue - equals() calls an unresolved method, so the scan bails out
return Objects.hash(id, version);
}
}
}
Loading
Loading