Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Kotlin metadata manually to honor nullability and avoid kotlin-metadata-jvm dep #3075

Open
AidanLaing opened this issue Apr 12, 2019 · 12 comments
Labels

Comments

@AidanLaing
Copy link

@AidanLaing AidanLaing commented Apr 12, 2019

Version: 2.6.0-SNAPSHOT
Exception: KotlinNullPointerException
Message: Response from {path to my suspend fun...} was null but response body type was declared as non-null

The current structure of my suspend fun in my service interface:

@POST("api/...")
suspend fun request(@Body body: Body): Response?

I'm using Gson for serialization.

Is there a way to declare the response body type as nullable that I'm missing? I've tried adding null safety on my response object with ? and @Nullable with no success.

@JakeWharton

This comment has been minimized.

Copy link
Collaborator

@JakeWharton JakeWharton commented Apr 12, 2019

@Rody66

This comment was marked as off-topic.

Copy link

@Rody66 Rody66 commented Apr 18, 2019

@JakeWharton Please notice that suspend ...: List<*> also is not supported.
Version: 2.6.0-SNAPSHOT
For instance: suspend fun fetchStrings(): List<String>

@JakeWharton

This comment was marked as resolved.

Copy link
Collaborator

@JakeWharton JakeWharton commented Apr 18, 2019

@JakeWharton JakeWharton changed the title Coroutines suspend fun 204 no content response throwing KotlinNullPointerException Parse Kotlin metadata manually to honor nullability and avoid kotlin-metadata-jvm dep Jun 5, 2019
@wlara

This comment was marked as off-topic.

Copy link

@wlara wlara commented Jun 12, 2019

Added @JakeWharton I'm getting a similar KotlinNullPointerException using a service that returns 204 (no content) on a delete call. Something like this:
@DELETE("/api/{id}") suspend fun deleteItem(@Path("id") id: String)
Would that use case also be fixed as part of this issue?

@JakeWharton

This comment was marked as off-topic.

Copy link
Collaborator

@JakeWharton JakeWharton commented Jun 12, 2019

No. That's #2867

@Hospes

This comment has been minimized.

Copy link

@Hospes Hospes commented Jul 3, 2019

Hi there! Any chance to get update on this issue? :) Want to move to 2.6.0 and remove all other dependencies but can't cause of null response body not supported :(

@jgavazzisp

This comment was marked as off-topic.

Copy link

@jgavazzisp jgavazzisp commented Jul 16, 2019

Moved to #2867

@JakeWharton

This comment was marked as off-topic.

Copy link
Collaborator

@JakeWharton JakeWharton commented Jul 16, 2019

That is not related to this issue. It's #2867.

@JavierSegoviaCordoba

This comment was marked as off-topic.

Copy link

@JavierSegoviaCordoba JavierSegoviaCordoba commented Jul 23, 2019

So at this moment we should force an exception with a interceptor for 204 responses?

@JakeWharton

This comment was marked as off-topic.

Copy link
Collaborator

@JakeWharton JakeWharton commented Jul 23, 2019

This issue has nothing to do with 204 handling and when it's fixed 204 handling won't have changed in any way. That's #2867.

@claucookie

This comment has been minimized.

Copy link

@claucookie claucookie commented Jul 26, 2019

Just in case it helps. I was experiencing the exact same KotlinNPE issue over the last 2 days and after trying Converters and Adapters what really worked was to return Response<Unit> in the retrofit method declaration.

I use Retrofit 2.6.0.

@Pitel

This comment has been minimized.

Copy link

@Pitel Pitel commented Dec 11, 2019

Any progress? We've just changed some of our REST endpoints to 204. So I thought it would be enought to just remove response type (making it Unit), but no.

Using Response<Unit> works 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
9 participants
You can’t perform that action at this time.