Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spoon hangs when building a model when nested conditional expressions containing a pattern matching with variable creation #5511

Open
ValeryKomarov opened this issue Oct 20, 2023 · 0 comments
Labels

Comments

@ValeryKomarov
Copy link

Describe the bug

I'm from PVS-Studio LLC. We develop a static analyzer for Java code that uses the Spoon library (we use the 10.3.0 version). Spoon uses org.eclipse.jdt.core 3.32.0 library.

When such code is evaluated via Spoon (a compliance level equal to 17 is used) the org.eclipse.jdt.internal.compiler.ast.Statement class hangs on a method Statement.addPatternVariables(LocalVariableBinding[] current, LocalVariableBinding add).

We have already created a bug Issue in the Eclipse Core Github repository.

Here is a StackTrace of the hang:

        at org.eclipse.jdt.internal.compiler.ast.Statement.addPatternVariables(Statement.java:522)
        at org.eclipse.jdt.internal.compiler.ast.Statement.addPatternVariables(Statement.java:507)
        at org.eclipse.jdt.internal.compiler.ast.Statement.addPatternVariablesWhenTrue(Statement.java:495)
        at org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression.collectPatternVariablesToScope(AND_AND_Expression.java:284)
        at org.eclipse.jdt.internal.compiler.ast.AND_AND_Expression.collectPatternVariablesToScope(AND_AND_Expression.java:281)
        at org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.collectPatternVariablesToScope(ConditionalExpression.java:460)
        at org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.resolveType(ConditionalExpression.java:535)
        at org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.resolveType(ConditionalExpression.java:546)
        at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:390)
        at org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:259)
        at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:662)
        at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:388)
        at org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:571)
        at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1503)
        at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1628)
        at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:667)
        at spoon.support.compiler.jdt.TreeBuilderCompiler.buildUnits(TreeBuilderCompiler.java:105)
        at spoon.support.compiler.jdt.JDTBatchCompiler.getUnits(JDTBatchCompiler.java:282)
        at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildUnits(JDTBasedSpoonCompiler.java:418)
        at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildUnitsAndModel(JDTBasedSpoonCompiler.java:370)
        at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildSources(JDTBasedSpoonCompiler.java:336)
        at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:117)
        at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:100)
        at spoon.Launcher.buildModel(Launcher.java:782)
        at com.pvsstudio.projects.Module.build(Module.java:428)
        at com.pvsstudio.runner.ModuleModelBuilder.createModuleWorkerWithBuiltModelAndAnalyzeTasksForModule(ModuleModelBuilder.java:136)
        at com.pvsstudio.runner.AnalyzerRunner.run(AnalyzerRunner.java:93)
        at com.pvsstudio.Main.main(Main.java:575)

Source code you are trying to analyze/transform

public class Main {
    static class PvsVariable {
    }

    static class PvsVariableNext_1 extends PvsVariable {
    }

    static class PvsVariableNext_2 extends PvsVariableNext_1 {
    }

    static class PvsVariableNext_3 extends PvsVariableNext_2 {
    }

    static class PvsVariableNext_4 extends PvsVariableNext_3 {
    }

    public static void main(String[] args) {
        final var pvsVariable = new PvsVariable();
        final Object origVar =
                pvsVariable instanceof PvsVariableNext_1 var_first
                    ? null
                    : (pvsVariable instanceof PvsVariableNext_2 var_second && 
                       pvsVariable instanceof PvsVariableNext_3 var_three && 
                       true) ? null
                                : null;
    }
}

Source code for your Spoon processing

No response

Actual output

No response

Expected output

No response

Spoon Version

10.3.0

JVM Version

JDK 17

What operating system are you using?

Windows, Linux, macOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant