Repository navigation
Flag String.format without an explicit Locale in added test and JMH code - #13697
dd-apm-ecosystems[bot] wants to merge 4 commits into
Conversation
…in test and JMH code
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Hi! 👋 Thanks for your pull request! 🎉 To help us review it, please make sure to:
If you need help, please check our contributing guidelines. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 998de383cc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| def is_comment(line): | ||
| stripped = line.lstrip() | ||
| return stripped.startswith(("//", "*", "/*")) |
There was a problem hiding this comment.
Exclude comment and string contents before matching calls
An added line such as int n = 1; // String.format("%d", 2) is reported because this predicate checks whether the entire line starts with a comment marker, not whether the match occurs inside a comment. Unstarred block-comment contents and Java text-block fixtures containing the same text are also reported. Since the new CI job fails on these matches, legitimate documentation or fixture changes can block a PR without introducing any default-locale invocation. Determine the lexical context of each match before reporting it.
Useful? React with 👍 / 👎.
| number = source.count("\n", 0, match.start()) + 1 | ||
| if number not in lines or is_comment(rows[number - 1]): |
There was a problem hiding this comment.
Check added lines across the matched invocation prefix
When an existing multiline call changes from String.format(\n Locale.ROOT, "%d", n) to String.format(\n "%d", n), the PR introduces the prohibited default-locale overload, but this check returns success: only the argument line is added, while number points to the unchanged String.format( line. Check whether any line spanned by the matched invocation prefix was added, rather than checking only its starting line, and cover this multiline Locale-removal case.
Useful? React with 👍 / 👎.
| import sys | ||
|
|
||
| # src/test/java, src/jmh/java, src/latestDepTest/java, src/test/java17, ... | ||
| TEST_OR_JMH_JAVA = re.compile(r"(?:^|/)src/(?:jmh|[A-Za-z0-9]*[Tt]est[A-Za-z0-9]*)/java[0-9]*/.+\.java$") |
There was a problem hiding this comment.
Include registered nested Java test source directories
The regex requires java to immediately follow the test source-set directory, excluding Java tests in existing nested source roots. For example, dd-java-agent/instrumentation/jetty/jetty-server/jetty-server-12.0/build.gradle:33–40 explicitly registers the ee8Test, ee9Test, and ee10Test suites from test/ee8, test/ee9, and test/ee10; their Java sources live under src/test/ee*/java. Newly added default-locale calls in those tests are silently skipped regardless of which lines changed. Extend the path matching to cover these registered test roots.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The blocking checker can reject comments and miss newly introduced default-locale calls in multiline edits and Jetty’s nested test roots. Focused execution confirmed all three cases.
🤖 Bits Code Review · Commit 998de38
|
|
||
| def is_comment(line): | ||
| stripped = line.lstrip() | ||
| return stripped.startswith(("//", "*", "/*")) |
There was a problem hiding this comment.
Exclude trailing and block comments from call detection
Focused execution reproduced reports for int x; // String.format("%d", 2) and unstarred text inside a block comment. Neither introduces an executable call, but the blocking CI job rejects both because this function only recognizes comment prefixes. Match against source that accounts for comment boundaries while preserving string literals; a line-prefix replacement cannot reliably fix this.
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
| number = source.count("\n", 0, match.start()) + 1 | ||
| if number not in lines or is_comment(rows[number - 1]): |
There was a problem hiding this comment.
Check added lines throughout multiline call prefixes
When an existing multiline call keeps its String.format( line but changes the following line from Locale.ROOT, "%05d", i to "%05d", i, the newly introduced default-locale overload passes. Focused execution reproduced this missed report: only the unchanged match-start line is checked. Consider added lines throughout the matched prefix. The suggested replacement catches this case and preserves the existing checker tests.
| number = source.count("\n", 0, match.start()) + 1 | |
| if number not in lines or is_comment(rows[number - 1]): | |
| number = source.count("\n", 0, match.start()) + 1 | |
| last_number = source.count("\n", 0, match.end()) + 1 | |
| if not lines.intersection(range(number, last_number + 1)) or is_comment(rows[number - 1]): |
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
| import sys | ||
|
|
||
| # src/test/java, src/jmh/java, src/latestDepTest/java, src/test/java17, ... | ||
| TEST_OR_JMH_JAVA = re.compile(r"(?:^|/)src/(?:jmh|[A-Za-z0-9]*[Tt]est[A-Za-z0-9]*)/java[0-9]*/.+\.java$") |
There was a problem hiding this comment.
Include nested Java test roots in the path filter
Jetty 12 registers Java test suites under src/test/ee8/java, src/test/ee9/java, and src/test/ee10/java. This filter requires java immediately after the source-set directory, excluding those suites entirely. Focused execution reproduced a missed default-locale call under the ee8 layout. Allow nested test roots; the suggested replacement catches this case and preserves the existing checker tests.
| TEST_OR_JMH_JAVA = re.compile(r"(?:^|/)src/(?:jmh|[A-Za-z0-9]*[Tt]est[A-Za-z0-9]*)/java[0-9]*/.+\.java$") | |
| TEST_OR_JMH_JAVA = re.compile(r"(?:^|/)src/(?:jmh|[A-Za-z0-9]*[Tt]est[A-Za-z0-9]*)(?:/[^/]+)*/java[0-9]*/.+\.java$") |
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
What Does This Do
Adds a diff-scoped
check-default-locale-formatjob that fails a pull request when it adds aString.format("...", ...)call, with noLocaleargument, to a test or JMH Java source file. It reports only the lines the PR adds, never existing code.Motivation
A reviewer asked for
String.format(Locale.ROOT, ...)in a new test and benchmark because the default overload uses the JVM default locale. Underar-EG,%05drenders Arabic-Indic digits, which changes the generated names, their hashes and the asserted probe counts. The author accepted and fixed it ("Done in 74dd6ff: both ... now useString.format(Locale.ROOT, ...)").test-string-format-default-locale|pr13576|4649652384).String.format("...")calls in test sources have no locale.String.formatwith a string-literal first argument is always the default-locale overload, so there is no judgment call and no false positives fromString.format(locale, "..."). Main sources already enforce this throughforbiddenApis(gradle/forbiddenApiFilters/main.txt). Test and JMH sources are not covered.Additional Notes
tooling/check_default_locale_format.py, plus unit tests intooling/tests/test_check_default_locale_format.py. It follows the existingcheck-codeownerspattern.forbiddenApisTesttasks are disabled indd-trace-java.conventions.forbidden-apis.gradle.kts. Enabling them would fail on every existing call (about 119) and cannot be limited to changed lines. TheforbiddenApisJmhtask is alreadyignoreFailures = truein some modules. A diff-scoped script avoids a bulk cleanup..gitlab/check-default-locale-format.ymldefines thecheck-default-locale-formatjob in thetestsstage. It runs the unit tests, then the check on the PR diff (merge-base from.gitlab/find-gh-base-ref.sh). It is skipped on master, release and merge-queue branches. It is included through.gitlab/ci-visibility-tests.yml, so it runs in the PR pipeline. The check needs only Python 3 and Git (same builder image ascheck-codeowners).// locale-default-ok: <reason>on the same line or the line above.src/test*,src/*Test*andsrc/jmhJava source sets. Main sources are left to forbiddenApis.CONTRIBUTING.mdparagraph. The job header and the failure message explain the fix and the reproduction command. A maintainer may want to add a short doc note.Contributor Checklist
type: enhancementplus acomp:label for build or CI tooling.tooling/and.gitlab/, so a maintainer should confirm that existing rules cover them (check_codeowners.pyruns in CI).Jira ticket: N/A (automated maintenance PR; no internal ticket filed)
Automation Context
String.format(Locale.ROOT, ...)here and inStringIndexKeyShapeBenchmark.name? This overload uses the JVM's default locale. For example,ar-EGformats the counter with Arabic-Indic digits, which changes the string hashes and probe counts."do_not_implementorimplement_differentlyrow exists for this theme.String.format(someVariable, ...),"..".formatted(...)andprintfare not covered. That is deliberate, to keep false positives at zero.