Commit bfce072
fix: Accept any numeric tracking event value (#65)
`track` threw a `ClassCastException` for a tracking event value which
was not a `Double`.
- `TrackingEventDetails.getValue()` is an `Optional<Number>`, so `new
MutableTrackingEventDetails(99)` (an `Integer`) reached the provider and
failed the `(Double)` cast before any event was sent.
- The value is now converted with `Number.doubleValue()`, which is what
the LaunchDarkly `trackMetric` API takes.
- Added a test tracking an integer value.
<details>
<summary>Implementation details</summary>
The OpenFeature Java SDK does not constrain the numeric type an
application passes, and `MutableTrackingEventDetails` stores the
`Number` as given, so any of `Integer`, `Long`, `Float`, or `BigDecimal`
reached the cast. Only `Double` worked.
Testing: the change is covered by
`ProviderTest.itCanTrackAnIntegerTrackingEventValue`. The test suite
could not be run on this machine because Maven Central and the Gradle
plugin portal answered dependency resolution with HTTP 429 from this
network; CI runs the suite.
</details>
Link to Devin session:
https://app.devin.ai/sessions/fe1eb757fe694ef79f3d09f6307d4b47
Open in Devin Desktop:
https://app.devin.ai/desktop/session/fe1eb757fe694ef79f3d09f6307d4b47?variant=devin
Requested by: @kinyoklion
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Overview**
> Fixes **`track`** failing with a **`ClassCastException`** when
**`TrackingEventDetails`** carries a metric that is not a **`Double`**
(for example **`MutableTrackingEventDetails(99)`** with an
**`Integer`**).
>
> The provider now reads **`Optional<Number>`** via
**`Number.doubleValue()`** before calling LaunchDarkly
**`trackMetric`**, matching the API’s double metric parameter. A unit
test asserts integer metrics are forwarded as **`99.0`**.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
d3177c0. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Signed-off-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>1 parent 373eac5 commit bfce072
2 files changed
Lines changed: 22 additions & 1 deletion
File tree
- src
- main/java/com/launchdarkly/openfeature/serverprovider
- test/java/com/launchdarkly/openfeature/serverprovider
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
269 | | - | |
| 269 | + | |
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
| |||
Lines changed: 21 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
217 | 238 | | |
0 commit comments