Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 347021 - NPE hovering in half broken program
Summary: NPE hovering in half broken program
Status: RESOLVED FIXED
Alias: None
Product: AJDT
Classification: Tools
Component: UI (show other bugs)
Version: 2.1.2   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 2.1.3   Edit
Assignee: AJDT-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-24 12:57 EDT by Andrew Clement CLA
Modified: 2011-06-11 01:33 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Clement CLA 2011-05-24 12:57:50 EDT
Hovering over 'Fun1' in the map ITD, i get:


java.lang.NullPointerException
	at org.eclipse.ajdt.core.text.ITDAwareSelectionRequestor.acceptType(ITDAwareSelectionRequestor.java:286)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.selectFrom(SelectionEngine.java:1098)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:938)
	at org.eclipse.ajdt.core.text.ITDCodeSelection.findJavaElement(ITDCodeSelection.java:97)
	at org.eclipse.ajdt.internal.core.contentassist.ContentAssistProvider.doCodeSelect(ContentAssistProvider.java:167)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect_aroundBody1$advice(CompilationUnit.java:317)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:1)
	at org.eclipse.jdt.internal.ui.text.java.hover.AbstractJavaEditorTextHover.getJavaElementsAt(AbstractJavaEditorTextHover.java:115)
	at org.codehaus.groovy.eclipse.editor.GroovyExtraInformationHover.getHoverInfo2(GroovyExtraInformationHover.java:39)
	at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:141)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy.getHoverInfo2(JavaEditorTextHoverProxy.java:82)
	at org.eclipse.jface.text.TextViewerHoverManager$4.run(TextViewerHoverManager.java:166)

This is IterableAspect.aj:
===
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;


class C implements Iterable<String> {

	@Override
	public Iterator<String> iterator() {
		return null;
	}
	
} 

abstract aspect IterableAspect<T> pertypewithin(Iterable<T>+){
	
	interface Fun1<T,R> {
		R apply(T param);
	}

	public <R> Collection<R> Iterable.map(Fun1<T,R> fun) {
		Collection<R> result=new ArrayList<R>();
		for (T value : this) {
			result.add(fun.apply(value));
		}
		return result;
	}
}

===
Comment 1 Andrew Eisenberg CLA 2011-05-30 19:57:56 EDT
Looks like there are several problems here.

First, this class still has 'this' with a spurious error:

import java.util.Iterator;
class C implements Iterable<String> {
	public Iterator<String> iterator() {
		return null;
	}
}

abstract aspect IterableAspect {

	public void C.map() {
		for (String value : this) {
		}
	}
}

Second, the NPE that you are seeing is happening because AJDT is getting tripped up in some code that is looking for ITITs.  This is easy enough to fix.

Third, it doesn't look like the type parameters in the ITD are being applied to Iterable.
Comment 2 Andrew Eisenberg CLA 2011-06-10 18:30:10 EDT
The NPE has now been fixed, but I am keeping this bug open because of the other problems that it has uncovered.
Comment 3 Andrew Eisenberg CLA 2011-06-10 19:06:35 EDT
OK.  For the spurious error, I have a solution.  We will ignore all type errors when the target expression is 'this' and we are inside ITDs.  Ignoring these errors in these situations is narrow enough that we shouldn't get into trouble.

I have the implementaiton locally, but need to write some tests before I commit.
Comment 4 Andrew Eisenberg CLA 2011-06-11 01:31:24 EDT
Now fixed.  Committed with regression tests.