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

Bug 380520

Summary: [hovering] NPE in JavaSourceHover.getBracketHoverInfo
Product: [Eclipse Project] JDT Reporter: Dani Megert <daniel_megert>
Component: TextAssignee: Deepak Azad <deepakazad>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, markus.kell.r
Version: 3.8Flags: daniel_megert: review-
markus.kell.r: review+
deepakazad: review+
Target Milestone: 3.8 RC2   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
fix
daniel_megert: review-
Fix none

Description Dani Megert CLA 2012-05-24 05:57:06 EDT
I20120521-2100.

Found in .log - no steps.

!ENTRY org.eclipse.jface.text 4 0 2012-05-24 10:51:50.586
!MESSAGE Unexpected runtime error while computing a text hover
!STACK 0
java.lang.NullPointerException
	at org.eclipse.jdt.internal.ui.text.java.hover.JavaSourceHover.getBracketHoverInfo(JavaSourceHover.java:129)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavaSourceHover.getHoverInfo(JavaSourceHover.java:96)
	at org.eclipse.jdt.internal.ui.text.java.hover.AbstractJavaEditorTextHover.getHoverInfo2(AbstractJavaEditorTextHover.java:84)
	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)
Comment 1 Dani Megert CLA 2012-05-24 06:05:39 EDT
Happens when the hover is about to be computed and the editor gets closed in-between.

Set bpt on IDocument document= textViewer.getDocument();
Comment 2 Deepak Azad CLA 2012-05-24 06:23:42 EDT
Created attachment 216189 [details]
fix

I guess the solution is to add a null check.
Comment 3 Dani Megert CLA 2012-05-24 10:09:03 EDT
Comment on attachment 216189 [details]
fix

This just fixes the 1. instance of the problem. Next NPE to come when the matcher is reached.
Comment 4 Dani Megert CLA 2012-05-24 10:10:58 EDT
Created attachment 216195 [details]
Fix

This fixes all the holes. The patch is not minimal as it also cleans up the code a little bit, but the changes are straightforward.
Comment 5 Markus Keller CLA 2012-05-24 10:40:10 EDT
(In reply to comment #4)
> Created attachment 216195 [details] [diff]
> Fix

Looks good, and I didn't find any more holes. +1 for RC2 or RC3.

Just one potential memory problem: If the editor is closed right before "display.syncExec(..)", topLine ends up being -1, and in the end we copy all lines in front of the "}", just to throw them away later.

I would add this just after "int topLine= topIndex[0];":

			if (topLine == -1)
				return null;
Comment 6 Deepak Azad CLA 2012-05-24 11:59:23 EDT
Looks good to me as well.

Released to master and integration including the change from comment 5
http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=48bbac49f9ea2da88cbe94a5f025e1edd2f5c38c
Comment 7 Deepak Azad CLA 2012-05-24 11:59:41 EDT
.
Comment 8 Dani Megert CLA 2012-05-25 02:57:10 EDT
Verified in I20120524-2300.