Skip Menu |

This queue is for tickets about the Inline-Java CPAN distribution.

Report information
The Basics
Id: 21176
Status: resolved
Priority: 0/
Queue: Inline-Java

People
Owner: patl [...] cpan.org
Requestors: artem [...] bizlink.ru
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.51
Fixed in: (no value)



Subject: Undoccumented $@ (eval/die) behaviour.
Had a chance to use Inline::Java::Handle recently. First thing: it worked! : ) But, i've spent a lot of time trying to understand, why some of my errors aren't propagated. I discovered, that when using Inline::Java::Handle, the error message - $@ - is cleared when the handlers are closed. This is disastrous, becouse by default they are closed automatically upon an exit from the subroutine, and it renders any exceptions inside the subroutine invisible. This property should be at least docummented, becouse it is then possible to workaround. Example code: sub foo { local *STDIN = new Inline::Java::Handle($in); local *STDOUT = new Inline::Java::Handle($out); die "bar"; } eval {foo();}; report($@) if $@; The workaround: sub foo { local *STDIN = new Inline::Java::Handle($in); local *STDOUT = new Inline::Java::Handle($out); eval { die "bar"; }; my $err = $@; close(*STDOUT); close(*STDIN); die $err if $err; } eval { foo(); }; report($@) if $@;
Subject: Re: [rt.cpan.org #21176] Undoccumented $@ (eval/die) behaviour.
Date: Fri, 25 Aug 2006 14:35:34 -0400
To: bug-Inline-Java [...] rt.cpan.org
From: "Patrick LeBoutillier" <patrick.leboutillier [...] gmail.com>
Hi, That's really a bug. Can you help me out in fixing it? Here is a patch you could try: Index: Java/Handle.pm =================================================================== RCS file: /cvsroot/inline-java/Inline-Java/Java/Handle.pm,v retrieving revision 1.6 diff -r1.6 Handle.pm 118c118,119 < my $ret = undef ; --- Show quoted text
> my $ret = undef ; > local $@ ;
Cheers, Patrick On 8/25/06, artem@bizlink.ru via RT <bug-Inline-Java@rt.cpan.org> wrote: Show quoted text
> > Fri Aug 25 03:16:34 2006: Request 21176 was acted upon. > Transaction: Ticket created by artem@bizlink.ru > Queue: Inline-Java > Subject: Undoccumented $@ (eval/die) behaviour. > Broken in: 0.51 > Severity: Important > Owner: Nobody > Requestors: artem@bizlink.ru > Status: new > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=21176 > > > > Had a chance to use Inline::Java::Handle recently. > First thing: it worked! : ) > But, i've spent a lot of time trying to understand, why some of my > errors aren't propagated. I discovered, that when using > Inline::Java::Handle, the error message - $@ - is cleared when the > handlers are closed. This is disastrous, becouse by default they are > closed automatically upon an exit from the subroutine, and it renders > any exceptions inside the subroutine invisible. This property should be > at least docummented, becouse it is then possible to workaround. > > Example code: > > sub foo { > local *STDIN = new Inline::Java::Handle($in); > local *STDOUT = new Inline::Java::Handle($out); > die "bar"; > } > eval {foo();}; > report($@) if $@; > > The workaround: > > sub foo { > local *STDIN = new Inline::Java::Handle($in); > local *STDOUT = new Inline::Java::Handle($out); > eval { die "bar"; }; > my $err = $@; > close(*STDOUT); > close(*STDIN); > die $err if $err; > } > eval { foo(); }; > report($@) if $@; > >
-- ===================== Patrick LeBoutillier Laval, Québec, Canada
Subject: Re: [rt.cpan.org #21176] Undoccumented $@ (eval/die) behaviour.
Date: Fri, 25 Aug 2006 23:13:04 +0400
To: bug-Inline-Java [...] rt.cpan.org
From: Artem Gr <artem [...] bizlink.ru>
Yeah, it seems to fix the issue. Testcase attached. Patrick LeBoutillier via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=21176 > > > Hi, > > That's really a bug. Can you help me out in fixing it? > > Here is a patch you could try: > > Index: Java/Handle.pm > =================================================================== > RCS file: /cvsroot/inline-java/Inline-Java/Java/Handle.pm,v > retrieving revision 1.6 > diff -r1.6 Handle.pm > 118c118,119 > < my $ret = undef ; > --- >
>> my $ret = undef ; >> local $@ ; >>
> > > Cheers, > > Patrick > > > > On 8/25/06, artem@bizlink.ru via RT <bug-Inline-Java@rt.cpan.org> wrote: >
>> Fri Aug 25 03:16:34 2006: Request 21176 was acted upon. >> Transaction: Ticket created by artem@bizlink.ru >> Queue: Inline-Java >> Subject: Undoccumented $@ (eval/die) behaviour. >> Broken in: 0.51 >> Severity: Important >> Owner: Nobody >> Requestors: artem@bizlink.ru >> Status: new >> Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=21176 > >> >> >> Had a chance to use Inline::Java::Handle recently. >> First thing: it worked! : ) >> But, i've spent a lot of time trying to understand, why some of my >> errors aren't propagated. I discovered, that when using >> Inline::Java::Handle, the error message - $@ - is cleared when the >> handlers are closed. This is disastrous, becouse by default they are >> closed automatically upon an exit from the subroutine, and it renders >> any exceptions inside the subroutine invisible. This property should be >> at least docummented, becouse it is then possible to workaround. >> >> Example code: >> >> sub foo { >> local *STDIN = new Inline::Java::Handle($in); >> local *STDOUT = new Inline::Java::Handle($out); >> die "bar"; >> } >> eval {foo();}; >> report($@) if $@; >> >> The workaround: >> >> sub foo { >> local *STDIN = new Inline::Java::Handle($in); >> local *STDOUT = new Inline::Java::Handle($out); >> eval { die "bar"; }; >> my $err = $@; >> close(*STDOUT); >> close(*STDIN); >> die $err if $err; >> } >> eval { foo(); }; >> report($@) if $@; >> >> >>
> > >
#!/usr/bin/perl use Inline ( Java => ' public class Foo { public java.io.InputStream foo() { return new java.io.ByteArrayInputStream("foo".getBytes()); } }' ); sub bar { my $foo = new Foo(); local *FH = new Inline::Java::Handle($foo->foo()); die "okay\n"; } my $got = eval { bar(); }; warn() if $@; print "Error!\n" if !$@;
From: artem [...] bizlink.ru
And thanks for the patch. : )
Subject: Re: [rt.cpan.org #21176] Undoccumented $@ (eval/die) behaviour.
Date: Fri, 25 Aug 2006 15:36:59 -0400
To: bug-Inline-Java [...] rt.cpan.org
From: "Patrick LeBoutillier" <patrick.leboutillier [...] gmail.com>
On 8/25/06, artem@bizlink.ru via RT <bug-Inline-Java@rt.cpan.org> wrote: Show quoted text
> > Queue: Inline-Java > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=21176 > > > And thanks for the patch. : ) >
No problem. I have also spotted quite a few other places where $@ should probably be localized. I'll work on that and include it in the next release. Patrick -- ===================== Patrick LeBoutillier Laval, Québec, Canada
$@ now localized in whe nused in DESTROY. Will be available in 0.52