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

Bug 495635

Summary: [null] NPE in TypeVariableBinding.evaluateNullAnnotations
Product: [Eclipse Project] JDT Reporter: Chris Hubick <chris>
Component: CoreAssignee: Till Brychcy <register.eclipse>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jarthana, register.eclipse, stephan.herrmann
Version: 4.6Flags: stephan.herrmann: review+
Target Milestone: 4.6.1   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/75350
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=e8351b891768459b45fcffb1834de23e13352047
https://git.eclipse.org/r/78665
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=b789afe530d50c1b1770698f09bbacfff70907bb
Whiteboard:
Bug Depends on: 499393    
Bug Blocks:    
Attachments:
Description Flags
Maven Project ZIP none

Description Chris Hubick CLA 2016-06-07 17:31:25 EDT
What steps will reproduce the problem?
1. Press F3 on something to navigate to it's declaration.
2. 
3. 


-- Error Details --
Date: Tue Jun 07 15:22:49 MDT 2016
Message: Internal Error
Severity: Error
Product: Eclipse 4.6.0.20160601-1520 (org.eclipse.epp.package.java.product)
Plugin: org.eclipse.jdt.ui
Session Data:
eclipse.buildId=4.6.0.I20160525-2000
java.version=1.8.0_91
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_CA
Framework arguments:  -product org.eclipse.epp.package.java.product
Command-line arguments:  -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.java.product

This is a continuation of log file /run/media/hubick/chwork/eclipse_workspace/.metadata/.bak_0.log
Created Time: 2016-06-07 15:16:15.771

Exception Stack Trace:
java.lang.reflect.InvocationTargetException
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:398)
	at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:481)
	at org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog.run(ProgressMonitorJobsDialog.java:242)
	at org.eclipse.ui.internal.progress.ProgressManager$3.run(ProgressManager.java:895)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ui.internal.progress.ProgressManager.busyCursorWhile(ProgressManager.java:930)
	at org.eclipse.ui.internal.progress.ProgressManager.busyCursorWhile(ProgressManager.java:905)
	at org.eclipse.jdt.internal.ui.actions.SelectionConverter.performForkedCodeResolve(SelectionConverter.java:265)
	at org.eclipse.jdt.internal.ui.actions.SelectionConverter.codeResolveForked(SelectionConverter.java:170)
	at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:152)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:275)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:249)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
	at org.eclipse.jface.commands.ActionHandler.execute(ActionHandler.java:118)
	at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:54)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:282)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:264)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
	at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:494)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:488)
	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.executeCommand(KeyBindingDispatcher.java:286)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.press(KeyBindingDispatcher.java:507)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.processKeyEvent(KeyBindingDispatcher.java:558)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.filterKeySequenceBindings(KeyBindingDispatcher.java:378)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.access$0(KeyBindingDispatcher.java:324)
	at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher$KeyDownFilter.handleEvent(KeyBindingDispatcher.java:86)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1594)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1339)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1366)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1349)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1378)
	at org.eclipse.swt.widgets.Widget.gtk_key_press_event(Widget.java:764)
	at org.eclipse.swt.widgets.Control.gtk_key_press_event(Control.java:3458)
	at org.eclipse.swt.widgets.Composite.gtk_key_press_event(Composite.java:801)
	at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:2000)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:5820)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:5479)
	at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
	at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:9545)
	at org.eclipse.swt.widgets.Display.eventProc(Display.java:1275)
	at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
	at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:2495)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4130)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:687)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:604)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:138)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1492)
Caused by: java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding.evaluateNullAnnotations(TypeVariableBinding.java:932)
	at org.eclipse.jdt.internal.compiler.lookup.CaptureBinding.initializeBounds(CaptureBinding.java:252)
	at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.capture(ParameterizedTypeBinding.java:174)
	at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.capture(ParameterizedTypeBinding.java:1)
	at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.isCompatibleWith0(ReferenceBinding.java:1356)
	at org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.isCompatibleWith(ReferenceBinding.java:1282)
	at org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding.internalBoundCheck(TypeVariableBinding.java:256)
	at org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding.boundCheck(TypeVariableBinding.java:119)
	at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.boundCheck(ParameterizedTypeBinding.java:117)
	at org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference.checkBounds(ParameterizedSingleTypeReference.java:66)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.checkParameterizedTypeBounds(ClassScope.java:903)
	at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.checkParameterizedTypes(CompilationUnitScope.java:240)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.completeTypeBindings(LookupEnvironment.java:313)
	at org.eclipse.jdt.internal.codeassist.impl.Engine.accept(Engine.java:132)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:192)
	at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:214)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:3228)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getType(Scope.java:2940)
	at org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference.internalResolveLeafType(ParameterizedSingleTypeReference.java:187)
	at org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference.internalResolveType(ParameterizedSingleTypeReference.java:165)
	at org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference.resolveType(ParameterizedSingleTypeReference.java:382)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:590)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveSuperType(TypeReference.java:564)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.findSupertype(ClassScope.java:1320)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.connectSuperInterfaces(ClassScope.java:1052)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.connectTypeHierarchy(ClassScope.java:1114)
	at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.connectTypeHierarchy(CompilationUnitScope.java:324)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.completeTypeBindings(LookupEnvironment.java:312)
	at org.eclipse.jdt.internal.codeassist.impl.Engine.accept(Engine.java:132)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:192)
	at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:214)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:3228)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getType(Scope.java:2940)
	at org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference.internalResolveLeafType(ParameterizedSingleTypeReference.java:187)
	at org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference.internalResolveType(ParameterizedSingleTypeReference.java:165)
	at org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference.resolveType(ParameterizedSingleTypeReference.java:382)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:590)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveSuperType(TypeReference.java:564)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.findSupertype(ClassScope.java:1320)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.connectSuperInterfaces(ClassScope.java:1052)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.connectTypeHierarchy(ClassScope.java:1114)
	at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.connectTypeHierarchy(CompilationUnitScope.java:324)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.completeTypeBindings(LookupEnvironment.java:312)
	at org.eclipse.jdt.internal.codeassist.impl.Engine.accept(Engine.java:132)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:192)
	at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:214)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getTypeOrPackage(Scope.java:3228)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.getType(Scope.java:2940)
	at org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference.internalResolveLeafType(ParameterizedSingleTypeReference.java:187)
	at org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference.internalResolveType(ParameterizedSingleTypeReference.java:165)
	at org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference.resolveType(ParameterizedSingleTypeReference.java:382)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveType(TypeReference.java:590)
	at org.eclipse.jdt.internal.compiler.ast.TypeReference.resolveSuperType(TypeReference.java:564)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.findSupertype(ClassScope.java:1320)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.connectSuperInterfaces(ClassScope.java:1052)
	at org.eclipse.jdt.internal.compiler.lookup.ClassScope.connectTypeHierarchy(ClassScope.java:1114)
	at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.connectTypeHierarchy(CompilationUnitScope.java:324)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.completeTypeBindings(LookupEnvironment.java:312)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:973)
	at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:163)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:377)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:371)
	at org.eclipse.jdt.internal.ui.actions.SelectionConverter.codeResolve(SelectionConverter.java:274)
	at org.eclipse.jdt.internal.ui.actions.SelectionConverter$1CodeResolveRunnable.run(SelectionConverter.java:258)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Comment 1 Stephan Herrmann CLA 2016-06-07 17:46:56 EDT
(In reply to Chris Hubick from comment #0)
> What steps will reproduce the problem?
> 1. Press F3 on something to navigate to it's declaration.

I do that all the time - without NPE :)
Can you narrow it down to a small example?

> eclipse.buildId=4.6.0.I20160525-2000

= 4.6RC3


> Caused by: java.lang.NullPointerException
> 	at org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding.evaluateNullAnnotations(TypeVariableBinding.java:932)

We seem to have a CaptureBinding with null superInterfaces.
First guesses, why null:
+ some error during resolution? Chris, do you have compile errors?
+ some unexpected processing order?

> 	at org.eclipse.jdt.internal.compiler.lookup.CaptureBinding.initializeBounds(CaptureBinding.java:252)

This call to evaluateNullAnnotations() has been introduced via Bug 485058.
Comment 2 Chris Hubick CLA 2016-06-07 19:12:46 EDT
(In reply to Stephan Herrmann from comment #1)
> > 1. Press F3 on something to navigate to it's declaration.
> 
> I do that all the time - without NPE :)

I know, right?

> Can you narrow it down to a small example?

Not really, sorry... it's one of those weird things that just started happening, and I can't tell why.

I initially didn't even have null annotations enabled globally, and it was doing it, so I enabled them globally... though, thanks to Maven causing each project to use it's own settings, I'm not positively sure if some projects didn't have them enabled previously.

> We seem to have a CaptureBinding with null superInterfaces.
> First guesses, why null:
> + some error during resolution? Chris, do you have compile errors?
> + some unexpected processing order?

I've just finished cleaning up all compilation errors and even all the null analysis warnings, closed all other projects, and restarted Eclipse, and it's *still* doing it.

Sorry, I can't really be of more help :-(
Comment 3 Till Brychcy CLA 2016-06-08 02:29:31 EDT
>org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding.evaluateNullAnnotations(TypeVariableBinding.java:932)
	at > >org.eclipse.jdt.internal.compiler.lookup.CaptureBinding.initializeBounds(CaptureBinding.java:252)

In initializeBounds, setSuperInterfaces is invoked in all code paths before the invocation of evaluateNullAnnotations. This means, that the arg of setSuperInterfaces must have been a null in the case of the bug.
Comment 4 Till Brychcy CLA 2016-06-08 14:36:11 EDT
A test case would be really useful.

Maybe you can extract an example by a closing projects and removing code till the problem goes away.

While the bug happens happens some types are being connected with super interfaces and there are  type parameters involved.
There must be a type variable that has a bound that contains a wildcard, e.g. interface X<T extends Y<?>>, but probably with some kind of deeper nesting or mutual recursion or nested classes.
Comment 5 Chris Hubick CLA 2016-06-08 15:16:06 EDT
Created attachment 262325 [details]
Maven Project ZIP

Multi-Module Maven project in which I'm experiencing this bug.

Highlight "empty()" in ca.athabascau.regdata.model.student.person.StudentFilter.getStudentIDFilter() and press F3.

I'd prefer this attachment were deleted once reproduced, thanks.
Comment 6 Till Brychcy CLA 2016-06-08 15:32:05 EDT
Thanks, I can reproduce. As expected, type bounds like <O extends BannerPerson<K,O,?,?,?>> are involved. I'll distill a test case.

Unfortunately, I don't have the necessary rights to delete the attachment. 
@Stephan, can you do that?
Comment 7 Till Brychcy CLA 2016-06-09 15:14:06 EDT
Reduced test case (with a seperate .java for each interface):

public interface AURegObject {
}
--
public interface AURegKey<O extends AURegObject> {
}
--
public interface Person<O extends Person<O>> extends AURegObject, PersonKey<O> {
}
--
public interface PersonKey<O extends Person<?>> extends AURegKey<O> {
}

To reproduce, open Person.java, highlight PersonKey and press F3
Comment 8 Till Brychcy CLA 2016-06-09 16:01:04 EDT
I also noted the following, probably related problem:

public interface AURegType<O extends AURegObject<O>> {
}
--
public interface AURegBase<O extends AURegObject<O>> extends AURegType<O> {
}
--
public interface AURegKey<O extends AURegObject<O>> extends AURegBase<O> {
}
--
public interface AURegObject<O extends AURegObject<O>>
    extends AURegBase<O>, AURegKey<O> {
}

when AugRegKey.java is open, an error "The hierarchy for type AugRegKey is inconsistent" as red underline at "AURegKey" (nothing is shown in the problems view)
Comment 9 Till Brychcy CLA 2016-06-09 16:10:12 EDT
The problem from comment 8 already exists in 4.4.2, 4.5.0 and 4.5.2
Comment 10 Till Brychcy CLA 2016-06-11 12:19:53 EDT
Analysis for the example in comment 7:

While doing Connect.connectTypeHierarchy() for Person, Engine.accept(…) calls
LookupEnvironment.completeTypeBindings(CompilationUnitDeclaration, boolean) which invokes CompilationUnitScope.checkParameterizedTypes(). During that, a type variable is checked against the bound Person<?> and for this the capture-operation is invoked from ReferenceBinding.isCompatibleWith0(…), but the super interfaces of type variable of Person are still null, which leads to the NPE.

This does not happen during normal compilation which goes via LookupEnvironment.completeTypeBindings(), which first does connectTypeHierarchy for all involved compilation units and then invokes checkParameterizedTypes for all of them, so the super interfaces are already set in this case.

Therefore I think that adding a null check in TypeVariableBinding.evaluateNullAnnotations will be enough as fix. Also, I think that the invocation of that method should only be done if annotation based null analysis is enabled.
Comment 11 Chris Hubick CLA 2016-06-11 13:49:11 EDT
Much Thanks for looking into all this! :-)
Comment 12 Stephan Herrmann CLA 2016-06-11 14:04:53 EDT
(In reply to Till Brychcy from comment #10)
> Therefore I think that adding a null check in
> TypeVariableBinding.evaluateNullAnnotations will be enough as fix.

Is this saying: "we can skip null annotations because we're not within regular compilation"?
What invocations of the compiler are considered relevant?
- batch
- *Builder invocations
- CompilationUnitProblemFinder (part of "reconcile")


> Also, I
> think that the invocation of that method should only be done if annotation
> based null analysis is enabled.

That's always a good idea :)
(and already done on the other path into evaluateNullAnnotations())
Comment 13 Till Brychcy CLA 2016-06-12 06:57:01 EDT
(In reply to Stephan Herrmann from comment #12)
> (In reply to Till Brychcy from comment #10)
> > Therefore I think that adding a null check in
> > TypeVariableBinding.evaluateNullAnnotations will be enough as fix.
> 
> Is this saying: "we can skip null annotations because we're not within
> regular compilation"?
Basically, yes, at least in this kind of situation. 

> What invocations of the compiler are considered relevant?
> - batch
> - *Builder invocations
> - CompilationUnitProblemFinder (part of "reconcile")

Yes. 

Or, coming from the other side: the call hierarchy of 
CompilationUnitScope.checkParameterizedTypes() shows that the invocations that don't go via LookupEnvironment.completeTypeBindings() but via  LookupEnvironment.completeTypeBindings(CompilationUnitDeclaration, boolean) or LookupEnvironment.completeTypeBindings(CompilationUnitDeclaration[], boolean[], int) are all related to "non-compilation" topics as completion, selection, hierarchy and search. 

I wonder if whole invocation of CompilationUnitScope.checkParameterizedTypes is needed for any of these, or if it is just in there for symmetry reasons.

LookupEnvironment.completeTypeBindings(CompilationUnitDeclaration), which *is* used by Compiler classes, does not invoke CompilationUnitScope.checkParameterizedTypes()

> 
> 
> > Also, I
> > think that the invocation of that method should only be done if annotation
> > based null analysis is enabled.
> 
> That's always a good idea :)
> (and already done on the other path into evaluateNullAnnotations())
Comment 14 Till Brychcy CLA 2016-06-12 17:49:37 EDT
I've created bug 495953 for the problem in comment 8. Changing the compilation order by renaming AURegKey to AU1RegKey makes the problem appear even in the problems view.
Comment 15 Eclipse Genie CLA 2016-06-15 16:00:03 EDT
New Gerrit change created: https://git.eclipse.org/r/75350
Comment 17 Till Brychcy CLA 2016-06-16 14:48:57 EDT
(In reply to Eclipse Genie from comment #16)
> Gerrit change https://git.eclipse.org/r/75350 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=e8351b891768459b45fcffb1834de23e13352047

Released for 4.7M1
Comment 18 Till Brychcy CLA 2016-06-16 14:54:16 EDT
@Jay, this simple fix of a NPE might be good for 4.6.1
Comment 19 Jay Arthanareeswaran CLA 2016-08-02 04:04:25 EDT
Verified for 4.7 M1 with build I20160801-2000

Reopening the bug for 4.6.1.

Stephan, the review flag is yet to be set. Do you want to set it already or use it for 4.6.1?
Comment 20 Stephan Herrmann CLA 2016-08-02 06:15:36 EDT
(In reply to Jay Arthanareeswaran from comment #19)
> Verified for 4.7 M1 with build I20160801-2000
> 
> Reopening the bug for 4.6.1.
> 
> Stephan, the review flag is yet to be set. Do you want to set it already or
> use it for 4.6.1?

I think we're good for 4.7 M1, will do the review for 4.6.1.
Comment 21 Eclipse Genie CLA 2016-08-09 03:30:29 EDT
New Gerrit change created: https://git.eclipse.org/r/78665
Comment 22 Eclipse Genie CLA 2016-08-09 03:30:32 EDT
New Gerrit change created: https://git.eclipse.org/r/78665
Comment 23 Stephan Herrmann CLA 2016-08-09 07:58:05 EDT
A few observations during review (and while waiting for repo.eclipse.org to come back online):

Indeed all this happens in the gray zone of compiler invocations for services like completion, selection, type hierarchy, search. Indeed we may not be totally consistent here as to how much error detection we actually need. Any errors found will probably be ignored by the callers anyway.
In particular we may miss a null annotation on a super type and hence raise a false error from bound checking. But I don't see how this could harm a caller like code select.

For 4.6.1 the additional null check is definitely the right measure.

For future we could think of cutting down some of this unneeded processing, with double potential benefit:
- better performance
- avoidance of null checks for which in normal operation ("real compilation") we do not have any meaningful "else" implementation. For normal compiler development work I consider such checks as undesired clutter.

This needs to be balanced against the risk of having half-processed sources, which would raise errors at bogus locations. E.g.: when avoiding null analysis for secondary types, those types will not have any nullTagBits, and when performing null analysis of the focus type with secondary types in some signatures we will see bogus errors.
For another example see where NullAnnotationMatching checks for TagBits.PassedBoundCheck which will never be set if we skip checkParameterizedTypeBounds().
Comment 24 Stephan Herrmann CLA 2016-08-09 11:35:38 EDT
The change looks good to me.

In patch set #2 I made the necessary version update to 3.12.1 (this being the first real commit for 4.6.1).
Comment 25 Eclipse Genie CLA 2016-08-09 12:35:33 EDT
Gerrit change https://git.eclipse.org/r/78665 was merged to [R4_6_maintenance].
Commit: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=b789afe530d50c1b1770698f09bbacfff70907bb
Comment 26 Stephan Herrmann CLA 2016-08-09 12:36:36 EDT
(In reply to Eclipse Genie from comment #25)
> Gerrit change https://git.eclipse.org/r/78665 was merged to
> [R4_6_maintenance].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=b789afe530d50c1b1770698f09bbacfff70907bb
> 

Released for 4.6.1
Thanks, Till.
Comment 27 Jay Arthanareeswaran CLA 2016-08-17 00:47:45 EDT
Verified for 4.6.1 with build M20160810-1300.