Skip to content

fix: Drop trackMetric events with a NaN or infinite metric value - #287

Merged
tanderson-ld merged 2 commits into
launchdarkly:mainfrom
pcbeingused33:fix/track-metric-non-finite
Nov 30, 2026
Merged

tanderson-ld merged 2 commits into
launchdarkly:mainfrom
pcbeingused33:fix/track-metric-non-finite

Conversation

@pcbeingused33

@pcbeingused33 pcbeingused33 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions (LDClientEventTest run on JDK 17 only)

Related issues

No issue in this repository. Same failure mode as launchdarkly/go-server-sdk#520 and launchdarkly/ruby-server-sdk#498.

Describe the solution you've provided

LDClient#trackMetric passes metricValue to the event processor without checking it. For NaN or ±Infinity, Gson throws in EventOutputFormatter when the value is written. The exception is caught around the whole flush in DefaultEventProcessor, so the other events and the summaries in that batch are not delivered either.

trackMetric now checks the value after the existing context checks. For a non-finite value it logs a warning with the event name and does not record the event. Finite values are unchanged.

The added test trackMetricWithNonFiniteValueDoesNotSendEvent covers all three values. It fails without the change and passes with it.

Describe alternatives you've considered

Checking in EventOutputFormatter (shared internal library). That would also protect the payload, but the Go SDK fix put the check in the SDK, where it can warn at the call site.

Additional context

This change was prepared with AI assistance (Claude Code).


Note

Overview
LDClient#trackMetric now treats NaN and ±Infinity like invalid input: after the existing context checks it logs a warning (including the event name) and does not call the event processor, so bad metrics never reach JSON serialization.

This avoids Gson failing during event flush and taking down the rest of the batch (other custom events and summaries). Valid finite metrics behave as before.

LDClientEventTest adds trackMetricWithNonFiniteValueDoesNotSendEvent, asserting NaN and both infinities produce no events.

Reviewed by Cursor Bugbot for commit fcc9bb0. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused33
pcbeingused33 requested a review from a team as a code owner November 27, 2026 06:55
@tanderson-ld

Copy link
Copy Markdown
Contributor

bugbot review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit fcc9bb0. Configure here.

@tanderson-ld
tanderson-ld merged commit 319a441 into launchdarkly:main Nov 30, 2026
31 checks passed
tanderson-ld pushed a commit that referenced this pull request Nov 30, 2026
🤖 I have created a release *beep* *boop*
---


##
[7.19.1](launchdarkly-java-server-sdk-7.19.0...launchdarkly-java-server-sdk-7.19.1)
(2026-11-30)


### Bug Fixes

* Drop trackMetric events with a NaN or infinite metric value
([#287](#287))
([319a441](319a441))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> **Release Please** bumps **launchdarkly-java-server-sdk** from
**7.19.0** to **7.19.1** in the manifest, Gradle `version`,
`Version.SDK_VERSION`, and **CHANGELOG**.
> 
> The documented fix in this patch is **`trackMetric` no longer records
events when the metric value is NaN or infinite**—those calls are
ignored with a warning instead of being sent to LaunchDarkly
([#287](#287)).
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
80f6da0. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants