Skip to content

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

Closed

Description

@ylk2534246654

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.

Activity

  1. 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[/+] on Jun 16, 2022
  2. p-bakker commented on Jun 19, 2022

    @p-bakker
    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

  3. added
    Android
    on Jun 19, 2022
  4. tonygermano commented on Aug 2, 2022

    @tonygermano
    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.

  5. added a commit that references this issue on Aug 6, 2022
  6. p-bakker commented on Nov 10, 2022

    @p-bakker
    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

  7. naijun0403 commented on Nov 10, 2022

    @naijun0403
    Contributor

    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.

  8. p-bakker commented on Nov 10, 2022

    @p-bakker
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    AndroidRegression

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions