Skip to content

Conversation

@graycreate
Copy link
Member

Summary

  • Fixes NullPointerException crash when OkHttp attempts to close ResponseBody
  • Replaces custom ResponseBody implementation with proper ResponseBody.create()
  • Ensures valid BufferedSource is always returned

Problem

The app was crashing with the following stack trace from Google Play Console:

java.lang.NullPointerException:
  at okhttp3.internal._UtilCommonKt.b (-UtilCommon.kt:3)
  at okhttp3.ResponseBody.close (ResponseBody.kt:195)
  at okhttp3.Response.close (Response.kt:343)

Root Cause

In APIService.java's ConfigInterceptor, when a network request fails, we were creating a custom ResponseBody with a source() method that returned null. When OkHttp tried to close this response, it caused a NullPointerException.

Solution

Replace the custom anonymous ResponseBody class with ResponseBody.create() which properly handles the BufferedSource creation and ensures no null references.

Test Plan

  • Build project successfully
  • Install and run on Pixel 8 device
  • Verify app launches without crashes
  • Monitor crash reports after release

🤖 Generated with Claude Code

- Replace custom ResponseBody anonymous class with ResponseBody.create()
- Ensures valid BufferedSource is returned instead of null
- Prevents NullPointerException when OkHttp attempts to close response
- Fixes crash reported in Google Play Console

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings September 17, 2025 10:30
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

Fixes a NullPointerException crash occurring when OkHttp attempts to close ResponseBody objects with null BufferedSource. The fix replaces a custom anonymous ResponseBody implementation that returned null from its source() method with the proper ResponseBody.create() factory method.

  • Replaces custom ResponseBody anonymous class with ResponseBody.create() factory method
  • Ensures valid BufferedSource is always provided to prevent null pointer exceptions
  • Adds meaningful error message content to the response body

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@graycreate graycreate merged commit cc8a7cd into main Sep 17, 2025
5 checks passed
@graycreate graycreate deleted the bugfix/okhttp-response-body-npe branch September 17, 2025 10:43
@graycreate
Copy link
Member Author

Released in 2.3.6

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