Skip to content

Record types are broken on Android when using R8 #5192

Closed
@HelloOO7

Description

@HelloOO7

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

When using Jackson along with the Android record support module, processing of record types fails when R8 (Android's code minifier) is used.

The real cause behind this problem lies not within Jackson, but is a consequence of the fact that R8 will rename all occurences of "java.lang.Record" to "com.android.tools.r8.RecordTag" when minification is enabled (for some reason, it does not happen when it is off - in that case everything works fine).

However, Jackson's ClassUtil.isRecordType detects whether a class is or is not a record by comparing the class name (which R8 replaces), thus erroneously deeming an Android record to be a Java record, which it is, in fact, not. Subsequently, an exception is thrown in JDK14Util when it tries to access Record-related methods on java.lang.Class, which are not present on Android.

I came up with a workaround of using "java.lang.Record".equals(parent.getName()) && !"com.android.tools.r8.RecordTag".equals(parent.getName()), which will always evaluate to false on Android. But given that Jackson by itself isn't Android-focused, I'm not sure if that is a proper solution. Perhaps calling class.isRecord() via reflection (and returning false if the method does not exist) would be better?

Version Information

2.19.0

Reproduction

  1. Create a record in an Android project and compile it with R8/Proguard enabled.
  2. Attempt to deserialize the record using Jackson.
  3. An exception Failed to access Methods needed to support java.lang.Record: (java.lang.NoSuchMethodException) getRecordComponents [] will be thrown.

Expected behavior

Jackson should not consider records on Android to be actual Java records, even if R8 manipulates the class name strings.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.20Issues planned at 2.20 or later

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions