Bug 563416 - Null Pointer Exception in while building type bindings
Summary: Null Pointer Exception in while building type bindings
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.12   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2020-05-20 22:22 EDT by Namana Pawar CLA
Modified: 2024-05-05 17:49 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Namana Pawar CLA 2020-05-20 22:22:44 EDT
A NullPointerException occurred in PackageBinding class at https://github.com/eclipse/eclipse.jdt.core/blob/master/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/PackageBinding.java#L106 during the buildTypeBindings process of creating AST 

the this.environment.globalOptions seems to be null, even though there are several measures to make sure this.environment is set to a default value I'm not sure if globalOptions has been taken care of.

Stack trace:
 
Caused by: java.lang.NullPointerException
    at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.addType(PackageBinding.java:109) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.ClassScope.buildType(ClassScope.java:432) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.buildTypeBindings(CompilationUnitScope.java:182) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.buildTypeBindings(LookupEnvironment.java:472) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.Compiler.accept(Compiler.java:340) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.accept(CompilationUnitResolver.java:186) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:333) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:268) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:3351) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getType(Scope.java:3063) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.SingleTypeReference.getTypeBinding(SingleTypeReference.java:57) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.internalResolveType(TypeReference.java:514) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:615) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:611) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:607) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.Annotation.resolveType(Annotation.java:876) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:888) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.ast.ASTNode.resolveAnnotations(ASTNode.java:747) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.FieldBinding.getAnnotationTagBits(FieldBinding.java:320) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypeFor(SourceTypeBinding.java:1793) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.fields(SourceTypeBinding.java:950) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.internalFaultInTypeForFieldsAndMethods(SourceTypeBinding.java:918) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:914) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:518) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:885) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1047) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:662) ~[org.eclipse.jdt.core-3.18.0.jar:?]
    at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:1012) ~[org.eclipse.jdt.core-3.18.0.jar:?]
Comment 1 Stephan Herrmann CLA 2020-05-21 07:49:35 EDT
Adjusting the version to 4.12 (from org.eclipse.jdt.core-3.18.0.jar).

Can you please try with a more recent version?

If the problem still exists we will need steps for reproducing the problem.

Looking at code in today's HEAD, here's what I see:

LookupEnvironment has two constructors:

/** Construct the root LookupEnvironment, corresponding to the UnNamedModule. */

This constructor first assigns global options and later also dereferences it in "... this.globalOptions.sourceLevel ...". If it were null, we'd see an NPE right here.


/** Construct a specific LookupEnvironment, corresponding to the given module. */

Copies globalOptions from the parameter rootEnv.

I.e., we can only construct a LookupEnvironment with null globalOptions, if we already have a LookupEnvironment with null globalOptions.

There are no further assignments to this field.

Hence: I cannot believe the observation until I see steps for reproducing. 


There is always a chance that what you are running is not exactly the code as authored in JDT, several projects maintain a fork of JDT, or perform runtime bytecode weaving. If any such technology is in use, please specify.
Comment 2 Namana Pawar CLA 2020-05-21 16:36:17 EDT
We use a version authored by JDT 
 1. What is the full name of the open source package (e.g., which version are you using)?
Eclipse JDT Core 3.18.0

 2. What is the URL of the authoritative download site?
https://mvnrepository.com/artifact/org.eclipse.jdt/org.eclipse.jdt.core/3.18.0

 3. What are the URLs of all licenses governing this package?
https://www.eclipse.org/legal/epl-2.0/

We will be unable to move to a new version as of now because we want to be sure that the new version has no backwards incompatible changes. 

If I provide the package used to construct the AST would that be enough context to reproduce this error for 3.18.0 version. 

Thank you so mcuh!
Comment 3 Namana Pawar CLA 2020-05-21 16:45:16 EDT
The repository for which AST could not be generated is https://github.com/SonarSource/sonar-java
Comment 4 Stephan Herrmann CLA 2020-05-21 18:04:18 EDT
(In reply to Namana Pawar from comment #2)
> We use a version authored by JDT 
>  1. What is the full name of the open source package (e.g., which version
> are you using)?
> Eclipse JDT Core 3.18.0
> 
>  2. What is the URL of the authoritative download site?
> https://mvnrepository.com/artifact/org.eclipse.jdt/org.eclipse.jdt.core/3.18.
> 0
> 
>  3. What are the URLs of all licenses governing this package?
> https://www.eclipse.org/legal/epl-2.0/
> 
> We will be unable to move to a new version as of now because we want to be
> sure that the new version has no backwards incompatible changes. 

You're free to use any version but certainly bugs will only be fixed in the latest version, which currently is JDT/Core 3.22.0

Still, we could save much time if for once you at least try to use a recent version. Maybe the issue has long ago been fixed?

> If I provide the package used to construct the AST would that be enough
> context to reproduce this error for 3.18.0 version. 

No, that's not enough :)

(In reply to Namana Pawar from comment #3)
> The repository for which AST could not be generated is
> https://github.com/SonarSource/sonar-java

That's a repository. But it doesn't tell me, what I need to *do* in order to reproduce the problem.
Comment 5 Eclipse Genie CLA 2022-05-13 19:46:28 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 6 Eclipse Genie CLA 2024-05-05 17:49:45 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.