Bug 537014 - [10] "Unexpected runtime error when computing a text hover" for java 10 var
Summary: [10] "Unexpected runtime error when computing a text hover" for java 10 var
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.8   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.14 M1   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-13 09:49 EDT by Clovis Seragiotto CLA
Modified: 2019-10-09 06:22 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Clovis Seragiotto CLA 2018-07-13 09:49:02 EDT
import java.util.*;

public class Hey {
    public static void main(String[] args) {
        var x = args.length > 0 ? new TreeSet<>() : new HashSet<>();
        x.add(1);
    }
}

When computing the text hover for x:


java.lang.IllegalArgumentException: java.util.AbstractSet<java.lang.Object>&java.lang.Cloneable&java.io.Serializable
	at org.eclipse.jdt.core.Signature.createCharArrayTypeSignature(Signature.java:1097)
	at org.eclipse.jdt.core.Signature.createTypeSignature(Signature.java:1293)
	at org.eclipse.jdt.internal.core.SelectionRequestor.acceptLocalVariable(SelectionRequestor.java:476)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.selectFrom(SelectionEngine.java:1385)
	at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:1083)
	at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:165)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:387)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:380)
	at org.eclipse.jdt.internal.ui.text.java.hover.AbstractJavaEditorTextHover.getJavaElementsAt(AbstractJavaEditorTextHover.java:121)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.internalGetHoverInfo(JavadocHover.java:671)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.getHoverInfo2(JavadocHover.java:667)
	at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:164)
	at org.eclipse.jdt.internal.ui.text.java.hover.BestMatchHover.getHoverInfo2(BestMatchHover.java:130)
	at org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy.getHoverInfo2(JavaEditorTextHoverProxy.java:86)
	at org.eclipse.jface.text.TextViewerHoverManager$4.run(TextViewerHoverManager.java:166)
Comment 1 Noopur Gupta CLA 2018-07-13 11:33:39 EDT
Jay, can you please check?
Comment 2 Eclipse Genie CLA 2018-07-15 18:09:23 EDT
New Gerrit change created: https://git.eclipse.org/r/126080
Comment 3 Stephan Herrmann CLA 2018-07-15 18:14:01 EDT
(In reply to Eclipse Genie from comment #2)
> New Gerrit change created: https://git.eclipse.org/r/126080

Draft of a possible fix. Feel free to modify ...


Note: Back in https://git.eclipse.org/r/#/c/119966/ I simply advised to add a comment regarding the unfortunate swap of | vs &.

Today, when looking at the implementation of org.eclipse.jdt.internal.core.util.Util.typeSignature(TypeReference) I'm utterly confused by this paragraph:

if ((type.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.IsUnionType) != 0) {
	// special treatment for union type reference
	UnionTypeReference unionTypeReference = (UnionTypeReference) type;
	TypeReference[] typeReferences = unionTypeReference.typeReferences;
	String[] typeSignatures = typeSignatures(typeReferences);
	signature = Signature.createIntersectionTypeSignature(typeSignatures);
} else if (type instanceof IntersectionCastTypeReference) {
	IntersectionCastTypeReference intersection = (IntersectionCastTypeReference) type;
	TypeReference[] typeReferences = intersection.typeReferences;
	String[] typeSignatures = typeSignatures(typeReferences);
	signature = Signature.createUnionTypeSignature(typeSignatures);
} else {

so, red is green and green is red? Really??
Comment 4 Manoj N Palat CLA 2019-02-11 04:16:14 EST
Bulk move out of 4.11
Comment 5 Stephan Herrmann CLA 2019-09-15 08:39:12 EDT
(In reply to Stephan Herrmann from comment #3)
> Note: Back in https://git.eclipse.org/r/#/c/119966/ I simply advised to add
> a comment regarding the unfortunate swap of | vs &.
> 
> Today, when looking at the implementation of
> org.eclipse.jdt.internal.core.util.Util.typeSignature(TypeReference) I'm
> utterly confused by this paragraph:
> 
> if ((type.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.IsUnionType)
> != 0) {
> 	// special treatment for union type reference
> 	UnionTypeReference unionTypeReference = (UnionTypeReference) type;
> 	TypeReference[] typeReferences = unionTypeReference.typeReferences;
> 	String[] typeSignatures = typeSignatures(typeReferences);
> 	signature = Signature.createIntersectionTypeSignature(typeSignatures);
> } else if (type instanceof IntersectionCastTypeReference) {
> 	IntersectionCastTypeReference intersection =
> (IntersectionCastTypeReference) type;
> 	TypeReference[] typeReferences = intersection.typeReferences;
> 	String[] typeSignatures = typeSignatures(typeReferences);
> 	signature = Signature.createUnionTypeSignature(typeSignatures);
> } else {
> 
> so, red is green and green is red? Really??

I pushed this to a new bug 551077 to unblock this bug.
Comment 7 Stephan Herrmann CLA 2019-09-15 10:53:44 EDT
(In reply to Eclipse Genie from comment #6)
> Gerrit change https://git.eclipse.org/r/126080 was merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=5b9892bd4cc46055e381266dc749bbc43aff733b

Resolved for 4.14 M1
Comment 8 Manoj N Palat CLA 2019-10-09 06:22:57 EDT
Verified for Eclipse Version: 2019-12 (4.14) M1 with  Build id: I20191008-1800