Mark-<br><br>Thanks for the report!&nbsp; I&#39;ll look into this after I&#39;ve pushed the initial prototype to the openjdk project.<br><br>Regards,<br>Neal<br><br><div class="gmail_quote">On Mon, Jun 16, 2008 at 5:42 AM, Mark Mahieu &lt;<a href="mailto:mark@twistedbanana.demon.co.uk">mark@twistedbanana.demon.co.uk</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">There appears to be some interaction between closures and for-each loops which can cause incorrect line numbers in stack traces.<br>

<br>
A couple of examples:<br>
<br>
<br>
public class StackTraceWrongLine1 {<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public static void main(String[] args) {<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Stack trace indicates that the NPE occurs here:<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;String[] items = null;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Comment out this line, and the stack trace is fine<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{==&gt; void} notInvoked = {==&gt; items = args; };<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (String item : items) { }<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
}<br>
<br>
<br>
Exception in thread &quot;main&quot; java.lang.NullPointerException<br>
 &nbsp; &nbsp; &nbsp; &nbsp;at StackTraceWrongLine1.main(StackTraceWrongLine1.java:6)<br>
<br>
<br>
- - - - - - - -<br>
<br>
<br>
public class StackTraceWrongLine2 {<br>
 &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp;public static void main(String[] args) {<br>
<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Stack trace indicates that items.iterator() is called here:<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Iterable&lt;String&gt; items = {=&gt; throw new RuntimeException(); };<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (String item : items) { }<br>
 &nbsp; &nbsp; &nbsp; &nbsp;}<br>
}<br>
<br>
<br>
Exception in thread &quot;main&quot; java.lang.RuntimeException<br>
 &nbsp; &nbsp; &nbsp; &nbsp;at StackTraceWrongLine2$2.+invoke(StackTraceWrongLine2.java:6)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;at StackTraceWrongLine2$2.iterator(StackTraceWrongLine2.java:6)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;at StackTraceWrongLine2.main(StackTraceWrongLine2.java:6)<br>
<br>
<br>
<br>
Regards,<br><font color="#888888">
<br>
Mark<br>
<br>
</font></blockquote></div><br>