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

NoSuchMethodError for java.lang.Constructor#getParameterCount #2876

Closed
damianw opened this issue Mar 25, 2024 · 4 comments · Fixed by #2881
Closed

NoSuchMethodError for java.lang.Constructor#getParameterCount #2876

damianw opened this issue Mar 25, 2024 · 4 comments · Fixed by #2881

Comments

@damianw
Copy link
Contributor

damianw commented Mar 25, 2024

This method was not added until Java 8, and thus is not available on Android API levels lower than 26:

Fatal Exception: java.lang.NoSuchMethodError: No virtual method getParameterCount()I in class Ljava/lang/reflect/Constructor; or its super classes (declaration of 'java.lang.reflect.Constructor' appears in /system/framework/core-oj.jar)
       at com.squareup.wire.KotlinConstructorBuilder.build(KotlinConstructorBuilder.kt:91)
       at com.squareup.wire.MessageJsonAdapter.fromJson(MessageJsonAdapter.kt:85)
       at com.squareup.wire.MessageJsonAdapter.fromJson(MessageJsonAdapter.kt:24)
       at com.squareup.moshi.internal.NullSafeJsonAdapter.fromJson(NullSafeJsonAdapter.java:41)
       ...        

I'm happy to put up a PR with a fix, but am curious to know what an appropriate test would look like given that there aren't currently any JDK-specific or Android-specific tests already in the codebase.

@oldergod
Copy link
Member

Thanks! Do you think you could make a new Android sample with API levels to 25 or less?

@damianw
Copy link
Contributor Author

damianw commented Mar 26, 2024

Can do, but can you clarify what you're asking for? Do you mean something in the samples directory?

@oldergod
Copy link
Member

oldergod commented Mar 26, 2024

Yes. For instance, make a new module copying android-app-kotlin-sample and add some code serializing/deserializing json to call the code you mentioned above

@damianw
Copy link
Contributor Author

damianw commented Mar 27, 2024

I put up a PR #2881 - let me know if that's what you're looking for

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