Skip to content

Commit

Permalink
Fix a NPE in ByteBufferBackingArray
Browse files Browse the repository at this point in the history
Fixes #1004

MOE_MIGRATED_REVID=193610886
  • Loading branch information
cushon committed Apr 20, 2018
1 parent 9010f1e commit ea07060
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
} while (receiver instanceof MethodInvocationTree);

Symbol bufferSymbol = ASTHelpers.getSymbol(receiver);
if (bufferSymbol == null) {
return Description.NO_MATCH;
}

// Checks for validating use on method scope.
if (bufferSymbol.owner instanceof MethodSymbol) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ public void testNegativeCases() throws Exception {
compilationHelper.addSourceFile("ByteBufferBackingArrayNegativeCases.java").doTest();
}


@Test
public void i1004() {
compilationHelper
.addSourceLines(
"Test.java",
"import java.nio.ByteBuffer;",
"public class Test {",
" public void ByteBufferBackingArrayTest() {",
" byte[] byteArray = ((ByteBuffer) new Object()).array();",
" }",
"}")
.doTest();
}
}

0 comments on commit ea07060

Please sign in to comment.