unrestricted closures

Neal Gafter neal at gafter.com
Sun Nov 16 10:10:23 PST 2008


All of the examples I've seen where you could get into this kind of
"trouble" involve making locally obvious errors.  The exception points you
precisely to where you made the mistake, too.  In this case the temp()
method clearly constructs a closure that should not escape its scope (it has
a return in it) yet is assigned to a static variable.

On Sat, Nov 15, 2008 at 8:26 PM, Vladimir Kirichenko <
vladimir.kirichenko at gmail.com> wrote:

> More accurate problematic example:
>
> public class Test {
>
>         static {int ==> int} temp;
>
>         static void term() {
>                 {int==>int} t = {int i ==> if (i > 5) return; i};
>                 temp = t;
>
>         }
>
>         static int m(int i, {int ==> int} f) {
>                 int y = f.invoke(i + 5);
>                 return y;
>         }
>
>         static int caller(int i) {
>                 return m(i,temp);
>         }
>         public static void main(String... args) {
>                 term();
>                 int x = caller(5);
>                 System.out.println(x);
>         }
> }
>
> Exception in thread "main" java.lang.UnmatchedTransfer: late transfer
>         at java.lang.Jump.transfer(Jump.java:48)
>         at test.Test$3.+invoke(Test.java:12)
>         at test.Test$3.invoke(Test.java:12)
>         at test.Test.m(Test.java:18)
>         at test.Test.caller(Test.java:23)
>         at test.Test.main(Test.java:29)
> Caused by: test.Test$2
>
> And it's not the bug - code like this could appear in different cases,
> it just shows what unrestricted closures passing could raise.
>
>
> --
> Best Regards,
> Vladimir Kirichenko
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.4-svn0 (GNU/Linux)
> Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
>
> iD8DBQFJH5KD2HRuYYrY4NQRAlR8AJ0dClhBvckn4NMiF14oBjTIijZ6BACdFgF3
> Zd8fWLKRU1XGF0ob9vEmTqo=
> =uZP4
> -----END PGP SIGNATURE-----
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/closures-dev/attachments/20081116/d63457a0/attachment.html 


More information about the closures-dev mailing list