1

Follow these steps to reproduce:

  1. Create a '.jsh' script with some kind of error(missing import, syntax error etc)

  2. open a jshell

  3. /open the erroneous script

  4. The /open command will finish silently.

  5. The elements declared in that script won't be in the current namespace.

Is there a way to force jshell to spit out the error and it's location in the script if an erroneous script is loaded? Setting the feedback level to verbose doesn't change anything.

saga
  • 1,933
  • 2
  • 17
  • 44

2 Answers2

0

jshell imports a lot of classes on startup and any subsequent snippet (even if load from file) can use them, SO few of the missing imports can be taken care here. --no-startup can be used to disable this behavior.

Fairoz
  • 1,616
  • 13
  • 16
0

This problem seems to be related to the „forward references“ feature of JShell: When a method or type declaration refers to a still undefined variable or method, JShell checks only for syntactical correctness and delays the compilation of the method resp. type. In interactive mode it prints a helpful message like „method x refers to undefined method y and can’t be invoked until method y is defined“. But while a startup script runs, that message is not printed and in many cases the script executes nothing, which is very confusing. I have not found a way to enable the printing of that message.

Hypercritical persons might say that this bug/feature renders JShell useless for „real“ scripting applications, and I tend to agree.

I propose that the „forward references“ feature be disabled during the execution of scripts. In order to make forward references still possible, the entire script should be considered ONE big snippet. That would also eliminate the problem with line-numbers-per-snippet which makes no sense at all with code parsed from scripts.

Arno Unkrig
  • 181
  • 2
  • 5