Skip to content

fix: return number variables in the type of the default value - #210

Open
pcbeingused33 wants to merge 1 commit into
DevCycleHQ:mainfrom
pcbeingused33:fix/number-variable-default-type
Open

pcbeingused33 wants to merge 1 commit into
DevCycleHQ:mainfrom
pcbeingused33:fix/number-variable-default-type

Conversation

@pcbeingused33

Copy link
Copy Markdown

variableValue / variable accept Integer, Float and Double defaults as number variables, but the returned value does not follow the class of the default:

Integer limit = client.variableValue(user, "num-var", 0);
// local bucketing: ClassCastException: class java.lang.Double cannot be cast to class java.lang.Integer

Root cause

  • Local bucketing: ProtobufUtils.createVariable always stores getDoubleValue(), so Integer and Float callers get a Double.
  • Cloud bucketing: the value is whatever Jackson picks for the JSON literal (Integer for 5, Double for 2.5), so for example a Double default fails when the served value is a whole number.

The cast happens at the caller, outside the SDK's error handling, so the default value is not used as a fallback.

Fix
Both clients now convert number values to the class of the default value with a small Variable.convertNumber helper, before the after-hooks run. A fractional value requested with an Integer default is truncated, which matches what DevCycleProvider.resolvePrimitiveVariable already does for OpenFeature.

Tests
Added one test for each client (local and cloud). Both fail with ClassCastException without the change and pass with it.

This change was prepared with AI assistance.

@pcbeingused33
pcbeingused33 requested a review from a team as a code owner November 27, 2026 07:08
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.

1 participant