diff options
author | Stephan Herrmann | 2019-12-20 23:41:08 +0000 |
---|---|---|
committer | Stephan Herrmann | 2019-12-20 23:41:08 +0000 |
commit | 77745aef3d0522476f7e972af1db6be761f02986 (patch) | |
tree | bf6d878eef4222e6bbaa16095e7c4e5a436972c3 | |
parent | 6af76575d4f7930be7e89c13fa03f51d6536e4a9 (diff) | |
download | eclipse.jdt.core-77745aef3d0522476f7e972af1db6be761f02986.tar.gz eclipse.jdt.core-77745aef3d0522476f7e972af1db6be761f02986.tar.xz eclipse.jdt.core-77745aef3d0522476f7e972af1db6be761f02986.zip |
Bug 558517 - ClassFile.getNewTypeBinding(...) throws
NullPointerException
Change-Id: I88358a0f96cfd73ac4a4734b0fd76914a57724d6
2 files changed, 58 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java index 5aac8b39e0..0fb06062af 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; +import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; @@ -84,6 +85,13 @@ public class StandAloneASTParserTest extends AbstractRegressionTest { parser.setUnitName(unitName); return parser.createAST(null); } + protected File createFile(File dir, String fileName, String contents) throws IOException { + File file = new File(dir, fileName); + try (Writer writer = new BufferedWriter(new FileWriter(file))) { + writer.write(contents); + } + return file; + } public void testBug529654_001() { String contents = "module m {\n" + @@ -1825,5 +1833,53 @@ public class StandAloneASTParserTest extends AbstractRegressionTest { SwitchExpression se = (SwitchExpression) fragment.getInitializer(); YieldStatement yieldStatement = (YieldStatement) ((Block)se.statements().get(1)).statements().get(0); assertNotNull("Expression null", yieldStatement.getExpression()); - } + } + public void testBug558517() throws IOException { + File f1 = null, f2 = null, packDir = null; + try { + File rootDir = new File(System.getProperty("java.io.tmpdir")); + packDir = new File(rootDir, "P/src/x"); + packDir.mkdirs(); + + String fileName1 = "EnsureImpl$1.java"; + String fileName2 = "C9947f.java"; + f1 = createFile( + packDir, fileName1, + "package x;\n" + + "\n" + + "class EnsureImpl$1 {\n" + + "}\n"); + f2 = createFile( + packDir, fileName2, + "package x;\n" + + "public final class C9947f {\n" + + " public C9947f() {\n" + + " try {\n" + + " new x.EnsureImpl$1();\n" + + " } catch (Throwable unused) {\n" + + " }\n" + + " }\n" + + "}\n"); + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setResolveBindings(true); + Map<String, String> options = new HashMap<>(); + JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); + parser.setCompilerOptions(options ); + parser.setEnvironment(null, + new String[] { rootDir + "/P/src" }, + null, + true); + parser.createASTs(new String[] { packDir + "/" + fileName1, packDir + "/" + fileName2 }, + null, + new String[] { "Lx/C9947f;" }, + new FileASTRequestor() { + }, + null); + // just ensure the above doesn't throw NPE + } finally { + f1.delete(); + f2.delete(); + packDir.delete(); + } + } }
\ No newline at end of file diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java index 9835a4607f..7d1ea83dec 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java @@ -5960,7 +5960,7 @@ public class ClassFile implements TypeConstants, TypeIds { private TypeBinding getNewTypeBinding(char[] typeConstantPoolName, Scope scope) { char[] typeName = typeConstantPoolName; - if (isLikelyLocalTypeName(typeName)) { + if (this.innerClassesBindings != null && isLikelyLocalTypeName(typeName)) { // find local type in innerClassesBindings: Set<TypeBinding> innerTypeBindings = this.innerClassesBindings.keySet(); for (TypeBinding binding : innerTypeBindings) { |