Java: make JDK 11 version normalisation in gradle buildless test robust - #22501
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The regex correctly handles representative JDK 11 formats while preserving checks for non-11 versions.
Review tier: Balanced
Findings: None
What changed in this PR
Makes JDK 11 version normalization resilient to variable-length JEP 322 version strings.
Changes:
- Anchors normalization to
java_version. - Supports patch components and build/prerelease suffixes.
| File | Description |
|---|---|
java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildless/test.py |
Robustly normalizes JDK 11 diagnostics. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
There's a few other places that use similar patterns. Should we update the others too? |
`java.version` may carry a fourth `$PATCH` component (JEP 322), as in Temurin `jdk-11.0.32.1+1`. The previous pattern matched exactly three components, so the trailing `.1` survived and the test reported `11.1`. Accept any number of version components, and anchor on the surrounding quotes so the substitution only rewrites a whole JSON string rather than version-like text elsewhere in the diagnostics. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
86b6367 to
703d680
Compare
|
Good catch — yes, and I've done so. In this repo this is the only version-normalising one: the only other Worth flagging what turned up there, since it argues for the quoted form. One of them normalised feature version 9 with
So it was silently mangling any unrelated version ending in |
java/ql/integration-tests/java/gradle-sample-without-wrapper-or-gradle-buildlessnormalises the reportedjava.versiondown to11so the test asserts the JDK feature version without pinning a specific build. The pattern it used,11\.[0-9]+\.[0-9]+, assumed exactly three dot-separated components.That assumption broke on macOS runners, which now provide Temurin
jdk-11.0.32.1+1:java.versionfor that build is11.0.32.1. Per JEP 322 a version number is$FEATURE.$INTERIM.$UPDATE.$PATCH, so a fourth component appears whenever upstream ships a patch release (11.0.15.1,11.0.20.1,11.0.32.1, ...). The old pattern consumed only11.0.32and left.1behind.Fix
(\.[0-9]+)*accepts any number of components, so the next JDK bump won't break it.([-+][^"]*)?tolerates a pre-release/build/opt suffix.java_versionkey and the closing quote keeps the substitution from rewriting version-like text elsewhere in the diagnostics JSON. The old unanchored pattern would happily rewrite11.0.32inside a URL or a path; the new one doesn't.I kept the normalisation rather than adding
attributes.java_versiontoredactnext tojava_vendor. Redacting is simpler, but this test deliberately uses plaincheck_diagnosticsinstead of the java-specific fixture that dropsjava_versionaltogether — the visible version is the assertion thatuse_java_11actually took effect, which is the point of the test and of the# The version of gradle used doesn't work on java 17comment above it. Redacting would silently keep passing if the fixture ever stopped selecting a JDK 11.diagnostics.expectedis unchanged.Validation
I replayed the diagnostics fixture's post-processing (text replacements → parse → redact → sort → dump) over a reconstructed raw diagnostics payload, for both JSON spacings, and compared the result against the checked-in
diagnostics.expected:java.version11.0.3211.0.32.111.1)11.0.20.111.1)11.0.32-ea+911-ea+9)The old pattern reproduces the CI failure exactly; the new one reproduces
diagnostics.expectedbyte for byte. Non-11 versions (17.0.1,21.0.5,1.8.0_412) are left untouched, so the test still fails loudly if a different JDK is picked up.This is the only place under
java/ql/integration-teststhat normalises a java version.