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

android-record: Adapt generic types returned by Android reflection to follow Java behavior #252

Merged
merged 2 commits into from
Sep 4, 2024

Conversation

HelloOO7
Copy link
Contributor

@HelloOO7 HelloOO7 commented Sep 3, 2024

Fixes #251.

This PR adds a method to AndroidRecordModule that fixes/resolves GenericArrayTypes and ParameterizedTypes returned by Android reflection on method/constructor parameters. In turn, they behave the same as field types and constructor recognition on records that use both arrays and generic types no longer fails.

The type resolution method is compatible with the one in Android here: https://android.googlesource.com/platform/libcore/+/refs/heads/main/luni/src/main/java/libcore/reflect/ParameterizedTypeImpl.java#75
with the difference that it automatically resolves arrays fully where possible instead of returning an instance of GenericArrayType even on non-generic arrays (which causes errors in the current behaviour).

@cowtowncoder cowtowncoder merged commit f269b35 into FasterXML:2.18 Sep 4, 2024
4 checks passed
@cowtowncoder
Copy link
Member

Forgot to ask for a unit test to show the fix, but not sure how feasible that'd have been. Merged for 2.18.0, regardless.

@HelloOO7
Copy link
Contributor Author

HelloOO7 commented Sep 4, 2024

Oh yeah, unfortunately the behavior only occurs on Android, so I don't think it would be actually testable wirhout stubbing its reflection classes on desktop. Thank you.

@cowtowncoder
Copy link
Member

Right, that makes sense. Thank you for confirming.

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.

Constructor is not recognized when a record uses both arrays and generic types
2 participants