Repository navigation
SONARJAVA-7278 Override SystemReleaseClasspath to expose the JDK API of a requested release (JEP 247) - #169
Conversation
f908700 to
e6e8a04
Compare
e6e8a04 to
c52e780
Compare
c52e780 to
0e84465
Compare
…d release (JEP 247) Override ASTParser so that the JDK API matching the requested release is exposed through the new SystemReleaseClasspath (backed by ct.sym, JEP 247). The release API is also applied to an explicit JDK: read the version of the JDK providing ct.sym from its release file, and only substitute when the requested release is older than it, so that a ct.sym is never asked for a release it does not describe. Expose isApplicable so that a client handing a JDK to the parser through its classpath (jrt-fs.jar) can replace it with the release API of that same JDK. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
0e84465 to
fed37d2
Compare
|
…rn and fall back otherwise The release is now served as soon as the JDK providing it has a ct.sym that describes it, instead of being compared with the version read from the "release" file of the JDK. When ECJ cannot initialize the entry (no lib/ct.sym, ct.sym that does not describe the release, release that is not a number...), one warning is logged per JDK and release and the parser keeps its previous behavior. Initializing the entry up front also avoids a failure in the middle of a parse, as ECJ cannot serve from ct.sym the release of the JDK that owns it. Java 8 and older are never served: ct.sym only holds the supported public API, which is less than a JDK 8 offers. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ff4c5e0 to
da6aaa2
Compare
da6aaa2 to
c39ee35
Compare
david-schroeter
left a comment
There was a problem hiding this comment.
This PR looks good and seems almost ready to merge.
There is just one point to clarify about errors when reading ct.sym: we fall back to the selected JDK when the file is missing, but throw when it exists and cannot be read. Is that difference intentional?
Otherwise, there are a few gaps in the test assertions that could let future regressions go unnoticed. If they aren't straightforward to address here, we could create a ticket and strengthen the tests in a follow-up PR.
david-schroeter
left a comment
There was a problem hiding this comment.
LGTM! Thanks for addressing the comments and for finding a way to better test which release version is used!
There is just an import in SystemReleaseClasspathTest.java that is unused and should be remove, but other than that this PR is ready to be merged.
Code Review ✅ Approved 🟡 Medium risk 4 closed / 4 findingsChanging ASTParser classpaths to use ct.sym for requested Java releases may alter type resolution and analysis results across supported releases. Adds a custom ASTParser override so the JDT parser can expose the JDK API of a requested release (JEP 247), serving it from ct.sym when the JDK supports it and warning and falling back otherwise. Resolved issues cover release resolution when javaHome is explicit, preserving the ASTParser patch across overrideECJ.sh upgrades, and tightening the legacy 1.8.0_362 and release-file version tests so they actually verify parsing. No open issues remain. ✅ 4 closed✅ Bug: Explicit javaHome with release >= that JDK's version breaks resolution
✅ Quality: ASTParser patch will be lost on the next overrideECJ.sh upgrade
✅ Quality: Legacy 1.8.0_362 notation assertion passes whether or not it is parsed
✅ Quality: Release-file version test passes even if the version is never parsed
Verification Rules 2/2 met Repos 1 inspected · PRs 3 inspectedFunctional validation No results Rules 2 passed 2 not applicable
Broader impact Repos 1 inspected PRs 3 inspectedCross-repo 1 repository inspected 0 open impacts
Cross-PR 3 PRs inspected 0 open impacts
Auto-approval Not enabledFor more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|





Summary by Gitar
SystemReleaseClasspathexposing the JDK API of a requested release (JEP 247ct.sym) toASTParserorg.sonarsource.java.jdt.systemReleaseand...javaHomeselect the release and the JDK providingct.symgetClasspath()uses the release classpath instead of the running VM bootclasspath when a release is requested, falling back otherwisejavaHomect.sym, so the running JVM API is keptct.symfall back to the JDK API instead of throwingSystemReleaseClasspathTestcovering option guards and the API exposed for a releaseASTParserReleaseITchecking the release API through the shaded jar's realASTParserpom.xmlmaven-failsafe-pluginto run integration tests against the shaded jarorg.eclipse.jdt.coreto 3.47.0 and project version to1.11-SNAPSHOTThis will update automatically on new commits.