Bug 341759 - NPE in ITypeBinding#getName() for intersection type
Summary: NPE in ITypeBinding#getName() for intersection type
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.7 M7   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-04 05:59 EDT by Markus Keller CLA
Modified: 2011-04-26 00:43 EDT (History)
2 users (show)

See Also:


Attachments
Proposed fix + regression test (1.70 KB, patch)
2011-04-07 11:40 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2011-04-04 05:59:46 EDT
N20110403-2000

- Have this class:

package xy;
public class Try {
    void test(String s, Integer i) {
        combine(s, i).compareTo(null); //1
        Comparable comp= combine(s, i); //2
        java.io.Serializable ser= combine(s, i); //3
        combine(s, i); //4
        //bug99922 java.util.Arrays.asList(s, i);
    }

    <T> T combine(T t1, T t2) {
        return Math.random() > 0 ? t1 : t2;
    }
}

- open ASTView on "combine(s, i)"
- expand the type binding of the SimpleName "combine"

java.lang.NullPointerException
	at java.lang.String.<init>(String.java:177)
	at org.eclipse.jdt.core.dom.TypeBinding.getName(TypeBinding.java:656)
	at org.eclipse.jdt.core.dom.TypeBinding.getQualifiedName(TypeBinding.java:786)
	at org.eclipse.jdt.astview.views.Binding.getLabel(Binding.java:315)
	at org.eclipse.jdt.astview.views.ASTViewLabelProvider.getText(ASTViewLabelProvider.java:78)
	at org.eclipse.jface.viewers.WrappedViewerLabelProvider.getText(WrappedViewerLabelProvider.java:108)
	at org.eclipse.jface.viewers.WrappedViewerLabelProvider.update(WrappedViewerLabelProvider.java:164)
	at org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerColumn.java:152)
	at org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:938)
Comment 1 Markus Keller CLA 2011-04-04 06:26:15 EDT
Note that the problematic binding is not the type binding for the expression type of "combine(s, i)", but the result of calling getGenericTypeOfWildcardType() on that type.
Comment 2 Olivier Thomann CLA 2011-04-04 07:45:41 EDT
I have a trivial fix for this one. The method getGenericTypeOfWildcardType() should return null for an intersection type.
Comment 3 Olivier Thomann CLA 2011-04-07 11:40:16 EDT
Created attachment 192758 [details]
Proposed fix + regression test

I don't touch other cases for intersection types like getRank(), isUpperBound(), getName(), getQualifiedName(), getBound(). This will be done when fixing bug 99931.
Comment 4 Olivier Thomann CLA 2011-04-07 13:26:18 EDT
Released in HEAD and BETA_JAVA7 branch.
The NPE came from trying to display the name of the generic type of wildcard for an intersection type.
To prevent it, the call to getGenericTypeOfWildcardType() now returns null for intersection type.
Comment 5 Jay Arthanareeswaran CLA 2011-04-26 00:43:06 EDT
Verified for 3.7M7 using build I20110421-1800