eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
168 stars 132 forks source link

Compiler error: Cannot store to object array because "frame.stackItems" is null #2913

Open nlisker opened 2 months ago

nlisker commented 2 months ago

Using Eclipse Version: 2024-06 (4.32) Build id: I20240601-0610. Hopefully it was fixed for 4.33.

I'm getting compilation error on one of my larger classes: image

The error appears on the first line of the class: image

The log shows various stack traces that change as I manipulate the code:

Java Model Exception: java.lang.NullPointerException
    at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:324)
    at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:346)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:186)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:92)
    at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:740)
    at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:805)
    at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1311)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:132)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:94)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:91)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:158)
    at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:94)
    at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:107)
    at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:78)
    at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:207)
Caused by: java.lang.NullPointerException
Caused by: java.lang.NullPointerException

and

!ENTRY org.eclipse.jdt.ui 4 0 2024-09-05 04:46:16.634
!MESSAGE Error in JDT Core during reconcile
!STACK 1
Java Model Exception: java.lang.NullPointerException: Cannot store to object array because "frame.stackItems" is null
    at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:324)
    at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure(CompilationUnit.java:186)
    at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:245)
    at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:585)
    at org.eclipse.jdt.internal.core.CompilationUnit.makeConsistent(CompilationUnit.java:1137)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:166)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:92)
    at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:740)
    at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:805)
    at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1311)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:132)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:94)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:91)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:158)
    at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:94)
    at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:107)
    at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:78)
    at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:207)
Caused by: java.lang.NullPointerException: Cannot store to object array because "frame.stackItems" is null
    at org.eclipse.jdt.internal.compiler.ClassFile.traverse(ClassFile.java:7742)
    at org.eclipse.jdt.internal.compiler.ClassFile.generateStackMapTableAttribute(ClassFile.java:5483)
    at org.eclipse.jdt.internal.compiler.ClassFile.completeCodeAttribute(ClassFile.java:1708)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:408)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:324)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:762)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:832)
    at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode(CompilationUnitDeclaration.java:412)
    at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:1074)
    at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:272)
    ... 18 more
Caused by: java.lang.NullPointerException: Cannot store to object array because "frame.stackItems" is null
    at org.eclipse.jdt.internal.compiler.ClassFile.traverse(ClassFile.java:7742)
    at org.eclipse.jdt.internal.compiler.ClassFile.generateStackMapTableAttribute(ClassFile.java:5483)
    at org.eclipse.jdt.internal.compiler.ClassFile.completeCodeAttribute(ClassFile.java:1708)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:408)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:324)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:762)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:832)
    at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode(CompilationUnitDeclaration.java:412)
    at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:1074)
    at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:272)
    at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure(CompilationUnit.java:186)
    at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:245)
    at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:585)
    at org.eclipse.jdt.internal.core.CompilationUnit.makeConsistent(CompilationUnit.java:1137)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:166)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:92)
    at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:740)
    at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:805)
    at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1311)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:132)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:94)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:91)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:158)
    at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:94)
    at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:107)
    at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:78)
    at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:207)
!SUBENTRY 1 org.eclipse.jdt.core 4 1005 2024-09-05 04:46:16.635
!MESSAGE Cannot store to object array because "frame.stackItems" is null
!STACK 0
java.lang.NullPointerException: Cannot store to object array because "frame.stackItems" is null
    at org.eclipse.jdt.internal.compiler.ClassFile.traverse(ClassFile.java:7742)
    at org.eclipse.jdt.internal.compiler.ClassFile.generateStackMapTableAttribute(ClassFile.java:5483)
    at org.eclipse.jdt.internal.compiler.ClassFile.completeCodeAttribute(ClassFile.java:1708)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:408)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:324)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:762)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:832)
    at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode(CompilationUnitDeclaration.java:412)
    at org.eclipse.jdt.internal.compiler.Compiler.resolve(Compiler.java:1074)
    at org.eclipse.jdt.internal.core.CompilationUnitProblemFinder.process(CompilationUnitProblemFinder.java:272)
    at org.eclipse.jdt.internal.core.CompilationUnit.buildStructure(CompilationUnit.java:186)
    at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:245)
    at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:585)
    at org.eclipse.jdt.internal.core.CompilationUnit.makeConsistent(CompilationUnit.java:1137)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.makeConsistent(ReconcileWorkingCopyOperation.java:166)
    at org.eclipse.jdt.internal.core.ReconcileWorkingCopyOperation.executeOperation(ReconcileWorkingCopyOperation.java:92)
    at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:740)
    at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:805)
    at org.eclipse.jdt.internal.core.CompilationUnit.reconcile(CompilationUnit.java:1311)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:132)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy$1.run(JavaReconcilingStrategy.java:94)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:91)
    at org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReconcilingStrategy.java:158)
    at org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(CompositeReconcilingStrategy.java:94)
    at org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(JavaCompositeReconcilingStrategy.java:107)
    at org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:78)
    at org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(AbstractReconciler.java:207)

!ENTRY org.eclipse.jdt.core.manipulation 4 2 2024-09-05 04:46:16.697
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.jdt.core.manipulation".
!STACK 0
java.lang.NullPointerException: Cannot store to object array because "frame.stackItems" is null
    at org.eclipse.jdt.internal.compiler.ClassFile.traverse(ClassFile.java:7742)
    at org.eclipse.jdt.internal.compiler.ClassFile.generateStackMapTableAttribute(ClassFile.java:5483)
    at org.eclipse.jdt.internal.compiler.ClassFile.completeCodeAttribute(ClassFile.java:1708)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:408)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:324)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:762)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:832)
    at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode(CompilationUnitDeclaration.java:412)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1332)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:791)
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateASTCached(ASTParser.java:1248)
    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.CoreASTProvider.getAST(CoreASTProvider.java:189)
    at org.eclipse.jdt.core.manipulation.SharedASTProviderCore.getAST(SharedASTProviderCore.java:138)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:167)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$1.lambda$0(SelectionListenerWithASTManager.java:149)
    at org.eclipse.jdt.internal.core.JavaModelManager.cacheZipFiles(JavaModelManager.java:5765)
    at org.eclipse.jdt.internal.core.JavaModelManager.callReadOnly(JavaModelManager.java:5754)
    at org.eclipse.jdt.core.JavaCore.callReadOnly(JavaCore.java:6130)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$1.run(SelectionListenerWithASTManager.java:149)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

!ENTRY org.eclipse.jdt.core.manipulation 4 0 2024-09-05 04:46:16.697
!MESSAGE Error in JDT Core during AST creation
!STACK 0
java.lang.NullPointerException: Cannot store to object array because "frame.stackItems" is null
    at org.eclipse.jdt.internal.compiler.ClassFile.traverse(ClassFile.java:7742)
    at org.eclipse.jdt.internal.compiler.ClassFile.generateStackMapTableAttribute(ClassFile.java:5483)
    at org.eclipse.jdt.internal.compiler.ClassFile.completeCodeAttribute(ClassFile.java:1708)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:408)
    at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.generateCode(AbstractMethodDeclaration.java:324)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:762)
    at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.generateCode(TypeDeclaration.java:832)
    at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.generateCode(CompilationUnitDeclaration.java:412)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:1332)
    at org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:791)
    at org.eclipse.jdt.core.dom.ASTParser.internalCreateASTCached(ASTParser.java:1248)
    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.CoreASTProvider.getAST(CoreASTProvider.java:189)
    at org.eclipse.jdt.core.manipulation.SharedASTProviderCore.getAST(SharedASTProviderCore.java:138)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:167)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$1.lambda$0(SelectionListenerWithASTManager.java:149)
    at org.eclipse.jdt.internal.core.JavaModelManager.cacheZipFiles(JavaModelManager.java:5765)
    at org.eclipse.jdt.internal.core.JavaModelManager.callReadOnly(JavaModelManager.java:5754)
    at org.eclipse.jdt.core.JavaCore.callReadOnly(JavaCore.java:6130)
    at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup$1.run(SelectionListenerWithASTManager.java:149)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

Unfortunately, I couldn't find a minimal reproducer, although in my project I can reproduce it 100% of the time. The class looks something like this:

public abstract class StackFrameBug<G extends Ggg, T extends Ttt, N extends Nnn> implements Serializable {

    /**
     * Index
     */
    sealed interface Index {
        enum GggIndex implements Index { A, B; }
        enum TttIndex implements Index { C, D; }
        abstract non-sealed class NnnIndex implements Index {}
    }

    interface GenericTargetable<S extends Index, A extends Index> {}

    interface Ggg extends GenericTargetable<GggIndex, GggIndex> {}
    interface Ttt extends GenericTargetable<TttIndex, TttIndex> {}
    interface Nnn extends GenericTargetable<NnnIndex, NnnIndex> {}

    abstract G getGgg();
    abstract T getTtt(int id);
    abstract N getNnn(int id);

    @SuppressWarnings("unchecked")
    public <I extends Index> GenericTargetable<I, ?> getEntity(int id, I index) {
        return (GenericTargetable<I, ?>) switch (index) {
            case GggIndex __ -> getGgg();
            case TttIndex __ -> getTtt(id);
            case NnnIndex __ -> getNnn(id);
        };
    }
}

Editing out the getEntity method fixes the problem. Adding a default branch to the switch fixes it as well, although the switch is exhaustive.

Without a reproducer it's difficult to find the issue, but I hope that the stack traces along with the description of what causes and alleviates the problem can be enough. If the stack trace guides towards something that should be in the class, I can find it in my project's class and copy it to the reproducer attempt to see if that changes things.

srikanth-sankaran commented 2 months ago

Can you try with 4.33 when it gets out (very soon) ? I would be wary of spending time investigating unless the problem is reproducible on 4.33.

srikanth-sankaran commented 2 months ago

A search for java.lang.NullPointerException: Cannot store to object array because "frame.stackItems" is null in the defect data base brings up only this ticket. Notwithstanding that it would be good to know if 4.33 has the problem.

nlisker commented 2 months ago

Yes, I intend to try on 4.33. It might take a while to update after its release because of 3rd party plugins that need to catch up.

I also searched for frame.stackItem before submitting to see if it was handled, but didn't find anything.

srikanth-sankaran commented 2 months ago

Thanks @nlisker - I will also spend some time to see if I can unearth something here.

srikanth-sankaran commented 1 month ago

There has been a substantial overhaul and reimplementation of sealed types and switch exhaustiveness determination. It would be good if this could be tested against master HEAD at some point.