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

Bug 366014

Summary: Make it easier to setup null analysis
Product: [Eclipse Project] JDT Reporter: Dani Megert <daniel_megert>
Component: UIAssignee: Markus Keller <markus.kell.r>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P2 CC: christoph, daniel_megert, deepakazad, loskutov, markus.kell.r, srikanth_sankaran, stephan.herrmann
Version: 3.8   
Target Milestone: 3.8 M7   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 366015    

Description Dani Megert CLA 2011-12-08 07:08:40 EST
I20111207-2118.

Make it easier to setup null analysis.

Ideas:
- Add Quick Assists that allow to declare stuff as being null/non-null and
  when invoked, help with the initial setup (if needed).
- Do it similar to what we do for JUnit4.
Comment 1 Markus Keller CLA 2011-12-08 10:27:55 EST
For normal Java projects we can't do much other than putting the JAR on the build path. Maybe generalize and reuse the JUnit library container.

But for PDE, we should only add it as compile-time dependency ("additional.bundles = org.eclipse.jdt.annotation" in build.properties), not as OSGi Require-Bundle.
Comment 2 Stephan Herrmann CLA 2011-12-11 14:38:29 EST
*** Bug 366326 has been marked as a duplicate of this bug. ***
Comment 3 Markus Keller CLA 2012-04-25 08:18:03 EDT
Added quick fixes on the nullity annotations (only if the project uses the default annotation names).
http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=b52baf374d7a2d8bfed5b4948fb8207b71526d9c
Comment 4 Deepak Azad CLA 2012-04-25 09:05:43 EDT
- Quick fixes are shown even if the jar is on the build path. This can be confusing as once the jar is already added there is still an error because of the missing import statement.

For plugin projects executing the Quick fix can result in multiple 'additional.bundles = org.eclipse.jdt.annotation' entries.

- For plugin projects we show both 'Copy to build path..' and 'Add to build path..', shouldn't we show only 'Add to build path...' one?
Comment 5 Deepak Azad CLA 2012-04-25 10:27:21 EDT
> Copy org.eclipse.jdt.annotation.jar to build path
The jar name should be in single quotes.
Comment 6 Markus Keller CLA 2012-04-25 13:44:56 EDT
Follow-up commit with fixes for all problems:
http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=3fd4a3b1d5804b7987b3315b97d28ec8fd11fff7

> - For plugin projects we show both 'Copy to build path..' and 'Add to build
> path..', shouldn't we show only 'Add to build path...' one?

I originally intended it to show both options for maximal flexibility, but I agree it rarely happens that plug-in developers don't want to use a reference.
Comment 7 Deepak Azad CLA 2012-04-26 02:19:02 EDT
You get an exception when additional.bundles already exists. 
org.eclipse.jface.text.BadLocationException
	at org.eclipse.jface.text.TreeLineTracker.fail(TreeLineTracker.java:1055)
	at org.eclipse.jface.text.TreeLineTracker.offsetByLine(TreeLineTracker.java:334)
	at org.eclipse.jface.text.TreeLineTracker.getLineOffset(TreeLineTracker.java:1122)
	at org.eclipse.jface.text.AbstractLineTracker.getLineOffset(AbstractLineTracker.java:169)
	at org.eclipse.jface.text.AbstractDocument.getLineOffset(AbstractDocument.java:922)
	at org.eclipse.core.internal.filebuffers.SynchronizableDocument.getLineOffset(SynchronizableDocument.java:382)
	at org.eclipse.jdt.internal.ui.text.correction.UnresolvedElementsSubProcessor$1.createChange(UnresolvedElementsSubProcessor.java:692)
	at org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal.getChange(ChangeCorrectionProposal.java:372)
	at org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal.performChange(ChangeCorrectionProposal.java:136)
	at org.eclipse.jdt.ui.text.java.correction.ChangeCorrectionProposal.apply

Fixed with http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=a918f74c71001dc67e1c502cfd21cb174a7199c4

Rest looks good.
Comment 8 Dani Megert CLA 2012-05-01 08:19:11 EDT
Verified in 4.2-I20120430-1800.
Comment 9 pascal christoph CLA 2015-10-09 03:17:50 EDT
(moved this from https://bugs.eclipse.org/bugs/show_bug.cgi?id=366327 . I don't know where the right place for this is , I am as more unsure as this Bug is taged as "fixed". Anyway, here is my problem:)
This Bug is still active. Using java8 features like using a stream and converting that into a string array:

 (new ArrayList<>()).stream().toArray(String[]::new);

results in
"The type org.eclipse.jdt.annotation.NonNull cannot be resolved. It is indirectly referenced from required .class files"
And with this the class cannot be compiled. Using cli javac everything compiles just fine.

I am using eclipse Mars.

The workaround I use is to disable the "annotation-based null analysis" in project->properties->java-compiler...
Comment 10 Stephan Herrmann CLA 2015-10-09 03:42:35 EDT
(In reply to pascal christoph from comment #9)
> (moved this from https://bugs.eclipse.org/bugs/show_bug.cgi?id=366327 . I
> don't know where the right place for this is , I am as more unsure as this
> Bug is taged as "fixed". Anyway, here is my problem:)
> This Bug is still active. Using java8 features like using a stream and
> converting that into a string array:
> 
>  (new ArrayList<>()).stream().toArray(String[]::new);
> 
> results in
> "The type org.eclipse.jdt.annotation.NonNull cannot be resolved. It is
> indirectly referenced from required .class files"
> And with this the class cannot be compiled. Using cli javac everything
> compiles just fine.
> 
> I am using eclipse Mars.
> 
> The workaround I use is to disable the "annotation-based null analysis" in
> project->properties->java-compiler...

Now that I see your problem, I filed bug 479389 to follow up.


This current (fixed) bug provided a quick fix to add null annotations to the build path, when they are referenced in source code but cannot be found.

Your problem, by contrast, originates from implicit use of null annotations within the compiler. To be continued in the new bug.