Skip to content

Commit

Permalink
Fix NPE on JDK13+ when InconsistentHashCode visits a break statement …
Browse files Browse the repository at this point in the history
…with a label.

Fixes #1287

RELNOTES: n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=250371701
  • Loading branch information
nick-someone authored and ronshapiro committed Jun 13, 2019
1 parent bad19ab commit 93d65e9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ public Void visitIdentifier(IdentifierTree tree, Void unused) {
}

private void handleSymbol(Symbol symbol) {
if (symbol.getKind() == ElementKind.FIELD
if (symbol != null
&& symbol.getKind() == ElementKind.FIELD
&& !symbol.isStatic()
&& symbol.owner.equals(classSymbol)) {
String name = symbol.name.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,31 @@ public void memoizedHashCode() {
"}")
.doTest();
}

@Test
public void breakLabeledBlock() {
helper
.addSourceLines(
"Test.java",
"class Test {",
" private int a;",
" private int b;",
" private int hashCode;",
" public void accessesLocalWithLabeledBreak() {",
" label: {",
" switch (a) {",
" case 0: break label;",
" }",
" }",
" }",
" @Override public boolean equals(Object o) {",
" Test that = (Test) o;",
" return this.a == that.a && this.b == that.b;",
" }",
" @Override public int hashCode() {",
" return hashCode;",
" }",
"}")
.doTest();
}
}

0 comments on commit 93d65e9

Please sign in to comment.