Skip to content

.delete_if blocks allow deleting same object from array twich #7976

@HoneyryderChuck

Description

@HoneyryderChuck

Environment Information

jruby 9.4.2.0 (3.1.0) 2023-03-08 90d2913 Java HotSpot(TM) 64-Bit Server VM 25.333-b02 on 1.8.0_333-b02 +jit [x86_64-darwin]

Expected Behavior

given the following example:

proc = -> { puts "bang" }
a = [proc]
a.delete_if { |p| a.delete(p); true }
puts a.size

I'd expect the output to be "0", as in CRuby, because you can delete an element only once.

Actual Behavior

running the snippet with jruby outputs "-1", which in other scenarios cascades into a NegativeArrayException:

puts a                                                                  
org.jruby.runtime.builtin.IRubyObject.array(IRubyObject.java:59): Java::JavaLang::NegativeArraySizeException                                                                                                
        from org.jruby.RubyArray.toJavaArray(RubyArray.java:515)  
        from org.jruby.specialized.RubyArrayOneObject.toJavaArray(RubyArrayOneObject.java:250)
        from org.jruby.RubyArray.toJavaArrayMaybeUnsafe(RubyArray.java:546)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions