Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling break in block passed to java interface terminates application #963

Closed
MagnusEngstrom opened this issue Aug 20, 2013 · 1 comment

Comments

@MagnusEngstrom
Copy link

The whole application terminates immediately without printing an error in JRuby 1.7.3 and 1.7.4 when using break as shown below. This works fine in JRuby 1.6.7.

FooListener.java

public interface FooListener
{
        void modifyText(int x);
}

Test.java

public class Test
{
        private FooListener foo;
        void addFooListener( FooListener foo_ )
        {
                foo = foo_;
        }
        void prod()
        {
                System.out.println( "--before--" );
                foo.modifyText(32);
                System.out.println( "--after--" );
        }
}

test.rb

require 'java'
$CLASSPATH << '.'

a = Java::Test.new
a.addFooListener { |x|
        puts x
        break
}
a.prod
puts "before exit"

On 1.7.3 and .4, output is:

--before--
32

and on 1.6.7:

--before--
32
--after--
before exit

@kares
Copy link
Member

kares commented Jul 28, 2016

believe break was never (officially) a way to finish a block/proc early ... silently. looking at MRI's :

2.3.1 :001 >     proc = Proc.new { puts "HELLO"; break; puts "AGAIN" }
 => #<Proc:0x000000013f9958@(irb):1> 
2.3.1 :002 >     proc.call; puts "proc called"
HELLO
LocalJumpError: break from proc-closure
    from (irb):1:in `block in irb_binding'
    from (irb):2
    from /opt/local/rvm/rubies/ruby-2.3.1/bin/irb:11:in `<main>'
2.3.1 :003 > exit

... the "new" behaviour seems as an improvement - breaks should not be ignored silently.

@kares kares closed this as completed Jul 28, 2016
@kares kares added this to the Invalid or Duplicate milestone Jul 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants