Bug 558517 - ClassFile.getNewTypeBinding(...) throws NullPointerException
Summary: ClassFile.getNewTypeBinding(...) throws NullPointerException
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.15   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.15 M1   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2019-12-20 11:02 EST by Ivan Ivan CLA
Modified: 2019-12-21 07:31 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Ivan CLA 2019-12-20 11:02:27 EST
Hi, there are two valid Java sources which cause the core to crash with stacktrace:
Exception in thread "main" java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.ClassFile.getNewTypeBinding(ClassFile.java:5965)
	at org.eclipse.jdt.internal.compiler.ClassFile.traverse(ClassFile.java:6937)
	at org.eclipse.jdt.internal.compiler.ClassFile.generateStackMapTableAttribute(ClassFile.java:4826)
	at org.eclipse.jdt.internal.compiler.ClassFile.completeCodeAttribute(ClassFile.java:1519)
	at org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration.internalGenerateCode(ConstructorDeclaration.java:459)
	at org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration.generateCode(ConstructorDeclaration.java:297)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:579)
	at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:649)
	at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode(CompilationUnitDeclaration.java:412)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:912)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1044)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:662)
	at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:1013)

Used the latest JDT core version from master branch

File "x/EnsureImpl$1.java"
package x;

class EnsureImpl$1 {
}

File "x/C9947f.java"
package x;

public final class C9947f {
    public C9947f() {
        try {
            new x.EnsureImpl$1();
        } catch (Throwable unused) {
        }
    }
}
Comment 1 Ivan Ivan CLA 2019-12-20 11:05:44 EST
Caused by
	private TypeBinding getNewTypeBinding(char[] typeConstantPoolName, Scope scope) {
		char[] typeName = typeConstantPoolName;
		if (isLikelyLocalTypeName(typeName)) {
			// find local type in innerClassesBindings:
			Set<TypeBinding> innerTypeBindings = this.innerClassesBindings.keySet(); // innerClassesBindings is null
Comment 2 Andrey Loskutov CLA 2019-12-20 11:32:56 EST
Is this a regression in 4.15?
Can you attach a simple code example that triggers the error?
Do you want to provide a patch?
Comment 3 Ivan Ivan CLA 2019-12-20 11:34:14 EST
> Can you attach a simple code example that triggers the error?

Already attached

> Do you want to provide a patch?

No, I want the Eclipse team to fix it
Comment 4 Andrey Loskutov CLA 2019-12-20 11:37:58 EST
(In reply to Sergey Toshin from comment #3)
> > Can you attach a simple code example that triggers the error?
> 
> Already attached

Sorry, missed after flying over the stack. Thanks.
Comment 5 Stephan Herrmann CLA 2019-12-20 16:37:43 EST
Thanks, I can reproduce. It's caused by the fix for bug 534223.
Comment 6 Eclipse Genie CLA 2019-12-20 18:43:11 EST
New Gerrit change created: https://git.eclipse.org/r/154931
Comment 7 Stephan Herrmann CLA 2019-12-20 18:48:28 EST
(In reply to Eclipse Genie from comment #6)
> New Gerrit change created: https://git.eclipse.org/r/154931

The fix is straight forward: when innerClassesBindings == null, we have no business interpreting EnsureImpl$1 as the name of an inner/local class.

As usual, it was the test that took a little longer than the fix...
Comment 9 Stephan Herrmann CLA 2019-12-21 07:31:19 EST
(In reply to Eclipse Genie from comment #8)
> Gerrit change https://git.eclipse.org/r/154931 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=77745aef3d0522476f7e972af1db6be761f02986

Released for 4.15 M1