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

Object cannot be cast to class retrofit2.ServiceMethod #4113

Closed
swankjesse opened this issue Mar 21, 2024 · 2 comments · Fixed by #4114
Closed

Object cannot be cast to class retrofit2.ServiceMethod #4113

swankjesse opened this issue Mar 21, 2024 · 2 comments · Fixed by #4114

Comments

@swankjesse
Copy link
Collaborator

I ran into this with Retrofit 2.10.

java.lang.ClassCastException: class java.lang.Object cannot be cast to class retrofit2.ServiceMethod (java.lang.Object is in module java.base of loader 'bootstrap'; retrofit2.ServiceMethod is in unnamed module of loader 'app')
	at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:246)
	at retrofit2.Retrofit$1.invoke(Retrofit.java:177)
	at jdk.proxy3/jdk.proxy3.$Proxy139.addPullRequestLabel(Unknown Source)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at misk.client.ClientInvocationHandler.invoke(ClientInvocationHandler.kt:125)
	at jdk.proxy3/jdk.proxy3.$Proxy139.addPullRequestLabel(Unknown Source)
	at com.squareup.cash.treelot.github.PullRequestMaker.addLabels(PullRequestMaker.kt:237)
@swankjesse
Copy link
Collaborator Author

I had misconfigured my method, but rather than a helpful error message I got a Retrofit internal crash. I think we need to make loadServiceMethod handle the case where parseAnnotations throws.

@JakeSteam
Copy link

Error message is seemingly fixed in later versions, but in case anyone gets the same problem: The issue is probably in your API definition.

For me I had (simplified, notice the missing }):

@GET("/myapi/{value1}/{value2/{value3}")
    suspend fun myApiCall(
        @Path("value1") value1: String,
        @Path("value2") value2: String,
        @Path("value3") value3: String
    ): Response<MyResponse>

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 a pull request may close this issue.

2 participants