NPE in isDuckTypeConvertible
----------------------------

                 Key: JRUBY-2236
                 URL: http://jira.codehaus.org/browse/JRUBY-2236
             Project: JRuby
          Issue Type: Bug
          Components: Java Integration
            Reporter: Anders Bengtsson


Hi,

I'm getting a NPE in the Java integration under some circumstances, when I have 
Java objects inside a Hash and then access the Hash from Java as a Map. It's in 
both RC2 and trunk, this is the stacktrace from trunk:

{noformat}
java.lang.NullPointerException
        at 
org.jruby.javasupport.JavaUtil.isDuckTypeConvertable(JavaUtil.java:501)
        at org.jruby.javasupport.JavaUtil.convertArgument(JavaUtil.java:477)
        at org.jruby.javasupport.JavaUtil.convertRubyToJava(JavaUtil.java:181)
        at org.jruby.javasupport.JavaUtil.convertRubyToJava(JavaUtil.java:66)
        at org.jruby.RubyHash.get(RubyHash.java:1369)
        at 
com.xyz.ProductDescription.descriptionForCountry(ProductDescription.java:125)
...
{noformat}

It's calling convertRubyToJava with a null javaClass, and then not dealing with 
it. The below change fixes it for me, but I doubt that it's the "real" solution:

{noformat}
Index: src/org/jruby/javasupport/JavaUtil.java
===================================================================
--- src/org/jruby/javasupport/JavaUtil.java     (revision 6117)
+++ src/org/jruby/javasupport/JavaUtil.java     (arbetskopia)
@@ -177,7 +177,9 @@
 
         if (rubyObject instanceof JavaObject) {
             Object value =  ((JavaObject) rubyObject).getValue();
-            
+           if (javaClass == null) {
+               javaClass = rubyObject.getJavaClass();
+           }
             return convertArgument(value, javaClass);
             
         } else if (javaClass == Object.class || javaClass == null) {
{noformat}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to