jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • JRuby
  • JRUBY-3224

Array#to_java with java object reference doesn't carry over object identity

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1.4, JRuby 1.1.5
  • Fix Version/s: JRuby 1.2
  • Component/s: Java Integration
  • Labels:
    None
  • Testcase included:
    yes

Description

http://archive.codehaus.org/lists/org.codehaus.jruby.user/msg/33A51D84-F7F0-4E47-BF52-50E07889E332@aps.org

Maybe this is necessary, but it can have non-intuitive results when testing because stubbed behavior disappears on objects that are passed into java methods in java arrays.

e.g the spec below began failing for me after 1.1.3 since the stubbed stuff is defined on the java objects directly.

def new_fig_details(values)
..
fig.stub!(:finalPercent).and_return(values[:percent]) #finalPercent is read only method
..
fig
end
...
it "should be able to handle multiple figures" do
fig = new_fig_details(:num => 1, :width => 12, :height => 11,
:picas => 12, :percent => 1.00, :col_size => 1.0, :total => 11)

fig2 = new_fig_details(:num => 2, :width => 11, :height => 12,
:picas => 13, :percent => 2.00, :col_size => 3.0, :total => 16)

@data.figureDetails = [fig, fig2].to_java(LengthCheck::FigureDetail)

expected =
" 1 1 12 11 12 1.00 1.0 11\n" +
" 2 2 11 12 13 2.00 3.0 16\n"

@substitutions.do_figure_substitutions!(@text)

@text.should == expected
end

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    spec-patch.txt
    08/Dec/08 3:52 PM
    0.8 kB
    Lenny Marks

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Lenny Marks added a comment - 08/Dec/08 3:54 PM

The workaround is to stub behavior directly on the java array elements.

ex.
@data.figureDetails = [fig, fig2].to_java(LengthCheck::FigureDetail)

@data.figureDetails[0].stub!(:finalPercent).and_return(1.00)
@data.figureDetails[1].stub!(:finalPercent).and_return(2.00)

Show
Lenny Marks added a comment - 08/Dec/08 3:54 PM The workaround is to stub behavior directly on the java array elements. ex. @data.figureDetails = [fig, fig2].to_java(LengthCheck::FigureDetail) @data.figureDetails[0].stub!(:finalPercent).and_return(1.00) @data.figureDetails[1].stub!(:finalPercent).and_return(2.00)
Hide
Permalink
Charles Oliver Nutter added a comment - 16/Feb/09 11:47 PM

I fixed this not by making sure that they're the same objects in reality, but by making all Java object wrappers override equal? to do a reference equality check. It's rather surprising this did not exist before, but it made your specs pass correctly and it's the right thing to do. Once we collapse the two layers of wrapping we do right now (yes, we do two layers of wrapping...it's awful), this will become less of an issue.

Show
Charles Oliver Nutter added a comment - 16/Feb/09 11:47 PM I fixed this not by making sure that they're the same objects in reality, but by making all Java object wrappers override equal? to do a reference equality check. It's rather surprising this did not exist before, but it made your specs pass correctly and it's the right thing to do. Once we collapse the two layers of wrapping we do right now (yes, we do two layers of wrapping...it's awful), this will become less of an issue.

People

  • Assignee:
    Charles Oliver Nutter
    Reporter:
    Lenny Marks
Vote (0)
Watch (1)

Dates

  • Created:
    08/Dec/08 3:52 PM
    Updated:
    21/Mar/09 1:14 PM
    Resolved:
    16/Feb/09 11:47 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.