eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
164 stars 130 forks source link

[code select] Unexpected runtime error while computing a text hover: java.lang.NegativeArraySizeException #3050

Closed nlisker closed 1 month ago

nlisker commented 1 month ago
import java.util.function.Function;

public class Hover {

    void d() {
        Function<Object, Object> f = d -> 2;
        switch (f) {
            case Function<?, ?> s -> {}
        }
    }
}

Hover over the switch branch: Function, ->, or s. The error log reports:

eclipse.buildId=4.33.0.I20240903-0240
java.version=22
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Command-line arguments:  -os win32 -ws win32 -arch x86_64

org.eclipse.jface.text
Error
Unexpected runtime error while computing a text hover

java.lang.NegativeArraySizeException: -1
    at org.eclipse.jdt.internal.compiler.parser.Parser.consumeTypeReferenceWithModifiersAndAnnotations(Parser.java:4570)
    at org.eclipse.jdt.internal.compiler.parser.Parser.consumeTypePattern(Parser.java:10389)
    at org.eclipse.jdt.internal.compiler.parser.Parser.consumeRule(Parser.java:7277)
    at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:12684)
    at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:2112)
    at org.eclipse.jdt.internal.codeassist.impl.AssistParser.parseBlockStatements(AssistParser.java:1948)
    at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:350)
    at org.eclipse.jdt.internal.codeassist.impl.Engine.parseBlockStatements(Engine.java:313)
    at org.eclipse.jdt.internal.codeassist.SelectionEngine.select(SelectionEngine.java:1080)
    at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:166)
    at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:382)
    at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:375)
    at org.eclipse.jdt.internal.ui.text.java.hover.AbstractJavaEditorTextHover.getJavaElementsAt(AbstractJavaEditorTextHover.java:121)
    at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.lambda$0(JavadocHover.java:713)
    at org.eclipse.jdt.internal.core.JavaModelManager.cacheZipFiles(JavaModelManager.java:5770)
    at org.eclipse.jdt.internal.core.JavaModelManager.callReadOnly(JavaModelManager.java:5759)
    at org.eclipse.jdt.core.JavaCore.callReadOnly(JavaCore.java:6188)
    at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.internalGetHoverInfo(JavadocHover.java:713)
    at org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover.getHoverInfo2(JavadocHover.java:709)
    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:130)
    at org.eclipse.jdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy.getHoverInfo2(JavaEditorTextHoverProxy.java:89)
    at org.eclipse.jface.text.TextViewerHoverManager$1.run(TextViewerHoverManager.java:155)
srikanth-sankaran commented 1 month ago

Reproduced, thanks for the report, I will take a look.

nlisker commented 1 month ago

Thanks for the super quick fix!