From 0deb5da8ab1de782f1d231b4fe72a8d7908f31f8 Mon Sep 17 00:00:00 2001 From: Johannes Coetzee Date: Fri, 21 Jun 2024 15:47:48 +0200 Subject: [PATCH 1/4] Disable spotless ratcheting and fix formatting --- .../contexts/CompilationUnitContext.java | 69 +++++++++---------- .../symbolsolver/Issue4450Test.java | 24 +++---- pom.xml | 2 - 3 files changed, 46 insertions(+), 49 deletions(-) diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java index e36d2faa2d..d508c2bd86 100644 --- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java +++ b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/contexts/CompilationUnitContext.java @@ -21,11 +21,6 @@ package com.github.javaparser.symbolsolver.javaparsermodel.contexts; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.stream.Collectors; - import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.ImportDeclaration; import com.github.javaparser.ast.Node; @@ -41,6 +36,10 @@ import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserInterfaceDeclaration; import com.github.javaparser.symbolsolver.resolution.SymbolSolver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.stream.Collectors; /** * @author Federico Tomassetti @@ -49,11 +48,12 @@ public class CompilationUnitContext extends AbstractJavaParserContext> resolvedStaticImport = ThreadLocal.withInitial(() -> new ArrayList()); + // Contains the names of static import declarations with asterisks that have + // already been resolved. The aim is to keep a history of name searches for the + // same resolution attempt in order to avoid a recursive issue leading to a + // stackoverflow exception. See issues 4450 & 2720 + private static ThreadLocal> resolvedStaticImport = + ThreadLocal.withInitial(() -> new ArrayList()); /// /// Static methods @@ -91,20 +91,20 @@ public SymbolReference solveSymbol(String na if (importDecl.isStatic()) { if (importDecl.isAsterisk()) { String qName = importDecl.getNameAsString(); - // Try to resolve the name in from declarations imported with asterisks only if - // they have not already been analysed, otherwise this can lead to an infinite - // loop via circular dependencies. - if (!isAlreadyResolved(qName)) { - resolvedStaticImport.get().add(qName); - ResolvedTypeDeclaration importedType = typeSolver.solveType(qName); - - SymbolReference ref = new SymbolSolver(typeSolver) - .solveSymbolInType(importedType, name); - if (ref.isSolved()) { - resolvedStaticImport.remove(); // clear the search history - return ref; - } - } + // Try to resolve the name in from declarations imported with asterisks only if + // they have not already been analysed, otherwise this can lead to an infinite + // loop via circular dependencies. + if (!isAlreadyResolved(qName)) { + resolvedStaticImport.get().add(qName); + ResolvedTypeDeclaration importedType = typeSolver.solveType(qName); + + SymbolReference ref = + new SymbolSolver(typeSolver).solveSymbolInType(importedType, name); + if (ref.isSolved()) { + resolvedStaticImport.remove(); // clear the search history + return ref; + } + } } else { String whole = importDecl.getNameAsString(); @@ -120,14 +120,14 @@ public SymbolReference solveSymbol(String na } } - // Clear of the search history because we don't want this context to be reused - // in another search. - resolvedStaticImport.remove(); + // Clear of the search history because we don't want this context to be reused + // in another search. + resolvedStaticImport.remove(); return SymbolReference.unsolved(); } private boolean isAlreadyResolved(String qName) { - return resolvedStaticImport.get().contains(qName); + return resolvedStaticImport.get().contains(qName); } @Override @@ -329,12 +329,12 @@ public SymbolReference solveMethod( return SymbolReference.unsolved(); } - ResolvedTypeDeclaration ref = typeSolver.solveType(importString); - SymbolReference method = MethodResolutionLogic.solveMethodInType(ref, - name, argumentsTypes, true); - if (method.isSolved()) { - return method; - } + ResolvedTypeDeclaration ref = typeSolver.solveType(importString); + SymbolReference method = + MethodResolutionLogic.solveMethodInType(ref, name, argumentsTypes, true); + if (method.isSolved()) { + return method; + } } else { String qName = importDecl.getNameAsString(); @@ -396,5 +396,4 @@ private String getMember(String qName) { String memberName = qName.substring(index + 1); return memberName; } - } 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 index 15752318a8..a1847c4348 100755 --- 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 @@ -21,6 +21,7 @@ package com.github.javaparser.symbolsolver; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + import com.github.javaparser.ParserConfiguration; import com.github.javaparser.StaticJavaParser; import com.github.javaparser.ast.CompilationUnit; @@ -28,7 +29,6 @@ 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 java.io.IOException; import java.nio.file.Path; import org.junit.jupiter.api.Test; @@ -39,23 +39,23 @@ public class Issue4450Test extends AbstractSymbolResolutionTest { public void test() throws IOException { ParserConfiguration config = new ParserConfiguration(); Path issueResourcesPath = adaptPath("src/test/resources/issue4450"); - JavaParserTypeSolver jpts = new JavaParserTypeSolver(issueResourcesPath); + JavaParserTypeSolver jpts = new JavaParserTypeSolver(issueResourcesPath); CombinedTypeSolver cts = new CombinedTypeSolver(); cts.add(new ReflectionTypeSolver(false)); cts.add(jpts); config.setSymbolResolver(new JavaSymbolSolver(cts)); StaticJavaParser.setConfiguration(config); - StaticJavaParser.setConfiguration(config); - CompilationUnit cu = StaticJavaParser.parse(issueResourcesPath.resolve("a/RefCycleClass.java")); + StaticJavaParser.setConfiguration(config); + 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()); + // We shouldn't throw a mismatched symbol + assertDoesNotThrow(() -> cu.findAll(NameExpr.class).stream() + .map(NameExpr::resolve) + .findAny() + .get()); - cu.findAll(NameExpr.class).forEach(expr -> { - expr.resolve().getName(); - }); + cu.findAll(NameExpr.class).forEach(expr -> { + expr.resolve().getName(); + }); } - } diff --git a/pom.xml b/pom.xml index adc9fce553..b5e4a6ae54 100644 --- a/pom.xml +++ b/pom.xml @@ -346,8 +346,6 @@ 2.43.0 - - origin/master From 7d854802b801c2f68e3b36cdb70a98662e8436c3 Mon Sep 17 00:00:00 2001 From: Johannes Coetzee Date: Fri, 21 Jun 2024 15:54:29 +0200 Subject: [PATCH 2/4] Add formatting instruction to CONTRIBUTING.md --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7d4f179565..00f3c37a3e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,3 +29,4 @@ Our development workflow is based on Pull Request. If you are not familiar with - Pull requests often stay open for at least a few days to give people a chance to review it. - A pull request is merged when all comments on it have been resolved. - If you create a pull request for an issue, mention the issue in the format #123 to make github link it automatically. +- Before submitting a pull request, please run `./mvnw spotless:apply` to format your code to avoid any formatting related issues during review. From ba7c8ddb546e6f092f93f10eca8016e797469302 Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 21 Jun 2024 17:41:58 +0200 Subject: [PATCH 3/4] Update changelog --- changelog.md | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index cbaf507083..7f5923dd48 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,7 @@ -Next Release (Version 3.26.1-snapshot) +Next Release (Version 3.26.2-snapshot) -------------------------------------- -[issues resolved](https://github.com/javaparser/javaparser/milestone/208?closed=1) +[issues resolved](https://github.com/javaparser/javaparser/milestone/209?closed=1) ### Added ### Changed @@ -10,9 +10,48 @@ Next Release (Version 3.26.1-snapshot) ### Fixed ### Security +Version 3.26.1 +-------------- +[issues resolved](https://github.com/javaparser/javaparser/milestone/208?closed=1) + +### Added + +* Fix record declarations nested in annotation declarations (PR [#4460](https://github.com/javaparser/javaparser/pull/4460) by [@johannescoetzee](https://github.com/johannescoetzee)) + +### Changed + +* Format code with spotless (PR [#4465](https://github.com/javaparser/javaparser/pull/4465) by [@johannescoetzee](https://github.com/johannescoetzee)) +* Simplifying the search for types in compilation unit (PR [#4459](https://github.com/javaparser/javaparser/pull/4459) by [@jlerbsc](https://github.com/jlerbsc)) +* Add spotless plugin configuration (PR [#4409](https://github.com/javaparser/javaparser/pull/4409) by [@johannescoetzee](https://github.com/johannescoetzee)) + +### Fixed + +* Disable spotless ratcheting and fix formatting (PR [#4478](https://github.com/javaparser/javaparser/pull/4478) by [@johannescoetzee](https://github.com/johannescoetzee)) +* Fix: issue 4450 Endless recursion (-> StackOverflow) with cyclic static references (PR [#4477](https://github.com/javaparser/javaparser/pull/4477) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix: issue 4399 MethodCallExpr inside lambda in assignment expression cannot be resolved (PR [#4462](https://github.com/javaparser/javaparser/pull/4462) by [@jlerbsc](https://github.com/jlerbsc)) +* Fix crash on SwitchExpr entries if tokens are not stored (PR [#4461](https://github.com/javaparser/javaparser/pull/4461) by [@johannescoetzee](https://github.com/johannescoetzee)) +* Fix lookahead for pattern expression in switch entries [Issue 4455] (PR [#4458](https://github.com/javaparser/javaparser/pull/4458) by [@johannescoetzee](https://github.com/johannescoetzee)) + +### Developer Changes + +* Automatically format code after codegen and validate with a github action (PR [#4468](https://github.com/javaparser/javaparser/pull/4468) by [@johannescoetzee](https://github.com/johannescoetzee)) +* Add git-blame-ignore-revs file to ignore the reformatting commit in git blame (PR [#4466](https://github.com/javaparser/javaparser/pull/4466) by [@johannescoetzee](https://github.com/johannescoetzee)) + +### Uncategorised + +* Add link to the guide to adding nodes in CONTRIBUTING.md (PR [#4453](https://github.com/javaparser/javaparser/pull/4453) by [@johannescoetzee](https://github.com/johannescoetzee)) + +### :heart: Contributors + +Thank You to all contributors who worked on this release! + +* [@johannescoetzee](https://github.com/johannescoetzee) +* [@jlerbsc](https://github.com/jlerbsc) -Next Release (Version 3.26.0) ------------------------------ + + +Version 3.26.0 +-------------- [issues resolved](https://github.com/javaparser/javaparser/milestone/207?closed=1) ### Added From b14c61eaf58f7045e7b610559bccb96eff1b822c Mon Sep 17 00:00:00 2001 From: jlerbsc Date: Fri, 21 Jun 2024 17:44:58 +0200 Subject: [PATCH 4/4] [maven-release-plugin] prepare release javaparser-parent-3.26.1 --- javaparser-core-generators/pom.xml | 2 +- javaparser-core-metamodel-generator/pom.xml | 2 +- javaparser-core-serialization/pom.xml | 2 +- javaparser-core-testing-bdd/pom.xml | 2 +- javaparser-core-testing/pom.xml | 2 +- javaparser-core/pom.xml | 2 +- javaparser-symbol-solver-core/pom.xml | 2 +- javaparser-symbol-solver-testing/pom.xml | 2 +- pom.xml | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/javaparser-core-generators/pom.xml b/javaparser-core-generators/pom.xml index 604dadd5fc..3b88373a5d 100644 --- a/javaparser-core-generators/pom.xml +++ b/javaparser-core-generators/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.26.1-SNAPSHOT + 3.26.1 4.0.0 diff --git a/javaparser-core-metamodel-generator/pom.xml b/javaparser-core-metamodel-generator/pom.xml index a744d49d67..91fedc0f21 100644 --- a/javaparser-core-metamodel-generator/pom.xml +++ b/javaparser-core-metamodel-generator/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.26.1-SNAPSHOT + 3.26.1 4.0.0 diff --git a/javaparser-core-serialization/pom.xml b/javaparser-core-serialization/pom.xml index ae2489da78..5a1e397aed 100644 --- a/javaparser-core-serialization/pom.xml +++ b/javaparser-core-serialization/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.26.1-SNAPSHOT + 3.26.1 4.0.0 diff --git a/javaparser-core-testing-bdd/pom.xml b/javaparser-core-testing-bdd/pom.xml index 9c35614477..487bcbe9e4 100644 --- a/javaparser-core-testing-bdd/pom.xml +++ b/javaparser-core-testing-bdd/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.26.1-SNAPSHOT + 3.26.1 4.0.0 diff --git a/javaparser-core-testing/pom.xml b/javaparser-core-testing/pom.xml index 5cf1acc9f7..e0ee736e8b 100644 --- a/javaparser-core-testing/pom.xml +++ b/javaparser-core-testing/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.26.1-SNAPSHOT + 3.26.1 4.0.0 diff --git a/javaparser-core/pom.xml b/javaparser-core/pom.xml index eca55fbc33..18c767a37f 100644 --- a/javaparser-core/pom.xml +++ b/javaparser-core/pom.xml @@ -2,7 +2,7 @@ javaparser-parent com.github.javaparser - 3.26.1-SNAPSHOT + 3.26.1 4.0.0 diff --git a/javaparser-symbol-solver-core/pom.xml b/javaparser-symbol-solver-core/pom.xml index dbd7956065..daba4fb045 100644 --- a/javaparser-symbol-solver-core/pom.xml +++ b/javaparser-symbol-solver-core/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.26.1-SNAPSHOT + 3.26.1 4.0.0 diff --git a/javaparser-symbol-solver-testing/pom.xml b/javaparser-symbol-solver-testing/pom.xml index 32c33753ce..6093b12368 100644 --- a/javaparser-symbol-solver-testing/pom.xml +++ b/javaparser-symbol-solver-testing/pom.xml @@ -3,7 +3,7 @@ javaparser-parent com.github.javaparser - 3.26.1-SNAPSHOT + 3.26.1 4.0.0 diff --git a/pom.xml b/pom.xml index b5e4a6ae54..b83f40774b 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.github.javaparser javaparser-parent pom - 3.26.1-SNAPSHOT + 3.26.1 javaparser-parent https://github.com/javaparser @@ -149,7 +149,7 @@ 1.8 1.14.17 -javaagent:'${settings.localRepository}/net/bytebuddy/byte-buddy-agent/${byte-buddy.version}/byte-buddy-agent-${byte-buddy.version}.jar' - 2024-06-02T00:00:00Z + 2024-06-21T00:00:00Z