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

Rhino 1.7.14 is not available under Android SDK 21,java.lang.NoSuchMethodError: java.util.Map.putIfAbsent #1237

Closed
ylk2534246654 opened this issue Jun 16, 2022 · 5 comments · Fixed by #1252
Labels
Android Issues related to running Rhino on Android Regression

Comments

@ylk2534246654
Copy link

Stack trace:

Caused by: java.lang.NoSuchMethodError: java.util.Map.putIfAbsent
at org.mozilla.javascript.JavaMembers.registerMethod(JavaMembers.java:389)
at org.mozilla.javascript.JavaMembers.discoverPublicMethods(JavaMembers.java:382)
at org.mozilla.javascript.JavaMembers.discoverAccessibleMethods(JavaMembers.java:355)
at org.mozilla.javascript.JavaMembers.discoverAccessibleMethods(JavaMembers.java:308)
at org.mozilla.javascript.JavaMembers.reflect(JavaMembers.java:425)
at org.mozilla.javascript.JavaMembers.<init>(JavaMembers.java:63)
at org.mozilla.javascript.JavaMembers.createJavaMembers(JavaMembers.java:833)
at org.mozilla.javascript.JavaMembers.lookupClass(JavaMembers.java:792)
at org.mozilla.javascript.NativeJavaObject.initMembers(NativeJavaObject.java:63)
at org.mozilla.javascript.NativeJavaObject.<init>(NativeJavaObject.java:53)
at org.mozilla.javascript.NativeJavaObject.<init>(NativeJavaObject.java:44)
at org.mozilla.javascript.WrapFactory.wrapAsJavaObject(WrapFactory.java:120)
at org.mozilla.javascript.WrapFactory.wrap(WrapFactory.java:74)
at org.mozilla.javascript.Context.javaToJS(Context.java:1753)
at org.mozilla.javascript.Context.javaToJS(Context.java:1712)

Replace the JavaMembers class back to 1.7.13 to solve the problem.

@ylk2534246654 ylk2534246654 changed the title Rhino 1.7.14 is not available under Android SDK 21,java.lang.NoSuchMethodError: java.util.Map.putIfAbsent Rhino 1.7.14 is not available under Android SDK 21,java.lang.NoSuchMethodError: java.util.Map.putIfAbsent Jun 16, 2022
@p-bakker
Copy link
Collaborator

Map.putIfAbsent only got added in API version 24, see https://developer.android.com/reference/java/util/Map#putIfAbsent(K,%20V), whereas in Java it got added in 1.8

So we'll need to see whether we can prevent the reported error from occurring, but this also ties into the larger challenge of running the entire Rhino testsuite against Android (after determining which Android SDK versions we can/should support), as to prevent such breakage from occurring in the first place.

Any help getting this going from Rhino users on Android would be more than welcome

@p-bakker p-bakker added Android Issues related to running Rhino on Android Regression labels Jun 19, 2022
@tonygermano
Copy link
Contributor

API version 24 corresponds to Android 7. Currently only versions 10+ are still maintained. Version 6, which is the newest version without putIfAbsent, has not had a security update since August 2018.

gbrail pushed a commit that referenced this issue Aug 6, 2022
Remove usage of putIfAbsent() in the Hashmap class. This method does not exist on many old Android releases and there's no real downside to removing it.

Fixes #1237
@p-bakker
Copy link
Collaborator

@ylk2534246654 @naijun0403 question about this issue with Map.putIfAbsent on Android: from what I understand, when Java code is compiled to run on Android, the D8 compiler would take care of desugaring Map.putIfAbsent if properly configured, see https://developer.android.com/studio/write/java8-support#library-desugaring and https://developer.android.com/studio/write/java8-support-table

Asking because I'm wondering if this issue was indeed something that needed fixing on the Rhino side and in the future we ought to remain careful not to introduce similar issues again or whether this is something that could've been handled with proper build config on the Android side

@naijun0403
Copy link
Contributor

naijun0403 commented Nov 10, 2022

Asking because I'm wondering if this issue was indeed something that needed fixing on the Rhino side and in the future we ought to remain careful not to introduce similar issues again or whether this is something that could've been handled with proper build config on the Android side

Obviously, this will solve the problem with java.util.

However, Java apis outside of java.util (eg #1149) are not supported. However, this issue may be solvable by using the desugaring.

@p-bakker
Copy link
Collaborator

Obviously, this will solve the problem with java.util.

K, great, tnx for the information. I'll make a note to add to the Android documentation to make sure to configure the build process on Android as such that it'll desugar unavailable API's when targeting old Android versions, so within Rhino we don't have to keep Android compatibility in the back of our mind in that regards

However, Java apis outside of java.util (eg #1149) are not supported. However, this issue may be solvable by using the desugaring.

Yup, that is understood. We're open to suggestions or better yet help in setting up something on our CI to surface such incompatibilities, see #1152 and some of the comments in #1149

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

Successfully merging a pull request may close this issue.

4 participants