Giter VIP home page Giter VIP logo

Comments (12)

jlerbsc avatar jlerbsc commented on September 27, 2024

Hello, thank you for taking the time to report this issue. To save us some time, can you provide us with an example that compiles and the test case you are using? Thank you.

from javaparser.

eldapiiro avatar eldapiiro commented on September 27, 2024

The examples I quoted above parse and fail. I've taken them from a unit test I'm adding -- I'll be opening a PR to fix this issue soon. Does this help?

from javaparser.

eldapiiro avatar eldapiiro commented on September 27, 2024

Here's the driver that uses these examples:

`public void testIssue4450() throws IOException {
Path issueResourcesPath = adaptPath("src/test/resources/issue4450");
ReflectionTypeSolver rts = new ReflectionTypeSolver();
JavaParserTypeSolver jpts = new JavaParserTypeSolver(issueResourcesPath);
CombinedTypeSolver cts = new CombinedTypeSolver();
cts.add(rts);
cts.add(jpts);
ParserConfiguration pc = new ParserConfiguration()
.setSymbolResolver(new JavaSymbolSolver(cts));
StaticJavaParser.setConfiguration(pc);
CompilationUnit cu = StaticJavaParser.parse(issueResourcesPath.resolve("a/RefCycleClass.java"));

// We shouldn't throw a mismatched symbol
assertDoesNotThrow(() -> cu.findAll(NameExpr.class).stream()
        .map(NameExpr::resolve)
        .findAny().get());

}`

from javaparser.

jlerbsc avatar jlerbsc commented on September 27, 2024

Thank you for taking the time to try and solve the issue you encountered. I've tried to reproduce this issue from the test case you provided but I can't do it with version 3.26.0.

from javaparser.

jlerbsc avatar jlerbsc commented on September 27, 2024

If you do not reply, I will close this exit.

from javaparser.

eldapiiro avatar eldapiiro commented on September 27, 2024

@jlerbsc
Apologies, I've replied on the PR actually. Unfortunately I was able to reproduce the issue with 3.26.0. I'm happy to jump no a Zoom call to discuss further if you wish.

from javaparser.

jlerbsc avatar jlerbsc commented on September 27, 2024

Can you try with the current version (3.26.1-SNAPSHOT) as your issue is not reproducible?

from javaparser.

eldapiiro avatar eldapiiro commented on September 27, 2024

Can you try with the current version (3.26.1-SNAPSHOT) as your issue is not reproducible?

@jlerbsc still reproduces with 3.26.1-SNAPSHOT
Here's what I did: I took pulled master and then applied this patch which adds the unit test from my PR. As expected, it fails on a stack overflow.

Index: javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue4450Test.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue4450Test.java b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue4450Test.java new file mode 100644 --- /dev/null (date 1717402757120) +++ b/javaparser-symbol-solver-testing/src/test/java/com/github/javaparser/symbolsolver/Issue4450Test.java (date 1717402757120) @@ -0,0 +1,43 @@ +package com.github.javaparser.symbolsolver; + +import com.github.javaparser.ParserConfiguration; +import com.github.javaparser.StaticJavaParser; +import com.github.javaparser.ast.CompilationUnit; +import com.github.javaparser.ast.expr.NameExpr; +import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver; +import com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver; +import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class Issue4450Test extends AbstractSymbolResolutionTest { + @Test + public void testIssue4450() throws IOException { + Path issueResourcesPath = adaptPath("src/test/resources/issue4450"); + ReflectionTypeSolver rts = new ReflectionTypeSolver(); + JavaParserTypeSolver jpts = new JavaParserTypeSolver(issueResourcesPath); + CombinedTypeSolver cts = new CombinedTypeSolver(); + cts.add(rts); + cts.add(jpts); + ParserConfiguration pc = new ParserConfiguration() + .setSymbolResolver(new JavaSymbolSolver(cts)); + StaticJavaParser.setConfiguration(pc); + + // We shouldn't stack overflow + CompilationUnit cu1 = StaticJavaParser.parse(issueResourcesPath.resolve("a/RefCycleClass.java")); + assertDoesNotThrow(() -> cu1.findAll(NameExpr.class).stream() + .map(NameExpr::resolve) + .findAny().get()); + + + CompilationUnit cu2 = StaticJavaParser.parse(issueResourcesPath.resolve("a/RefCycleClassFailure.java")); + assertThrows(Exception.class, () -> cu2.findAll(NameExpr.class).stream() + .map(NameExpr::resolve) + .findAny().get()); + } +} Index: javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefClass2.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefClass2.java b/javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefClass2.java new file mode 100644 --- /dev/null (date 1717402611961) +++ b/javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefClass2.java (date 1717402611961) @@ -0,0 +1,6 @@ +package a; + +public class RefClass2 { + public static Runnable unknownName; + public Runnable nonStatic; +} \ No newline at end of file Index: javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefCycleClass.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefCycleClass.java b/javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefCycleClass.java new file mode 100644 --- /dev/null (date 1717402237300) +++ b/javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefCycleClass.java (date 1717402237300) @@ -0,0 +1,16 @@ +package a; + +import static a.RefCycleEnum.*; +import static a.RefClass2.*; + +public class RefCycleClass { + + public static int value1Value = 1; + + private RefCycleEnum theEnum; + + public void runMe() { + unknownName.run(); + RefCycleEnum myEnum = Value1; + } +} Index: javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefCycleClassFailure.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefCycleClassFailure.java b/javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefCycleClassFailure.java new file mode 100644 --- /dev/null (date 1717402657940) +++ b/javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefCycleClassFailure.java (date 1717402657940) @@ -0,0 +1,9 @@ +package a; + +import static a.RefClass2.*; + +public class RefCycleClassFailure { + public void runMe() { + nonStatic.run(); + } +} Index: javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefCycleEnum.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefCycleEnum.java b/javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefCycleEnum.java new file mode 100644 --- /dev/null (date 1717332850932) +++ b/javaparser-symbol-solver-testing/src/test/resources/issue4450/a/RefCycleEnum.java (date 1717332850932) @@ -0,0 +1,13 @@ +package a; + +import static a.RefCycleClass.*; + +public enum RefCycleEnum { + Value1(value1Value); + + private RefCycleEnum(int value) { + Underlying = value; + } + + public final int Underlying; +}

from javaparser.

jlerbsc avatar jlerbsc commented on September 27, 2024

In fact, the problem is related to the way in which static imports declared with asterisks are implemented.
Thank your for declaring this bug.

from javaparser.

eldapiiro avatar eldapiiro commented on September 27, 2024

In fact, the problem is related to the way in which static imports declared with asterisks are implemented. Thank your for declaring this bug.

Indeed. And the PR I've opened for this focuses exactly on that. The problem is that when we look up symbols and follow static wildcard imports we don't restrict our search to static members -- which may lead to circular dependencies causing an infinite loop. (Also the implementation is somewhat brittle in that the lookup isn't restricted to static members...)

from javaparser.

jlerbsc avatar jlerbsc commented on September 27, 2024

The issue is simply that during processing we lose the search history, which leads us to analyse classes that have already been analysed without success.

from javaparser.

jlerbsc avatar jlerbsc commented on September 27, 2024

This issue is related to this one #2720.
One detects the stackoverflow exception in the same compilation unit, while the other detects the exception in a different compilation unit.

from javaparser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.