-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Enforce string values in InstanceSpec's custom properties #1274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enforce string values in InstanceSpec's custom properties #1274
Conversation
`InstanceSpec`'s `customProperties` will be fed to `Properties` in `QuorumConfigBuilder::buildConfigProperties`, so we have to make sure it contains only string values. Instead of `ClassCastException` in read phase, this pr complains in `InstanceSpec` construction phase. We could deprecate these constructors in next step by introducing builder for `InstanceSpec`(apache#1222). Fixes apache#1178, CURATOR-663.
2330f0a to
50b74fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enforces that all values in InstanceSpec's customProperties map are strings to prevent ClassCastException errors when the properties are later used in QuorumConfigBuilder::buildConfigProperties. The validation is moved from runtime usage to construction time for earlier error detection.
Key changes:
- Added validation to ensure all custom property values are strings during
InstanceSpecconstruction - Replaced potential runtime
ClassCastExceptionwith earlyIllegalArgumentException
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| private static Map<String, Object> enforceStringMap(Map<String, Object> properties) { | ||
| for (Map.Entry<String, Object> entry : properties.entrySet()) { | ||
| if (!(entry.getValue() instanceof String)) { | ||
| String msg = String.format("property %s has non string value %s", entry.getKey(), entry.getValue()); |
Copilot
AI
Aug 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message should include the expected type for clarity. Consider changing to: "Property '%s' must have a string value, but found %s of type %s" and include entry.getValue().getClass().getSimpleName().
| String msg = String.format("property %s has non string value %s", entry.getKey(), entry.getValue()); | |
| String msg = String.format("Property '%s' must have a string value, but found %s of type %s", entry.getKey(), entry.getValue(), entry.getValue() == null ? "null" : entry.getValue().getClass().getSimpleName()); |
tisonkun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect a better solution to change the type signature in the ctor, but it would be a break change anyway. Perhaps we can track these possible break changes that helps in a tracking issue said for 6.0.
I think we can create labels for this ? We should discuss this in dev mail. |
InstanceSpec'scustomPropertieswill be fed toPropertiesinQuorumConfigBuilder::buildConfigProperties, so we have to make sure itcontains only string values.
Instead of
ClassCastExceptionin read phase, this pr complains inInstanceSpecconstruction phase.We could deprecate these constructors in next step by introducing builder
for
InstanceSpec(#1222).Fixes #1178, CURATOR-663.