Comments (12)
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.
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.
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.
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.
If you do not reply, I will close this exit.
from javaparser.
@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.
Can you try with the current version (3.26.1-SNAPSHOT) as your issue is not reproducible?
from javaparser.
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.
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.
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.
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.
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)
- Record can't be resolved in lambda expressions HOT 4
- UnsolvedSymbolException{context='null', name='We are unable to find the method declaration corresponding to this::getAmount', cause='null'} HOT 2
- ParseProblemException when parsing record pattern with primitive types HOT 7
- `com.github.javaparser.ast.Node#setParentNode` maybe lost parentNode,There may be forced modifications to the original AST Node HOT 5
- FindAll does not retrieve all the MethodCallExpr within a Statement HOT 2
- javaparser-core.jar is not reproducible due to JavaParserBuild
- Out of Memory Error with `sourceZip` API while trying to parse java's Core Library by javaparser HOT 2
- JavaParser cannot resolve objectCreationExpression when type argument is a record type HOT 2
- Question: Getting the index of token in parsed text HOT 1
- ResolvedMethodDeclaration.toDescription fails in the presence of type variables HOT 1
- VariableDeclarator character range does not match range of children HOT 1
- How to find implementation by MethodCallExpr HOT 2
- Pattern variables not always introduced into the correct scope HOT 7
- Node.PostOrderIterator broken for root without children
- Parsing issue in switch with yield HOT 2
- parseVariableDeclarationExpr with `var` HOT 1
- LexicalPreservingPrinter performance HOT 7
- ParseProblemException Switch expressions with constants throw error HOT 4
- After toAst(),error: Symbol resolution not configured: to configure consider setting a SymbolResolver in the ParserConfiguration HOT 6
- Import added through CompilationUnit.addImport should not have a range HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javaparser.