Skip to content

Conversation

@kezhuw
Copy link
Member

@kezhuw kezhuw commented Aug 18, 2025

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(#1222).

Fixes #1178, CURATOR-663.

`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.
@kezhuw kezhuw force-pushed the fix-class-cast-exception-due-to-non-strings-in-custom-properties branch from 2330f0a to 50b74fb Compare August 19, 2025 03:40
@kezhuw kezhuw changed the title Fix ClassCastException due to no string values in InstanceSpec's custom properties Enforce string values in InstanceSpec's custom properties Aug 19, 2025
@kezhuw kezhuw requested a review from Copilot August 19, 2025 05:29
Copy link

Copilot AI left a 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 InstanceSpec construction
  • Replaced potential runtime ClassCastException with early IllegalArgumentException

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());
Copy link

Copilot AI Aug 19, 2025

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().

Suggested change
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());

Copilot uses AI. Check for mistakes.
Copy link
Member

@tisonkun tisonkun left a 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.

@kezhuw kezhuw merged commit 0b549b7 into apache:master Aug 19, 2025
10 checks passed
@kezhuw
Copy link
Member Author

kezhuw commented Aug 19, 2025

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.

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.

[CURATOR-663] ZooKeeperServerEmbeddedAdapter.configure might fail with ClassCastException

3 participants