History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-2561
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Critical Critical
Assignee: Thomas E Enebo
Reporter: Evan David Light
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
JRuby

JavaField.set_value(foo, nil) breaks

Created: 23/May/08 11:25 AM   Updated: Monday 07:13 PM
Component/s: Java Integration
Affects Version/s: JRuby 1.1+
Fix Version/s: JRuby 1.1.4

Time Tracking:
Not Specified

File Attachments: 1. File 2561_patch_and_spec.tgz (5 kb)



 Description  « Hide
JAVA:
public class PrivateField {
  private String strField;
}

JRUBY:

import 'PrivateField'
p = PrivateField.new
f = PrivateField.java_class.declared_field 'strField'
f.accessible = true

# This just causes an Exception because 'nil' isn't a JavaObject (set_value doesn't do any conversion)
f.set_value(p.java_object, nil)

# This, however, causes an NPE
f.set_value(p.java_object, Java.ruby_to_java(nil))


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Evan David Light - 23/May/08 03:34 PM
Patch attached.

Problem appeared to be in JavaUtil.java:445

parameterType.isPrimitive == false, evidently, when a wrapped 'nil' is passed as the argument. Therefore this fell through to line 477 causing an NPE. Added an else clause that returns null as was intended. Specs now SELECTIVELY pass.

Note about the attached specs: they test conditions that work now (i.e., passing in a JavaObject) and conditions that SHOULD work (i.e., passing in an object that responds_to? :java_object). Tests field mutators for private, protected and public. Needs tests for getters.


Charles Oliver Nutter - 25/May/08 12:05 AM
Specs and fix committed in r6783. I had to clean up the specs a bit, so have a look and make sure they're still testing what you intended. Several would not pass as written, so I'm not sure if they were just overlooked or if they tested behavior you've fixed elsewhere...

Evan David Light - 25/May/08 12:32 AM
Several of the specs are supposed to fail in JRuby trunk. The intent was to spec the fox but also spec that JavaField should automatically wrap/unwrap Ruby classes (which it does not currently hence the failures).

Evan David Light - 25/May/08 01:37 AM
Note to self: don't comment in JIRA from iPhone.

I see the confusion. My words in the specs didn't quite match my intent. I mention that it should accept a Ruby value. What I also meant, but didn't say, was that it should accept a Ruby object upon which to set the Ruby value.

Right now, JavaField#set_value breaks when a Ruby object is passed as the object param – which is why you have the @obj.java_object code in there. It should also work for @obj as well.


Charles Oliver Nutter - 25/May/08 02:32 PM
Ok, I've expanded and cleaned up the specs to include all four cases across four visibilities: JavaField setting an X field with a Y value: ruby/ruby, ruby/java, java/ruby, java/java. Since we still can't set the field using nil (nor any other Ruby object) this will remain open and I'm bumping it to 1.2.

Thomas E Enebo - 25/Aug/08 07:13 PM
Fixed in commit 7533 on trunk. This fixes the original reported problem and fixes description of bug.