Bug 550973 - NullPointerException during resolving annotation binding
Summary: NullPointerException during resolving annotation binding
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.11   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2019-09-11 09:38 EDT by Tomasz Malinowski CLA
Modified: 2023-09-03 10:26 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tomasz Malinowski CLA 2019-09-11 09:38:56 EDT
Hello

I am observing following NPE during parsing code with annotation.

java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.UnresolvedAnnotationBinding.resolve(UnresolvedAnnotationBinding.java:34)
	at org.eclipse.jdt.internal.compiler.lookup.UnresolvedAnnotationBinding.getAnnotationType(UnresolvedAnnotationBinding.java:41)
	at org.eclipse.jdt.core.dom.MethodBinding.filterTypeAnnotations(MethodBinding.java:226)
	at org.eclipse.jdt.core.dom.MethodBinding.getAnnotations(MethodBinding.java:115)

Debugger shows that env value is null during reverting state for  env.mayTolerateMissingType (patch https://bugs.eclipse.org/bugs/show_bug.cgi?id=388042).
Comment 1 Stephan Herrmann CLA 2019-09-11 17:55:11 EDT
Wow, thanks.

Is it the "this.env = null" inside getElementValuePairs() that breaks it?

Maybe we should simply pull this.env into a local variable, to be independent of the changes in the field.

@Tomasz are you in a position to try this?
Comment 2 Tomasz Malinowski CLA 2019-09-13 05:37:35 EDT
Hi Stephan

Creating a local reference of this.env used inside resolve method fixed the NPE problem.

However I have a one concern about the flow in this class.

- Method resolve() temporary changes state of this.env.mayTolerateMissingType (path 388042)
- Since reference of this.env is changed to null during calling "resolve()" method is means that getElementValuePairs() (which can change this state) is called independently (from separated thread).

It means that both methods changes state of env in the same time (change it's content or make whole reference null), so they may be not thread safe.

Should their content use some synchronization block to avoid case when ie. this.env.mayTolerateMissingType will changed by resolve() in one thread when getElementValuePairs() will start resolving method binding in other thread (method part after independent call to resolve() at its begining) ?
Comment 3 Eclipse Genie CLA 2021-09-03 09:33:23 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 4 Amy Brennan-Luna CLA 2021-09-12 10:36:10 EDT
I ran into this issue today and Googled the error and found this bug. I tested my code single threaded and didn't get the error. When multi-threaded, I get the error inconsistently, which aligns with the 2019 discussion that it's a bug where env value is null sometimes, which yields the inconsistent bug when multi-threaded.

Exception in thread "ForkJoinPool-1-worker-1" java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.UnresolvedAnnotationBinding.resolve(UnresolvedAnnotationBinding.java:34)
	at org.eclipse.jdt.internal.compiler.lookup.UnresolvedAnnotationBinding.getAnnotationType(UnresolvedAnnotationBinding.java:41)
	at org.eclipse.jdt.core.dom.MethodBinding.filterTypeAnnotations(MethodBinding.java:227)
	at org.eclipse.jdt.core.dom.MethodBinding.getAnnotations(MethodBinding.java:116)


I'm using Java 8 and the following dependencies

		<dependency>
			<groupId>org.eclipse.platform</groupId>
			<artifactId>org.eclipse.text</artifactId>
			<version>3.11.0</version>
		</dependency>

		<dependency>
			<groupId>org.eclipse.platform</groupId>
			<artifactId>org.eclipse.equinox.common</artifactId>
			<version>3.14.100</version>
		</dependency>

		<dependency>
			<groupId>org.eclipse.platform</groupId>
			<artifactId>org.eclipse.core.runtime</artifactId>
			<version>3.20.100</version>
		</dependency>

		<dependency>
			<groupId>org.eclipse.platform</groupId>
			<artifactId>org.eclipse.core.resources</artifactId>
			<version>3.14.0</version>
		</dependency>
Comment 5 Amy Brennan-Luna CLA 2021-09-12 10:51:54 EDT
I can also confirm the issue remains in org.eclipse.jdt.core version 3.26.0 using JDK 11

		<dependency>
			<groupId>org.eclipse.jdt</groupId>
			<artifactId>org.eclipse.jdt.core</artifactId>
			<version>3.26.0</version>
		</dependency>
Comment 6 Eclipse Genie CLA 2023-09-03 10:26:01 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.