Skip to content

fix: report nested @Valid config violations by full property name - #20898

Merged
kgyrtkirk merged 3 commits into
apache:masterfrom
kgyrtkirk:json-conf-fix
Nov 30, 2026
Merged

kgyrtkirk merged 3 commits into
apache:masterfrom
kgyrtkirk:json-conf-fix

Conversation

@kgyrtkirk

Copy link
Copy Markdown
Member

🐛 Nested-Violation-Crash

Nested @Valid constraint fails -> JsonConfigurator throws bare RuntimeException(NoSuchFieldException). No property named.

🔍 Cause

  • violation path resolved node by node via getDeclaredField on root class (JsonConfigurator.java:175)
  • nested node lives on nested class -> NoSuchFieldException -> rethrown (:193-195)
  • flat configs unaffected: all nodes on root
  • live case: S3StorageConfig -> @Valid S3TransferConfig, bound under druid.storage
💥 Before: druid.storage.transfer.multipartUploadThreshold=0
java.lang.RuntimeException: java.lang.NoSuchFieldException: multipartUploadThreshold
	at org.apache.druid.guice.JsonConfigurator.configurate(JsonConfigurator.java:194)
	at org.apache.druid.guice.JsonConfigurator.configurate(JsonConfigurator.java:91)
	...
Caused by: java.lang.NoSuchFieldException: multipartUploadThreshold
	at java.base/java.lang.Class.getDeclaredField(Class.java:2382)
	at org.apache.druid.guice.JsonConfigurator.configurate(JsonConfigurator.java:175)
	... 6 more

This reverts commit 79ab7f06f929faac50122b1a0853694cbe1e4cba.

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

🟢 Approval recommended

No actionable issues found in this review. The nested Bean Validation path traversal correctly resolves the declared nested type, and the tests cover both generic nested configuration and the S3 production binding.

Reviewed 3 of 3 changed files.


This is an automated review by Codex GPT-5.6-Luna(max)

@FrankChen021 FrankChen021 added the Approval Recommended Used when AI completes a review and reports no findings label Nov 14, 2026

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

🐻

} else {
path.append(".").append(pathPart);
}
beanClazz = theField.getType();

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.

Optional: this fixes the S3 case, but the walk still throws for shapes it doesn't model, e.g. @Valid List<Inner> items (items=[{"count":0}]) or a nested type whose constrained field is declared on a superclass: both still end in RuntimeException: NoSuchFieldException: count. Falling back to the validator's own path in the catch below keeps the property name in the message for those cases too:

        catch (NoSuchFieldException e) {
          path = new StringBuilder(violation.getPropertyPath().toString());
        }

That gives <prefix>.items[0].count - must be greater than or equal to 1 (it loses the @JsonProperty rename for that one violation, which seems fine for an error message).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is a generated problem ...would have been better to just avoid the usage of JsonProperty instead of adding any logic like this....

updated it

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

🟡 Changes recommended

The fallback prevents crashes for list and inherited nested validations, but it can produce incorrect property names when Jackson aliases are used. Preserve alias-aware paths before merging.

Reviewed 3 of 3 changed files; finding in 1 file. No follow-up thread was supplied; the current-head review is sufficient.

Validation: git diff --check passed. No tests or builds were run.

Severity Findings
P0 0
P1 0
P2 1
P3 0
Total 1

This is an automated review by Codex GPT-5.6-Luna(max)

After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.

}
catch (NoSuchFieldException e) {
throw new RuntimeException(e);
path = new StringBuilder(violation.getPropertyPath().toString());

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.

[P2] Fallback loses Jackson property aliases

Finding: When reflection cannot resolve a list/container or inherited-field segment, the fallback replaces the translated path with Bean Validation's Java-name path. This discards @JsonProperty aliases and can report a non-existent configuration property.

Suggestion: Resolve container and inherited types with Jackson metadata, or preserve translated segments while resolving only the remaining suffix; add an aliased list/inherited-field regression.

@FrankChen021 FrankChen021 removed the Approval Recommended Used when AI completes a review and reports no findings label Nov 20, 2026
@kgyrtkirk
kgyrtkirk merged commit 880b924 into apache:master Nov 30, 2026
28 checks passed
@kgyrtkirk
kgyrtkirk deleted the json-conf-fix branch November 30, 2026 08:37
@github-actions github-actions Bot added this to the 40.0.0 milestone Nov 30, 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.

3 participants