Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 535927

Summary: [compile] NullPointerException when importing deprecated class in Java 10 project
Product: [Eclipse Project] JDT Reporter: Lukas Eder <lukas.eder>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED DUPLICATE QA Contact:
Severity: critical    
Priority: P3 CC: jarthana, manoj.palat, stephan.herrmann
Version: 4.7.3   
Target Milestone: 4.9 M2   
Hardware: PC   
OS: Windows 10   
Whiteboard:
Attachments:
Description Flags
NPETest2.zip none

Description Lukas Eder CLA 2018-06-15 04:49:37 EDT
Created attachment 274471 [details]
NPETest2.zip

Note, I'm actually using Eclipse 4.7.3a, but that option wasn't available in Bugzilla:

Version: Oxygen.3a Release (4.7.3a)
Build id: 20180405-1200

I'm getting the following NullPointerException when compiling a class that imports a deprecated type:



!ENTRY org.eclipse.jdt.core 4 4 2018-06-15 10:41:04.537
!MESSAGE Exception occurred during problem detection:
----------------------------------- SOURCE BEGIN -------------------------------------
package p2;

import p1.C1;

public class C2 {
}

----------------------------------- SOURCE END -------------------------------------
!STACK 0
java.lang.NullPointerException

!ENTRY org.eclipse.jdt.ui 4 2 2018-06-15 10:41:04.540
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jdt.ui".
!STACK 1
Java Model Exception: java.lang.NullPointerException
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:254)
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:276)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:191)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:90)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:724)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:790)
	at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1260)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:128)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.access$0(JavaReconcilingStrategy.java:110)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:90)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:87)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:154)
	at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:89)
	at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:104)
	at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:73)
	at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:207)
Caused by: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
!SUBENTRY 1 org.eclipse.jdt.core 4 1005 2018-06-15 10:41:04.541
!MESSAGE java.lang.NullPointerException
!STACK 0
java.lang.NullPointerException
!SUBENTRY 1 org.eclipse.jdt.core 4 1005 2018-06-15 10:41:04.541
!MESSAGE java.lang.NullPointerException
!STACK 0
java.lang.NullPointerException

!ENTRY org.eclipse.jdt.ui 4 0 2018-06-15 10:41:04.543
!MESSAGE Error in JDT Core during reconcile
!STACK 1
Java Model Exception: java.lang.NullPointerException
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:254)
	at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:276)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:191)
	at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:90)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:724)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:790)
	at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1260)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:128)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.access$0(JavaReconcilingStrategy.java:110)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:90)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:87)
	at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:154)
	at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:89)
	at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:104)
	at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:73)
	at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:207)
Caused by: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
!SUBENTRY 1 org.eclipse.jdt.core 4 1005 2018-06-15 10:41:04.544
!MESSAGE java.lang.NullPointerException
!STACK 0
java.lang.NullPointerException

!ENTRY org.eclipse.core.jobs 4 2 2018-06-15 10:41:06.800
!MESSAGE An internal error occurred during: "Compute launch button tooltip".
!STACK 0
java.lang.NullPointerException


-------------------------------------------------------------------------------

In the above MVCE, the problem doesn't appear all the time. Keep cleaning / building the project several times until the issue pops up.

In a more complex project setup (which I cannot provide an MVCE for), the same NPE appears at a different location, which seems to be the actual cause of the above problem. When setting a breakpoint on org.eclipse.jdt.internal.compiler.problem.ProblemHandler.handle(ProblemHandler.java:145), it can be seen that it's always the same null reference causing the issue:



!ENTRY org.eclipse.core.resources 4 75 2018-06-15 10:08:32.205
!MESSAGE Errors occurred during the build.
!SUBENTRY 1 org.eclipse.jdt.core 4 75 2018-06-15 10:08:32.217
!MESSAGE Errors running builder 'Java Builder' on project 'jOOQ-test'.
!STACK 0
java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.problem.ProblemHandler.handle(ProblemHandler.java:145)
	at org.eclipse.jdt.internal.compiler.problem.ProblemHandler.handle(ProblemHandler.java:226)
	at org.eclipse.jdt.internal.compiler.problem.ProblemReporter.handle(ProblemReporter.java:2513)
	at org.eclipse.jdt.internal.compiler.problem.ProblemReporter.deprecatedType(ProblemReporter.java:1831)
	at org.eclipse.jdt.internal.compiler.problem.ProblemReporter.deprecatedType(ProblemReporter.java:1808)
	at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.checkAndRecordImportBinding(CompilationUnitScope.java:960)
	at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInImports(CompilationUnitScope.java:471)
	at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:501)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:878)
	at org.eclipse.jdt.internal.compiler.ProcessTaskManager.run(ProcessTaskManager.java:141)
	at java.lang.Thread.run(Unknown Source)


-------------------------------------------------------------------------------


This only seems to happen with Java 10, not with Java 8 (haven't tested Java 9).

It is currently completely blocking my upgrade to Java 10 (and the modularisation of jOOQ). I'll continue investigating this, hopefully finding a possible patch.

A related issue is this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=529176
Comment 1 Lukas Eder CLA 2018-06-15 05:07:10 EDT
The problem is located in:

------------------------
org.eclipse.jdt.internal.compiler.problem.ProblemReporter.deprecatedType(TypeBinding type, ASTNode location, int index)
------------------------

The method call

------------------------
String sinceValue = deprecatedSinceValue(() -> leafType.getAnnotations());
------------------------

... resets ProblemReporter.referenceContext to null, just prior to the call to this.handle() thereafter, which needs the reference to the referenceContext to be present.


I've deactivated the feature by applying

------------------------
String deprecatedSinceValue(Supplier<AnnotationBinding[]> annotations) {
	if (true)
		return null;
------------------------

Effectively ignoring the functionality, and this "fixes" the NPE
Comment 2 Stephan Herrmann CLA 2018-06-15 12:09:10 EDT
(In reply to Lukas Eder from comment #0)
> A related issue is this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=529176

Thanks for report and link.

I believe this is the exact same issue. And in bug 534304 we already have the connection to deprecatedSinceValue()

*** This bug has been marked as a duplicate of bug 534304 ***
Comment 3 Lukas Eder CLA 2018-06-17 05:51:20 EDT
Thanks for linking. Yes, those issues look the same. I couldn't seem to find the duplicates prior to my report.
Comment 4 Stephan Herrmann CLA 2018-06-17 07:32:31 EDT
Setting target milestone as the original bug has been fixed for 4.9 M2

@Lukas, it seems the bug is triggered by the combination of a deprecation warning and another problem on a sibling annotation next to @Deprecated. If you identify the second problem the NPE should be avoidable on your side. In your MVCE it's probably that @SW is detected to be unnecessary.

As always it would be great if you test-drive the latest I-build from http://download.eclipse.org/eclipse/downloads/#4.8_Integration_Builds (once you see one newer than 2018-06-16).
Comment 5 Lukas Eder CLA 2018-06-19 05:34:05 EDT
(In reply to Stephan Herrmann from comment #4)
> @Lukas, it seems the bug is triggered by the combination of a deprecation
> warning and another problem on a sibling annotation next to @Deprecated. If
> you identify the second problem the NPE should be avoidable on your side. In
> your MVCE it's probably that @SW is detected to be unnecessary.

It's complicated... The real world code is generated by a code generator. It will not be that easy to avoid the @SW annotation.

> As always it would be great if you test-drive the latest I-build from
> http://download.eclipse.org/eclipse/downloads/#4.8_Integration_Builds (once
> you see one newer than 2018-06-16).

Cool, does that mean you'll expect a backport? I'll keep an eye out for new builds and will report here, again.
Comment 6 Stephan Herrmann CLA 2018-06-19 05:46:00 EDT
(In reply to Lukas Eder from comment #5)
> > As always it would be great if you test-drive the latest I-build from
> > http://download.eclipse.org/eclipse/downloads/#4.8_Integration_Builds (once
> > you see one newer than 2018-06-16).
> 
> Cool, does that mean you'll expect a backport? I'll keep an eye out for new
> builds and will report here, again.

Sorry, here I was confused by the current strategy to (not) publish I-builds - see bug 534304 comment 13. 
Also note that 4.9 will be released only 3 months from now - cf. https://dev.eclipse.org/mhonarc/lists/cross-project-issues-dev/msg15021.html
Comment 7 Jay Arthanareeswaran CLA 2018-08-01 06:22:25 EDT
Verified for 4.9 M2 with build I20180731-2000