Skip to content

[fix][common] Clear empty String values in FieldParser#26078

Open
hiSandog wants to merge 1 commit into
apache:masterfrom
hiSandog:fix/fieldparser-empty-string-20260623
Open

[fix][common] Clear empty String values in FieldParser#26078
hiSandog wants to merge 1 commit into
apache:masterfrom
hiSandog:fix/fieldparser-empty-string-20260623

Conversation

@hiSandog

Copy link
Copy Markdown
Contributor

Motivation

FieldParser.setEmptyValue is intended to clear String and boxed numeric fields when a configuration property is present but blank. The String branch currently checks fieldType.getClass().equals(String.class), which compares Class.class to String.class and never matches. As a result, an existing String field value is left unchanged when the property value is empty.

Modifications

  • Check field.getType().equals(String.class) when handling empty values.
  • Add a regression test that verifies an empty property clears an existing String field.

Verifying this change

This change added tests and can be verified as follows:

  • Added FieldParserTest.testEmptyValueClearsStringField.
  • Ran git diff --check.
  • Not run locally: ./gradlew :pulsar-common:test --tests org.apache.pulsar.common.util.FieldParserTest -PtestRetryCount=0, because this environment has no Java Runtime installed.

Does this pull request potentially affect one of the following parts:

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Assisted-by: OpenAI Codex

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This breaks current behavior. Although there was a clear bug in the previous code, according to the failing tests, an empty java.lang.String is expected to map to an empty String (it shouldn't map to null). Please check the failing unit tests.

Comment on lines +231 to 232
} else if (Number.class.isAssignableFrom(field.getType()) || field.getType().equals(String.class)) {
field.set(obj, null);

@lhotari lhotari Jun 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
} else if (Number.class.isAssignableFrom(field.getType()) || field.getType().equals(String.class)) {
field.set(obj, null);
} else if (Number.class.isAssignableFrom(field.getType())) {
field.set(obj, null);
} else if (String.class.equals(field.getType())) {
field.set(obj, "");

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Check the review comments

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