Skip to content

Flag String.format without an explicit Locale in added test and JMH code - #13697

Open
dd-apm-ecosystems[bot] wants to merge 4 commits into
masterfrom
automated/lint-test-string-format-locale-20261126
Open

dd-apm-ecosystems[bot] wants to merge 4 commits into
masterfrom
automated/lint-test-string-format-locale-20261126

Conversation

@dd-apm-ecosystems

Copy link
Copy Markdown

What Does This Do

Adds a diff-scoped check-default-locale-format job that fails a pull request when it adds a String.format("...", ...) call, with no Locale argument, 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. Under ar-EG, %05d renders 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 use String.format(Locale.ROOT, ...)").

  • This run's window: 1 distinct PR, Spread StringIndex hashes so sequential names don't cluster (FFE optimization) #13576 (human reviewer, accepted by the author; occurrence test-string-format-default-locale|pr13576|4649652384).
  • Recalled from memory: none. One confirmed occurrence suffices, and the pattern likely recurs outside the window. About 119 existing String.format("...") calls in test sources have no locale.
  • Origin: human reviewer (AlexeyKuznetsov-DD), accepted by the PR author (dougqh). No bot comment is involved.
  • Why it is automatable: String.format with a string-literal first argument is always the default-locale overload, so there is no judgment call and no false positives from String.format(locale, "..."). Main sources already enforce this through forbiddenApis (gradle/forbiddenApiFilters/main.txt). Test and JMH sources are not covered.

Additional Notes

  • Tool: a small Python script, tooling/check_default_locale_format.py, plus unit tests in tooling/tests/test_check_default_locale_format.py. It follows the existing check-codeowners pattern.
  • Why not extend forbiddenApis: forbiddenApisTest tasks are disabled in dd-trace-java.conventions.forbidden-apis.gradle.kts. Enabling them would fail on every existing call (about 119) and cannot be limited to changed lines. The forbiddenApisJmh task is already ignoreFailures = true in some modules. A diff-scoped script avoids a bulk cleanup.
  • CI wiring: .gitlab/check-default-locale-format.yml defines the check-default-locale-format job in the tests stage. 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 as check-codeowners).
  • Escape hatch: // locale-default-ok: <reason> on the same line or the line above.
  • Scope: src/test*, src/*Test* and src/jmh Java source sets. Main sources are left to forbiddenApis.
  • Local reproduction:
    python3 -m unittest discover -s tooling/tests -p 'test_check_default_locale_format.py'
    python3 tooling/check_default_locale_format.py "$(git merge-base origin/master HEAD)" HEAD
  • Verification: the 12 unit tests pass locally. The check reports nothing on merged master commit 1e9392a (Spread StringIndex hashes so sequential names don't cluster (FFE optimization) #13576), which already contains the fix. I could not run the GitLab job itself from this environment, so the first CI run is the first end-to-end run.
  • Not done: no CONTRIBUTING.md paragraph. 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

  • Title follows the contribution guidelines (one sentence, starts with an infinitive verb, no prefix).
  • Labels: flagged for a maintainer, since the automation cannot set labels. Suggested: type: enhancement plus a comp: label for build or CI tooling.
  • No issue-linking keywords are used.
  • CODEOWNERS: N/A for review purposes. New files are under tooling/ and .gitlab/, so a maintainer should confirm that existing rules cover them (check_codeowners.py runs in CI).
  • Public documentation: N/A, because there are no new configuration flags or user-facing behavior.
  • Merge queue: to be done by a maintainer once approved.

Jira ticket: N/A (automated maintenance PR; no internal ticket filed)

Automation Context

  • Source comment: PR Spread StringIndex hashes so sequential names don't cluster (FFE optimization) #13576, review comment 4649652384 (AlexeyKuznetsov-DD): "Could we use String.format(Locale.ROOT, ...) here and in StringIndexKeyShapeBenchmark.name? This overload uses the JVM's default locale. For example, ar-EG formats the counter with Arabic-Indic digits, which changes the string hashes and probe counts."
  • Acceptance: reply 4667747488 (dougqh), "Done in 74dd6ff ...". The follow-up commit is merged.
  • Maintainer-feedback table: no do_not_implement or implement_differently row exists for this theme.
  • Known limits: the check is textual, not type-aware. It only flags literal-format first arguments, so String.format(someVariable, ...), "..".formatted(...) and printf are not covered. That is deliberate, to keep false positives at zero.

@dd-apm-ecosystems
dd-apm-ecosystems Bot requested review from a team as code owners November 26, 2026 01:20
@dd-apm-ecosystems
dd-apm-ecosystems Bot requested review from AlexeyKuznetsov-DD, claponcet and randomanderson and removed request for a team November 26, 2026 01:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T01:24:14.164654Z 998de38 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dd-octo-sts

dd-octo-sts Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Hi! 👋 Thanks for your pull request! 🎉

To help us review it, please make sure to:

  • Add at least one type, and one component or instrumentation label to the pull request

If you need help, please check our contributing guidelines.

@dd-apm-ecosystems
dd-apm-ecosystems Bot requested a review from dougqh November 26, 2026 01:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +58 to +60
def is_comment(line):
stripped = line.lstrip()
return stripped.startswith(("//", "*", "/*"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Comment on lines +69 to +70
number = source.count("\n", 0, match.start()) + 1
if number not in lines or is_comment(rows[number - 1]):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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$")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@datadog-prod-us1-4 datadog-prod-us1-4 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

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.

Open Bits AI session

🤖 Bits Code Review · Commit 998de38


def is_comment(line):
stripped = line.lstrip()
return stripped.startswith(("//", "*", "/*"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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

Comment on lines +69 to +70
number = source.count("\n", 0, match.start()) + 1
if number not in lines or is_comment(rows[number - 1]):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Suggested change
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$")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Suggested change
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

@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 61.19% (-0.03%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 998de38 | Docs | Give us feedback!

@dd-octo-sts

dd-octo-sts Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.97 s 14.04 s [-1.2%; +0.2%] (no difference)
startup:insecure-bank:tracing:Agent 12.99 s 13.05 s [-1.1%; +0.2%] (no difference)
startup:petclinic:appsec:Agent 17.64 s 17.13 s [-1.4%; +7.3%] (no difference)
startup:petclinic:iast:Agent 16.99 s 17.46 s [-7.0%; +1.6%] (no difference)
startup:petclinic:profiling:Agent 17.31 s 16.91 s [-2.1%; +6.8%] (no difference)
startup:petclinic:sca:Agent 17.69 s 17.20 s [-1.5%; +7.1%] (no difference)
startup:petclinic:tracing:Agent 16.80 s 16.43 s [-1.9%; +6.5%] (no difference)

Commit: 998de383 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants