Skip to content

fix(tools): stop feeding the cold data flow ctr payload to printf as a format string - #11075

Open
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/cold-data-ctr-info-printf
Open

fix(tools): stop feeding the cold data flow ctr payload to printf as a format string#11075
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/cold-data-ctr-info-printf

Conversation

@zjncs

@zjncs zjncs commented Sep 8, 2026

Copy link
Copy Markdown

Motivation

GetColdDataFlowCtrInfoSubCommand.getAndPrint pretty-prints the JSON returned by the broker and passes it to printf as the format string:

String formatStr = JSON.toJSONString(jsonObject, JSONWriter.Feature.PrettyFormat);
System.out.printf(formatStr);

The payload is keyed by consumer group names, and % is a legal character in consumer group and topic names — the validation regex is ^[%|a-zA-Z0-9_-]+$ (it exists precisely to allow the %RETRY% / %RETRY%-style prefixes). A group like order%group therefore makes the command die halfway through the report:

java.util.MissingFormatArgumentException: Format specifier '%g'

(any % in the group name triggers MissingFormatArgumentException, UnknownFormatConversionException or UnknownFormatFlagsException depending on the following character — none of the command output is printed.)

Modification

Print the payload literally:

System.out.print(formatStr);
System.out.printf("%n");

Verification

mvn -pl tools test -Dtest=GetColdDataFlowCtrInfoSubCommandTest

fail-before (fix reverted, test kept) — the mocked broker response contains a legal group name order%group:

Tests run: 1, Failures: 0, Errors: 1
testPrintsEntriesWhoseGroupNameContainsPercent  <<< ERROR!
java.util.MissingFormatArgumentException: Format specifier '%g'

pass-after:

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

and the captured stdout contains the untouched group name order%group.

No associated issue; found by code inspection.

…a format string

The pretty-printed JSON returned by the broker is passed to
System.out.printf(formatStr), so any '%' inside it is interpreted as a
format specifier. '%' is a legal character in consumer group and topic
names (the validation regex is ^[%|a-zA-Z0-9_-]+$, see the %RETRY%
prefix), so a group like order%group makes the command die with
MissingFormatArgumentException: Format specifier '%g' halfway through
the report. Print the payload literally instead.

Signed-off-by: zjncs <18910855655@163.com>
Copilot AI lite review requested due to automatic review settings September 8, 2026 06:34

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM — correct fix. System.out.printf(formatStr) would throw UnknownFormatConversionException if the JSON payload contains % characters (legal in consumer group names like %RETRY%). Switching to System.out.print(formatStr) is the right approach.

Good test coverage verifying that % in the payload is preserved correctly.


Automated review by github-manager-bot

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.

3 participants