Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6RC2
    • Fix Version/s: JRuby 1.6RC3
    • Component/s: None
    • Labels:
      None
    • Environment:
      On Android using Ruboto 0.5.1
    • Number of attachments :
      0

      Description

      Simple java_imports now throw an exception:

      Initializing JRuby...Done
      >>[Running toast.rb]
      org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `name' for #<Java::JavaLang::Package:0x407a8580>
      at Object.java_import(file:/mnt/asec/org.ruboto.irb-2/pkg.apk!/builtin/javasupport/core_ext/object.rb:61)
      at #<Class:0x1405e96d0>.(root)(<script>:2)
      => null

      The line:
      import 'android.widget.Toast'

      Same problem if it is java_import. Java::android.widget::Toast works fine. Same problem with core classes like java.lang.Thread. Can't duplicate when not on Android.

      This works fine with JRuby 1.5.6 and JRuby 1.6.0.RC1. I tried to use the latest (today) code on github, but "ant gem" failed.

        Activity

        Hide
        Uwe Kubosch added a comment - - edited

        Any luck with this? It is also failing with current master in ruboto-core generated apps.

        Show
        Uwe Kubosch added a comment - - edited Any luck with this? It is also failing with current master in ruboto-core generated apps.
        Hide
        Charles Oliver Nutter added a comment -

        Looking into this before RC3 release today.

        Show
        Charles Oliver Nutter added a comment - Looking into this before RC3 release today.
        Charles Oliver Nutter made changes -
        Field Original Value New Value
        Assignee Thomas E Enebo [ enebo ] Charles Oliver Nutter [ headius ]
        Fix Version/s JRuby 1.6RC3 [ 17147 ]
        Charles Oliver Nutter made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        Charles Oliver Nutter added a comment -

        Ok, this one is peculiar. The line in question:

              package_name = package.name
        

        ...should just be working against a java.lang.Package, which defines getName. That should get mapped to "name" and this code should work. The error also reports that it is a java.lang.Package (Java::JavaLang::Package) so I'm very confused what's happening here.

        I'll have to boot up a fresh Ruboto app and see what's happening.

        Show
        Charles Oliver Nutter added a comment - Ok, this one is peculiar. The line in question: package_name = package.name ...should just be working against a java.lang.Package, which defines getName. That should get mapped to "name" and this code should work. The error also reports that it is a java.lang.Package (Java::JavaLang::Package) so I'm very confused what's happening here. I'll have to boot up a fresh Ruboto app and see what's happening.
        Hide
        Charles Oliver Nutter added a comment -

        I have successfully reproduced the problem with a local app. Continuing to investigate.

        Show
        Charles Oliver Nutter added a comment - I have successfully reproduced the problem with a local app. Continuing to investigate.
        Hide
        Charles Oliver Nutter added a comment -

        I dumped out the package object and the list of methods it contains, and it looks very peculiar:

        W/System.err(  409): #<Java::JavaLang::Package:0x442f0238>
        W/System.err(  409): ["==", "===", "=~", "__id__", "__jcreate!", "__jsend!", "__send__", "class", "clone", "com", "display", "dup", "enum_for", "eql?", "equal?", "equals", "equals?", "extend", "finalize", "freeze", "frozen?", "getAnnotation", "getAnnotations", "getClass", "getDeclaredAnnotations", "getImplementationTitle", "getImplementationVendor", "getImplementationVersion", "getName", "getSpecificationTitle", "getSpecificationVendor", "getSpecificationVersion", "getnull_anullnnotation", "getnull_anullnnotations", "getnull_cnulllass", "getnull_dnulleclarednull_anullnnotations", "getnull_inullmplementationnull_tnullitle", "getnull_inullmplementationnull_vnullendor", "getnull_inullmplementationnull_vnullersion", "getnull_nnullame", "getnull_snullpecificationnull_tnullitle", "getnull_snullpecificationnull_vnullendor", "getnull_snullpecificationnull_vnullersion", "handle_different_imports", "hash", "hashCode", "hashnull_cnullode", "id", "include_class", "initialize", "inspect", "instance_eval", "instance_exec", "instance_of?", "instance_variable_defined?", "instance_variable_get", "instance_variable_set", "instance_variables", "internalClone", "internalnull_cnulllone", "isAnnotationPresent", "isCompatibleWith", "isSealed", "is_a?", "isnull_anullnnotationnull_pnullresent", "isnull_anullnnotationnull_pnullresent?", "isnull_cnullompatiblenull_wnullith", "isnull_cnullompatiblenull_wnullith?", "isnull_snullealed", "isnull_snullealed?", "java", "java_annotation", "java_class", "java_implements", "java_kind_of?", "java_method", "java_name", "java_object", "java_object=", "java_package", "java_require", "java_send", "java_signature", "javax", "kind_of?", "marshal_dump", "marshal_load", "method", "methods", "nil?", "notify", "notifyAll", "notifynull_anullll", "object_id", "org", "private_methods", "protected_methods", "public_methods", "respond_to?", "send", "singleton_methods", "synchronized", "taint", "tainted?", "tap", "toString", "to_a", "to_enum", "to_java", "to_java_object", "to_s", "tonull_snulltring", "type", "untaint", "wait"]
        

        Whynull arenull therenull sonull manynull nullsnull?

        Show
        Charles Oliver Nutter added a comment - I dumped out the package object and the list of methods it contains, and it looks very peculiar: W/System.err( 409): #<Java::JavaLang::Package:0x442f0238> W/System.err( 409): ["==", "===", "=~", "__id__", "__jcreate!", "__jsend!", "__send__", "class", "clone", "com", "display", "dup", "enum_for", "eql?", "equal?", "equals", "equals?", "extend", "finalize", "freeze", "frozen?", "getAnnotation", "getAnnotations", "getClass", "getDeclaredAnnotations", "getImplementationTitle", "getImplementationVendor", "getImplementationVersion", "getName", "getSpecificationTitle", "getSpecificationVendor", "getSpecificationVersion", "getnull_anullnnotation", "getnull_anullnnotations", "getnull_cnulllass", "getnull_dnulleclarednull_anullnnotations", "getnull_inullmplementationnull_tnullitle", "getnull_inullmplementationnull_vnullendor", "getnull_inullmplementationnull_vnullersion", "getnull_nnullame", "getnull_snullpecificationnull_tnullitle", "getnull_snullpecificationnull_vnullendor", "getnull_snullpecificationnull_vnullersion", "handle_different_imports", "hash", "hashCode", "hashnull_cnullode", "id", "include_class", "initialize", "inspect", "instance_eval", "instance_exec", "instance_of?", "instance_variable_defined?", "instance_variable_get", "instance_variable_set", "instance_variables", "internalClone", "internalnull_cnulllone", "isAnnotationPresent", "isCompatibleWith", "isSealed", "is_a?", "isnull_anullnnotationnull_pnullresent", "isnull_anullnnotationnull_pnullresent?", "isnull_cnullompatiblenull_wnullith", "isnull_cnullompatiblenull_wnullith?", "isnull_snullealed", "isnull_snullealed?", "java", "java_annotation", "java_class", "java_implements", "java_kind_of?", "java_method", "java_name", "java_object", "java_object=", "java_package", "java_require", "java_send", "java_signature", "javax", "kind_of?", "marshal_dump", "marshal_load", "method", "methods", "nil?", "notify", "notifyAll", "notifynull_anullll", "object_id", "org", "private_methods", "protected_methods", "public_methods", "respond_to?", "send", "singleton_methods", "synchronized", "taint", "tainted?", "tap", "toString", "to_a", "to_enum", "to_java", "to_java_object", "to_s", "tonull_snulltring", "type", "untaint", "wait"] Whynull arenull therenull sonull manynull nullsnull?
        Hide
        Charles Oliver Nutter added a comment -

        FWIW, compare to running on Hotspot:

        #<Java::JavaLang::Package:0x1eca460>
        ["==", "===", "=~", "__id__", "__jcreate!", "__jsend!", "__send__", "annotationPresent", "annotation_present", "annotation_present?", "annotations", "class", "clone", "com", "compatibleWith", "compatible_with", "compatible_with?", "declaredAnnotations", "declared_annotations", "display", "dup", "enum_for", "eql?", "equal?", "equals", "equals?", "extend", "finalize", "freeze", "frozen?", "getAnnotation", "getAnnotations", "getClass", "getDeclaredAnnotations", "getImplementationTitle", "getImplementationVendor", "getImplementationVersion", "getName", "getPackageInfo", "getSpecificationTitle", "getSpecificationVendor", "getSpecificationVersion", "get_annotation", "get_annotations", "get_class", "get_declared_annotations", "get_implementation_title", "get_implementation_vendor", "get_implementation_version", "get_name", "get_package_info", "get_specification_title", "get_specification_vendor", "get_specification_version", "handle_different_imports", "hash", "hashCode", "hash_code", "id", "implementationTitle", "implementationVendor", "implementationVersion", "implementation_title", "implementation_vendor", "implementation_version", "include_class", "initialize", "inspect", "instance_eval", "instance_exec", "instance_of?", "instance_variable_defined?", "instance_variable_get", "instance_variable_set", "instance_variables", "isAnnotationPresent", "isCompatibleWith", "isSealed", "is_a?", "is_annotation_present", "is_annotation_present?", "is_compatible_with", "is_compatible_with?", "is_sealed", "is_sealed?", "java", "java_annotation", "java_class", "java_implements", "java_kind_of?", "java_method", "java_name", "java_object", "java_object=", "java_package", "java_require", "java_send", "java_signature", "javax", "kind_of?", "marshal_dump", "marshal_load", "method", "methods", "name", "nil?", "notify", "notifyAll", "notify_all", "object_id", "org", "packageInfo", "package_info", "private_methods", "protected_methods", "public_methods", "respond_to?", "sealed", "sealed?", "send", "singleton_methods", "specificationTitle", "specificationVendor", "specificationVersion", "specification_title", "specification_vendor", "specification_version", "synchronized", "taint", "tainted?", "tap", "toString", "to_a", "to_enum", "to_java", "to_java_object", "to_s", "to_string", "type", "untaint", "wait"]
        
        Show
        Charles Oliver Nutter added a comment - FWIW, compare to running on Hotspot: #<Java::JavaLang::Package:0x1eca460> ["==", "===", "=~", "__id__", "__jcreate!", "__jsend!", "__send__", "annotationPresent", "annotation_present", "annotation_present?", "annotations", "class", "clone", "com", "compatibleWith", "compatible_with", "compatible_with?", "declaredAnnotations", "declared_annotations", "display", "dup", "enum_for", "eql?", "equal?", "equals", "equals?", "extend", "finalize", "freeze", "frozen?", "getAnnotation", "getAnnotations", "getClass", "getDeclaredAnnotations", "getImplementationTitle", "getImplementationVendor", "getImplementationVersion", "getName", "getPackageInfo", "getSpecificationTitle", "getSpecificationVendor", "getSpecificationVersion", "get_annotation", "get_annotations", "get_class", "get_declared_annotations", "get_implementation_title", "get_implementation_vendor", "get_implementation_version", "get_name", "get_package_info", "get_specification_title", "get_specification_vendor", "get_specification_version", "handle_different_imports", "hash", "hashCode", "hash_code", "id", "implementationTitle", "implementationVendor", "implementationVersion", "implementation_title", "implementation_vendor", "implementation_version", "include_class", "initialize", "inspect", "instance_eval", "instance_exec", "instance_of?", "instance_variable_defined?", "instance_variable_get", "instance_variable_set", "instance_variables", "isAnnotationPresent", "isCompatibleWith", "isSealed", "is_a?", "is_annotation_present", "is_annotation_present?", "is_compatible_with", "is_compatible_with?", "is_sealed", "is_sealed?", "java", "java_annotation", "java_class", "java_implements", "java_kind_of?", "java_method", "java_name", "java_object", "java_object=", "java_package", "java_require", "java_send", "java_signature", "javax", "kind_of?", "marshal_dump", "marshal_load", "method", "methods", "name", "nil?", "notify", "notifyAll", "notify_all", "object_id", "org", "packageInfo", "package_info", "private_methods", "protected_methods", "public_methods", "respond_to?", "sealed", "sealed?", "send", "singleton_methods", "specificationTitle", "specificationVendor", "specificationVersion", "specification_title", "specification_vendor", "specification_version", "synchronized", "taint", "tainted?", "tap", "toString", "to_a", "to_enum", "to_java", "to_java_object", "to_s", "to_string", "type", "untaint", "wait"]
        Hide
        Charles Oliver Nutter added a comment -

        Ok, I see the problem. We match the Java name using this regexp:

        (([a-z0-9])([A-Z])|([A-Za-z0-9])([A-Z][a-z]))

        And then try to replaceAll using all groups like this:

        m.replaceAll("$2$4_$3$5")

        On OpenJDK, the unmatched $4 and $5 groups produce "" for this replaceAll, but on Android they produce null. Because methods like getName turn into getnull_nnullame, later checks for get_* fail, so we never map the short Ruby attr names.

        Fixing.

        Show
        Charles Oliver Nutter added a comment - Ok, I see the problem. We match the Java name using this regexp: (( [a-z0-9] )( [A-Z] )|( [A-Za-z0-9] )( [A-Z] [a-z] )) And then try to replaceAll using all groups like this: m.replaceAll("$2$4_$3$5") On OpenJDK, the unmatched $4 and $5 groups produce "" for this replaceAll, but on Android they produce null. Because methods like getName turn into getnull_nnullame, later checks for get_* fail, so we never map the short Ruby attr names. Fixing.
        Hide
        Charles Oliver Nutter added a comment -

        See also http://blog.headius.com/2011/03/differing-javautilregexmatcher.html

        commit c4aebe991c9d42b6970722d4a27e0dc884d06cbe
        Author: Charles Oliver Nutter <headius@headius.com>
        Date: Mon Mar 7 13:06:24 2011 -0600

        Fix JRUBY-5541: Problem with java_import on Android (Ruboto)

        Android was producing "null" for unmatching $ group variables in replaceAll, botching our conversion from camelCase to snake_case. Fixed by manually walking the matches and only replacing from groups that matched.

        Show
        Charles Oliver Nutter added a comment - See also http://blog.headius.com/2011/03/differing-javautilregexmatcher.html commit c4aebe991c9d42b6970722d4a27e0dc884d06cbe Author: Charles Oliver Nutter <headius@headius.com> Date: Mon Mar 7 13:06:24 2011 -0600 Fix JRUBY-5541 : Problem with java_import on Android (Ruboto) Android was producing "null" for unmatching $ group variables in replaceAll, botching our conversion from camelCase to snake_case. Fixed by manually walking the matches and only replacing from groups that matched.
        Charles Oliver Nutter made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Charles Oliver Nutter made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Scott Moyer
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: