eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
149 stars 116 forks source link

[dom ast] NPE from ASTConverter on typing #2494

Open noopur2507 opened 1 month ago

noopur2507 commented 1 month ago
public class Snippet {

    public static void m(Object object) {

        if (object instanceof Path(Pos(int x1, int y1), _)) {
              System.out.printf("object is a path starting at x = %d, y = %d%n", x1, y1);
        }
    }
}

record Pos(int x, int y) {

}

record Path(Pos p1, Pos p2) {

}

Have this code in a Java 22 project. Just click or type anything in this file. We get the following error messages in the Error Log view:

java.lang.NullPointerException: Cannot invoke "org.eclipse.jdt.internal.compiler.ast.TypeReference.extraDimensions()" because "typeReference" is null
    at org.eclipse.jdt.core.dom.ASTConverter.convertToSingleVariableDeclaration(ASTConverter.java:4074)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3641)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2953)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2367)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2944)
    at org.eclipse.jdt.core.dom.ASTConverter.convertToPatternInstanceOfExpression(ASTConverter.java:2432)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2406)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2111)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2390)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3212)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:813)
    at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:208)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:3567)
    at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1595)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:345)
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateASTCached(ASTParser.java:1275)
    at org.eclipse.jdt.core.dom.ASTParser.lambda$0(ASTParser.java:1126)
    at org.eclipse.jdt.internal.core.JavaModelManager.cacheZipFiles(JavaModelManager.java:5765)
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1126)
    at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:874)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider$1.run(CoreASTProvider.java:294)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.createAST(CoreASTProvider.java:286)
    at org.eclipse.jdt.core.manipulation.CoreASTProvider.getAST(CoreASTProvider.java:199)
    at org.eclipse.jdt.core.manipulation.SharedASTProviderCore.getAST(SharedASTProviderCore.java:138)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:167)
...
srikanth-sankaran commented 1 month ago

I think we are ill prepared to deal with unnamed patterns at that point.

srikanth-sankaran commented 1 month ago

@subyssurendran666 - Per Manoj's request can you please take this up ? Thanks, I am unable to assign this to you

mpalat commented 1 month ago

@subyssurendran666 can you please take this up?

subyssurendran666 commented 1 month ago

@subyssurendran666 can you please take this up?

Sure @mpalat

mpalat commented 1 week ago

@subyssurendran666 - I believe we will have to do a design change here - Neither The changes to SVD (SingleVariableDeclaration) nor the NullType/NoType pattern look like the right approach - agree that I am also culprit to these proposals, but both do not seem perfect - rather each resonates an afterthought. I believe we should be looking at an approach similar to TypeElided LambdaExpression as we initially planned. Would suggest to create a new issue to investigate such a design change. Specifically the suggestion is to replace SVD in TypePattern with Parameters. Let us go down that path and see whether we get a more appropriate solution. will discuss. Thanks!

subyssurendran666 commented 1 week ago

https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2623