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

NoClassDefFoundError at DeserializationContext.<init> on Android 4.1.2 and Jackson 2.10.0 #2599

Closed
johnjohndoe opened this issue Jan 19, 2020 · 6 comments
Labels
android Issues related to use on Android platform
Milestone

Comments

@johnjohndoe
Copy link
Contributor

johnjohndoe commented Jan 19, 2020

I discovered a NoClassDefFoundError: java.util.Objects when I run this Android app in the following environment:

  • Android emulator, Nexus 5X, Intel x86 Atom, system-images;android-16;google_apis;x86, revision: 6
  • Android 4.1.2 (API level 16, Jelly Bean),
  • no Google Play Services installed
  • com.fasterxml.jackson.core:jackson-databind:2.10.0 - 2.10.2
  • crash happens for DEBUG and RELEASE builds

Here is the excerpt which causes the crash. The full source code can be found here (commit: db1173da74c2b7c1e296a612af88faf9bb281dc4) where I raised the version of jackson-databind from v.2.9.9 to v.2.10.2:

116 ObjectMapper objectMapper = new ObjectMapper(); // <-- crash

The following stacktrace is generated when I open the ZonesFragment from the toolbar menu:

java.lang.NoClassDefFoundError: java.util.Objects
    at com.fasterxml.jackson.databind.DeserializationContext.<init>(DeserializationContext.java:158)
    at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.<init>(DefaultDeserializationContext.java:44)
    at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext$Impl.<init>(DefaultDeserializationContext.java:318)
    at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:628)
    at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:531)
    at de.avpptr.umweltzone.utils.ContentProvider.getContent(ContentProvider.java:116)
    at de.avpptr.umweltzone.utils.ContentProvider.getContent(ContentProvider.java:101)
    at de.avpptr.umweltzone.utils.ContentProvider.getAdministrativeZones(ContentProvider.java:76)
    at de.avpptr.umweltzone.zones.ZonesFragment.onActivityCreated(ZonesFragment.kt:41)
    ....

I also checked if the crash disappears when I use the new builder pattern:

117 ObjectMapper objectMapper = JsonMapper.builder() // <-- crash
118         .addModule(module)
119         .defaultDateFormat(DateFormats.getDateFormat(datePattern))
120         .build();

The same error occurs. Here is the associated stacktrace:

java.lang.NoClassDefFoundError: java.util.Objects
    at com.fasterxml.jackson.databind.DeserializationContext.<init>(DeserializationContext.java:158)
    at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.<init>(DefaultDeserializationContext.java:44)
    at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext$Impl.<init>(DefaultDeserializationContext.java:318)
    at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:628)
    at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:540)
    at com.fasterxml.jackson.databind.json.JsonMapper.<init>(JsonMapper.java:93)
    at com.fasterxml.jackson.databind.json.JsonMapper.<init>(JsonMapper.java:89)
    at com.fasterxml.jackson.databind.json.JsonMapper.builder(JsonMapper.java:114)
    at de.avpptr.umweltzone.utils.ContentProvider.getContent(ContentProvider.java:117)
    at de.avpptr.umweltzone.utils.ContentProvider.getContent(ContentProvider.java:101)
    at de.avpptr.umweltzone.utils.ContentProvider.getAdministrativeZones(ContentProvider.java:76)
    at de.avpptr.umweltzone.zones.ZonesFragment.onActivityCreated(ZonesFragment.kt:41)

Findings

  • The crash does not occur when I use jackson-databind:2.9.9.
  • The crash does not occur when I run the app on an Android emulator, Nexus 5, Android 4.4.2 (API level 19, KitKat), Intel x86 Atom, system-images;android-19;google_apis;x86, revision: 38.
  • The crash does also occur when I run the app on an Android emulator, Nexus 5, Android 4.3.1 (API level 18, Jelly Bean), Intel x86 Atom, system-images;android-18;google_apis;x86, revision: 6.

Related

@cowtowncoder cowtowncoder added 2.10 android Issues related to use on Android platform labels Jan 19, 2020
@cowtowncoder
Copy link
Member

Line 158 would be:

        _factory = Objects.requireNonNull(df, "Cannot pass null DeserializerFactory");

Looking at java.util.Objects javadocs (https://docs.oracle.com/javase/8/docs/api/), it was added in Java 7 (1.7). At this point this usage is allowed as JDK 7 is the baseline; 2.9 did not use it, 2.10 has just couple (3 to be exact), all for Objects.requireNonNull().

Now... given small number of usages it would probably be possible to replace them with equivalent JDK 6 code (it's just a null check). But I would be interested in knowing significance of the issue, wrt Android versions. I remember that compatibility with J2SE tends to increase with newer Android versions and in some cases problems only affect old enough versions that it is not necessarily worth it addressing the problem.
But it sounds like this may not be the case here?

@johnjohndoe
Copy link
Contributor Author

... But I would be interested in knowing significance of the issue, wrt Android versions ...

If I get you right then you are asking for numbers of the current distribution of Android versions. The official statement from Google can be found here - the latest version is from May 2019. As the table shows there is minimal amount of users (3.5%) which use devices running Android 4.0.x (API 15) - 4.3.x (API 19).

Android distribution

@cowtowncoder
Copy link
Member

Yes, that is what I wanted to get an idea of. As SDK javadocs:

https://developer.android.com/reference/java/util/Objects

class was added in Android SDK API level 19. With assumption that 19+ do not have the issue, it would affect less than 4% of phones. Not entirely trivial amount but quite small.

I guess I might as well replace usage for now, regardless. Would be interesting to know how far back this helps. I am guessing it might make 16+ work but no further (I think there are other issues for older versions).

@johnjohndoe
Copy link
Contributor Author

johnjohndoe commented Jan 20, 2020

I am guessing it might make 16+ work but no further (I think there are other issues for older versions).

At least I know that there is other issues which we discussed in #1802, linked above.

API 14 is the lowest version being relevant when published on Google Play since Google has forced developers to comply to this version or higher in 2019.

@cowtowncoder cowtowncoder added this to the 2.10.3 milestone Jan 20, 2020
@cowtowncoder
Copy link
Member

Ah. Yes, that's the previous discussion I vaguely recalled.

I changed 2.10 branch to replace few Objects.requireNonNull() instances (except for tests), so 2.10.3 should work better.

One note: I could add a note on

https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.10

if it could be verified that specific API level appears to work. Earlier releases notes (esp https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.8) actually suggest 19+ would be needed but I think that was due to #1802 being fixed quite late in patches.

@johnjohndoe
Copy link
Contributor Author

johnjohndoe commented Jan 21, 2020

I changed 2.10 branch to replace few Objects.requireNonNull() instances (except for tests), so 2.10.3 should work better.

Thank you for the quick patch.

One note: I could add a note on

https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.10

if it could be verified that specific API level appears to work.

I am happy to test this with my project and share the results with you. I am looking forward to do so once the version is released - or is there a snapshot build available somewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Issues related to use on Android platform
Projects
None yet
Development

No branches or pull requests

2 participants