Skip to content

fix: update the SSE message parsing to not cause number exception#289

Merged
suthar26 merged 2 commits intomainfrom
ICP-3942-update-sse-message-parsing
Apr 28, 2026
Merged

fix: update the SSE message parsing to not cause number exception#289
suthar26 merged 2 commits intomainfrom
ICP-3942-update-sse-message-parsing

Conversation

@suthar26
Copy link
Copy Markdown
Contributor

@suthar26 suthar26 commented Apr 16, 2026

fix to combat the SSE read error when parsing the message

closes #288

@suthar26 suthar26 requested a review from a team as a code owner April 16, 2026 15:13
Copilot AI review requested due to automatic review settings April 16, 2026 15:13
Copy link
Copy Markdown
Contributor

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 updates the Android SDK’s Server-Sent Events (SSE) message parsing to prevent runtime number/parsing exceptions when handling realtime update messages, improving robustness of the realtime-config refresh path.

Changes:

  • Extracted SSE message parsing into a dedicated handleSSEMessage function and added JSONException handling.
  • Made parsing tolerant to different SSE payload shapes (outer envelope with "data" vs direct inner payload) and to mixed field types.
  • Updated initEventSource to use the new handler reference.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread android-client-sdk/src/main/java/com/devcycle/sdk/android/api/DevCycleClient.kt Outdated
Comment on lines +201 to +203
} catch (e: JSONException) {
DevCycleLogger.w(e, "SSE Message: Error parsing SSE message data: ${messageEvent.data}")
}
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

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

Avoid logging the full raw SSE payload on JSONException. messageEvent.data may be large and can include config values; logging it can leak sensitive data and create noisy logs. Consider logging only the exception plus a truncated payload, payload length, or an event id/type extracted safely via opt* calls.

Copilot uses AI. Check for mistakes.
Comment thread android-client-sdk/src/main/java/com/devcycle/sdk/android/api/DevCycleClient.kt Outdated
@bencehornak
Copy link
Copy Markdown
Contributor

@suthar26 This PR fixes #288, right?

@suthar26 suthar26 requested a review from jsalaber April 24, 2026 15:03
@suthar26
Copy link
Copy Markdown
Contributor Author

that is correct @bencehornak its to fix #288, will add that as part of the PR description

Copilot AI review requested due to automatic review settings April 28, 2026 14:24
@suthar26 suthar26 force-pushed the ICP-3942-update-sse-message-parsing branch from 265afdf to fc3a216 Compare April 28, 2026 14:24
@suthar26 suthar26 enabled auto-merge (squash) April 28, 2026 14:25
Copy link
Copy Markdown
Contributor

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +16 to +17
* 2. **Direct format** (legacy): The `data` field directly contains the message
* payload as a JSON object (with `type`, `lastModified`, `etag`).
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

SSEMessage KDoc says the "Direct format" is where the data field directly contains the payload as a JSON object, but the implementation (and tests) also support a direct/top-level payload with no data field. Update the KDoc to describe both supported direct forms to avoid confusing consumers.

Suggested change
* 2. **Direct format** (legacy): The `data` field directly contains the message
* payload as a JSON object (with `type`, `lastModified`, `etag`).
* 2. **Direct format** (legacy): The message payload (with `type`, `lastModified`,
* `etag`) is provided either as the top-level JSON object itself, or directly
* in the `data` field as a JSON object.

Copilot uses AI. Check for mistakes.
} else ""

val etag = if (innerData.has("etag") && !innerData.isNull("etag")) {
innerData.getString("etag")
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

innerData.getString("etag") will throw JSONException if etag is present but not a JSON string (e.g., number/boolean/object). Since parse() is documented to return null when data cannot be parsed, consider using optString/opt + toString() (with NULL handling) or wrapping the field extraction in a try/catch and returning null to keep parsing exception-safe.

Suggested change
innerData.getString("etag")
innerData.opt("etag").toString()

Copilot uses AI. Check for mistakes.
@suthar26 suthar26 merged commit bf93108 into main Apr 28, 2026
10 checks passed
@suthar26 suthar26 deleted the ICP-3942-update-sse-message-parsing branch April 28, 2026 14:33
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.

NumberFormatException when refetching configuration

4 participants