<div dir="ltr"><div>Hi,</div><div><br></div><div>I got reported a "fun" issue on jbang <a href="https://github.com/jbangdev/jbang/issues/2072">https://github.com/jbangdev/jbang/issues/2072</a> which boils down to the following calls to jshell behaving differently for reasons I can't really explain.<br><br>I've boiled it down to what *looks* like a bug/change of behaviour and wondering if intentional or not:<br><br>Take this code and put in test.jsh (you can also manually type it but whats the fun in that):</div><div><br></div><div>String[] args = { "arg1", "arg2" }<br>import module java.base;<br>import static java.util.stream.Collectors.*;<br>System.out.println(args.length);<br>/exit<br></div><div><br></div><div>now run this using:<br><br>jshell --enable-preview -J--enable-preview --startup=DEFAULT --execution=local test.jsh<br><br>And you will get printed:</div><div>2<br><br>the correct length of the args array.<br><br>Now change it to:<br><br class="gmail-Apple-interchange-newline">String[] args = { "arg1", "arg2" }<br>import static java.util.stream.Collectors.*;<br>import module java.base;<br>System.out.println(args.length);<br>/exit<br><br>Note, the import order is changed.<br><br>Now you get:<br><br>WARNING: Using incubator modules: jdk.incubator.vector<br>Exception java.lang.NullPointerException: Cannot read the array length because "REPL.$JShell$11B.args" is null<br>      at (#4:1)</div><div><br>question is why is this happening?<br><br>Also, if you remove `--startup=DEFAULT` OR `--execution=local` the behaviour stays the same and 2 is printed in all cases.<br><br>Bug or expected ? <br><br>Hope it all makes sense :)<br><br></div>--<br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>/max<br></div><a href="https://about.me/maxandersen" target="_blank">https://about.me/maxandersen</a><br></div></div></div>