Skip to content

Commit

Permalink
Add service class & instance to Invocation
Browse files Browse the repository at this point in the history
Fixes #3730
  • Loading branch information
efemoney committed Jun 1, 2022
1 parent 3a49a6a commit dba8ebd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 3 additions & 1 deletion retrofit/src/main/java/retrofit2/Invocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public static Invocation of(Class<?> service, @Nullable Object instance, Method
}

public static Invocation of(Method method, List<?> arguments) {
return of(method.getDeclaringClass(), null, method, arguments);
Objects.requireNonNull(method, "method == null");
Objects.requireNonNull(arguments, "arguments == null");
return new Invocation(method.getDeclaringClass(), null, method, new ArrayList<>(arguments)); // Defensive copy.
}

private final Class<?> service;
Expand Down
7 changes: 2 additions & 5 deletions retrofit/src/main/java/retrofit2/KotlinExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package retrofit2

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.suspendCancellableCoroutine
import java.lang.reflect.ParameterizedType
import kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED
import kotlin.coroutines.intrinsics.intercepted
import kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn
Expand All @@ -40,11 +39,9 @@ suspend fun <T : Any> Call<T>.await(): T {
val body = response.body()
if (body == null) {
val invocation = call.request().tag(Invocation::class.java)!!
val service = invocation.service()
val method = invocation.method()
val e = KotlinNullPointerException("Response from " +
method.declaringClass.name +
'.' +
method.name +
val e = KotlinNullPointerException("Response from ${service.name}.${method.name}" +
" was null but response body type was declared as non-null")
continuation.resumeWithException(e)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Response intercept(Chain chain) throws IOException {
if (invocation != null) {
System.out.printf(
"%s.%s %s HTTP %s (%.0f ms)%n",
invocation.method().getDeclaringClass().getSimpleName(),
invocation.service().getSimpleName(),
invocation.method().getName(),
invocation.arguments(),
response.code(),
Expand Down

0 comments on commit dba8ebd

Please sign in to comment.