All of the examples I&#39;ve seen where you could get into this kind of &quot;trouble&quot; involve making locally obvious errors.&nbsp; The exception points you precisely to where you made the mistake, too.&nbsp; 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.<br>
<br><div class="gmail_quote">On Sat, Nov 15, 2008 at 8:26 PM, Vladimir Kirichenko <span dir="ltr">&lt;<a href="mailto:vladimir.kirichenko@gmail.com">vladimir.kirichenko@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
More accurate problematic example:<br>
<br>
public class Test {<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; static {int ==&gt; int} temp;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; static void term() {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {int==&gt;int} t = {int i ==&gt; if (i &gt; 5) return; i};<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp = t;<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; }<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; static int m(int i, {int ==&gt; int} f) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int y = f.invoke(i + 5);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return y;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; }<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; static int caller(int i) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return m(i,temp);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; }<br>
 &nbsp; &nbsp; &nbsp; &nbsp; public static void main(String... args) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; term();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int x = caller(5);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; System.out.println(x);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; }<br>
}<br>
<br>
Exception in thread &quot;main&quot; java.lang.UnmatchedTransfer: late transfer<br>
 &nbsp; &nbsp; &nbsp; &nbsp; at java.lang.Jump.transfer(Jump.java:48)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; at test.Test$3.+invoke(Test.java:12)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; at test.Test$3.invoke(Test.java:12)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; at test.Test.m(Test.java:18)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; at test.Test.caller(Test.java:23)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; at test.Test.main(Test.java:29)<br>
Caused by: test.Test$2<br>
<br>
And it&#39;s not the bug - code like this could appear in different cases,<br>
it just shows what unrestricted closures passing could raise.<br>
<br>
<br>
-- <br>
Best Regards,<br><font color="#888888">
Vladimir Kirichenko<br>
</font><br>-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v2.0.4-svn0 (GNU/Linux)<br>
Comment: Using GnuPG with SUSE - <a href="http://enigmail.mozdev.org" target="_blank">http://enigmail.mozdev.org</a><br>
<br>
iD8DBQFJH5KD2HRuYYrY4NQRAlR8AJ0dClhBvckn4NMiF14oBjTIijZ6BACdFgF3<br>
Zd8fWLKRU1XGF0ob9vEmTqo=<br>
=uZP4<br>
-----END PGP SIGNATURE-----<br>
<br>
<br></blockquote></div><br>