Bug 435213 - [Hover] NPE when Annotation not visible on classpath
Summary: [Hover] NPE when Annotation not visible on classpath
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks: 435279
  Show dependency tree
 
Reported: 2014-05-19 10:59 EDT by Holger Schill CLA
Modified: 2022-07-16 14:30 EDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Holger Schill CLA 2014-05-19 10:59:55 EDT
In the following scenario the hover is not shown. Instead of that a NPE is shown in the errorlog.

Bundle A has a class Foo and does not reexport org.eclipse.jdt.annotation.
import org.eclipse.jdt.annotation.NonNullByDefault;
@NonNullByDefault
class Foo {}

Bundle B has a dep to A and the following class that references Foo somehow:

class Bar extends Foo {}

Hover over Foo.

No hover is shown. The errorlog shows:

java.lang.NullPointerException
	at org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.createURI(JavaElementLinks.java:348)
	at org.eclipse.jdt.internal.ui.viewsupport.JavaElementLinks.createURI(JavaElementLinks.java:322)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.addAnnotation(JavadocHover.java:1073)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.getAnnotations(JavadocHover.java:1028)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.addAnnotations(JavadocHover.java:962)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.getHoverInfo(JavadocHover.java:685)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.internalGetHoverInfo(JavadocHover.java:607)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.getHoverInfo2(JavadocHover.java:599)
	at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:163)
	at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:129)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy.getHoverInfo2(JavaEditorTextHoverProxy.java:85)
	at org.eclipse.jface.text.TextViewerHoverManager$4.run(TextViewerHoverManager.java:166)

Caused by org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.addAnnotation(StringBuffer, IJavaElement, IAnnotationBinding)

since annotation.getAnnotationType().getJavaElement() is null when the Annotation is not visible.
Comment 1 Holger Schill CLA 2014-05-19 11:06:13 EDT
I forgot to mention that this only happens when the bundle A is installed in the IDE and consumed by bundle B in the workspace. Otherwise PDE would not handle the visibilities correct and the Annotation would be visible even when org.eclipse.jdt.annotation is not exported.
Comment 2 Dani Megert CLA 2014-05-19 11:35:38 EDT
(In reply to Holger Schill from comment #1)
> I forgot to mention that this only happens when the bundle A is installed in
> the IDE and consumed by bundle B in the workspace.

How is it "consumed"?
Comment 3 Martin Mathew CLA 2014-05-19 22:31:54 EDT
The issue was reproducible in Build id: I20140515-1230 with the hints provided in comment 1.

Steps to reproduce:
1. In the development WS create plugin 'com.test.bug435213A' and create public class 'Foo':
import org.eclipse.jdt.annotation.NonNullByDefault;
@NonNullByDefault
public class Foo {}
2. Open the plugin.xml file and in the 'Runtime' tab export the package containing 'Foo'.
3. Launch runtime Eclipse.
4. In the runtime WS create another plugin 'com.test.bug435213B' and create the 'Bar' class as mentioned in comment 0.
5. Get rid of all the compiler errors by adding 'com.test.bug435213A' to the current plugin dependency.
6. Now hovering over 'Foo' gives NPE as the type associated with the annotation binding is not resolved.

Moving to JDT/Core to understand why the type is not resolved from the annotation binding.
Comment 4 Stephan Herrmann CLA 2014-05-20 08:14:34 EDT
(In reply to Manju Mathew from comment #3)
> Moving to JDT/Core to understand why the type is not resolved from the
> annotation binding.

Can you please say which API is being used, and on what element exactly?
Comment 5 Martin Mathew CLA 2014-05-20 08:31:57 EDT
(In reply to Stephan Herrmann from comment #4)

> Can you please say which API is being used, and on what element exactly?
API being invoked is IAnnotationBinding#getAnnotationType() and it returns [MISSING:org.eclipse.jdt.annotation.NonNullByDefault]

JavadocHover#addAnnotation LN: 1073 invokes   annotation.getAnnotationType().getJavaElement() which in this case returns null and hence the NPE.
Comment 6 Srikanth Sankaran CLA 2014-07-17 04:07:09 EDT
Jay, please take a look. TIA,
Comment 7 Holger Schill CLA 2014-09-01 02:07:08 EDT
Any progress on that?
Comment 8 Markus Keller CLA 2014-09-01 13:42:30 EDT
No progress on the API side, but the NPE has been fixed in 4.4, see bug 435279.
Comment 9 Jay Arthanareeswaran CLA 2015-05-12 04:01:42 EDT
No progress on this. Moving out to 4.6.
Comment 10 Jay Arthanareeswaran CLA 2016-04-05 04:34:12 EDT
No progress yet and unlikely to get time during 4.6. Moving out.
Comment 11 Manoj N Palat CLA 2018-05-16 01:06:35 EDT
bulk move out of 4.8
Comment 12 Eclipse Genie CLA 2020-06-03 14:53:15 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 13 Stephan Herrmann CLA 2020-06-03 17:01:20 EDT
@Jay, feel free to assign to me, if you don't have time for this.
Comment 14 Jay Arthanareeswaran CLA 2020-06-03 23:04:42 EDT
(In reply to Stephan Herrmann from comment #13)
> @Jay, feel free to assign to me, if you don't have time for this.

The fact that this has been postponed forever is an indication that it's better of off my plate. Thanks for the offer, Stephan!
Comment 15 Eclipse Genie CLA 2022-07-16 14:30:36 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.