Skip to content

Commit

Permalink
Fix a crash in WrongParameterPackage
Browse files Browse the repository at this point in the history
MethodSymbol#params is null if the symbol hasn't been completed,
params() should be used instead.

Fixes #356

MOE_MIGRATED_REVID=124159835
  • Loading branch information
cushon committed Jun 7, 2016
1 parent 00c12ee commit eb5a3f7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ public Description matchMethod(MethodTree tree, VisitorState state) {
}

// if this doesn't have the right number of parameters, look at other ones.
if (supermethod.params.size() != method.params.size()) {
if (supermethod.params().size() != method.params().size()) {
continue;
}

for (int x = 0; x < method.params.size(); x++) {
Type methodParamType = method.params.get(x).type;
Type supermethodParamType = supermethod.params.get(x).type;
for (int x = 0; x < method.params().size(); x++) {
Type methodParamType = method.params().get(x).type;
Type supermethodParamType = supermethod.params().get(x).type;
if (methodParamType.tsym.name.contentEquals(supermethodParamType.tsym.name)
&& !state.getTypes().isSameType(methodParamType, supermethodParamType)) {
this.supermethod = supermethod;
Expand All @@ -106,9 +106,9 @@ public Description describe(MethodTree tree, VisitorState state) {
throw new IllegalStateException("Matching supermethod was not found");
}

for (int x = 0; x < method.params.size(); x++) {
Type methodParamType = method.params.get(x).type;
Type supermethodParamType = supermethod.params.get(x).type;
for (int x = 0; x < method.params().size(); x++) {
Type methodParamType = method.params().get(x).type;
Type supermethodParamType = supermethod.params().get(x).type;
if (methodParamType.tsym.name.contentEquals(supermethodParamType.tsym.name)
&& !state.getTypes().isSameType(methodParamType, supermethodParamType)) {
VariableTree param = tree.getParameters().get(x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,22 @@ public void testNPE() throws Exception {
"}")
.doTest();
}

// regression test for https://github.com/google/error-prone/issues/356
@Test
public void testCompleteParams() throws Exception {
compilationHelper
.addSourceLines(
"Test.java",
"package org.gaul.mypackage;",
"import java.io.IOException;",
"import java.io.InputStream;",
"class MyInputStream extends InputStream {",
" @Override",
" public int read() throws IOException {",
" return 0;",
" }",
"}")
.doTest();
}
}

0 comments on commit eb5a3f7

Please sign in to comment.