Skip to content

Trim config values before binding properties to objects - #10948

Open
AliasJeff wants to merge 1 commit into
apache:developfrom
AliasJeff:fix-trim-config-values
Open

Trim config values before binding properties to objects#10948
AliasJeff wants to merge 1 commit into
apache:developfrom
AliasJeff:fix-trim-config-values

Conversation

@AliasJeff

@AliasJeff AliasJeff commented Aug 16, 2026

Copy link
Copy Markdown

Which Issue(s) This PR Fixes

Fixes #10708

Brief Description

This PR trims property values before binding them to config objects in MixAll.properties2Object.

Previously, only String values were trimmed. Numeric and boolean values were parsed as-is, so a value like fileReservedTime = 168 failed to parse and the config field kept its default value.

This change trims the value before type conversion, so int, long, double, float, boolean, and String values are handled consistently.

How Did You Test This Change?

Added tests for:

  • primitive config values with leading/trailing whitespace;
  • fileReservedTime = 168 being parsed as 168 instead of keeping the default value.

Test commands:

mvn -pl common -DskipITs -Dspotbugs.skip=true -Dcheckstyle.skip=true -Dlicense.skip=true -Dtest=org.apache.rocketmq.common.UtilAllTest#testProperties2ObjectTrimsPrimitiveValues test
mvn -pl broker -am -DskipITs -Dspotbugs.skip=true -Dcheckstyle.skip=true -Dlicense.skip=true -DfailIfNoTests=false -Dtest=org.apache.rocketmq.broker.BrokerControllerTest#testFileReservedTimeWithTrailingWhitespaceIsPreserved test

Both targeted tests passed locally.

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

Summary

Fixes a real bug where config properties with leading/trailing whitespace silently fail to parse for non-String types (int, long, double, float, boolean). Moving property.trim() before the type-switch block is the correct and minimal fix.

Changes reviewed:

  • MixAll.properties2Object() — trim moved before type dispatch (correct)
  • UtilAllTest — comprehensive test covering all primitive types with whitespace
  • BrokerControllerTest — specific regression test for the fileReservedTime = 168 scenario from #10708

LGTM. Clean fix with good test coverage.


Automated review by "github-manager-bot"

@AliasJeff AliasJeff changed the title Trim config values before biding properties to objects Trim config values before binding properties to objects Aug 16, 2026
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.

fileReservedTime配置被覆盖

2 participants