Local execution mode and local variables

Robert Field robert.field at oracle.com
Thu Feb 22 20:56:48 UTC 2018


Hi Christian,

Thanks for your question.

Let me start by saying local execution mode is not the intended mode of use.

Interesting case.

Local execution mode cannot do redefinition, wherein a class is updated 
in-place, so updates are done by replacing the class, when replaced 
instances of the old class are lost, hence the null you are seeing.

Class A is tagged for update because of a false-positive matching the 
name of the two variables.  Usually false positives are harmless because 
the class is redefined with itself, but, per the above, local execution 
loses the instance.

I am submitting a bug because there are several options for handling 
this better:

       https://bugs.openjdk.java.net/browse/JDK-8198573

The false positive could be detected in the compiler tree or bytecode.

More importantly, in a case requiring an actual replace in normal 
execution mode the instance is lost which is surprising.  Instance 
recreation could be examined.  At a minimum, the replacement event 
should be exposed to JShell tool users.

Thanks,
Robert


On 02/22/18 06:54, Christian Stein wrote:
> Hi,
>
> The following script leads to unexpected loss
> of an object reference when jshell is launched
> with option "--execution local":
>
>    class A { int a() { int error = 0; return error; } }
>    A a = new A()
>    System.out.println("before error | a = " + a)
>    int error = 4711
>    System.out.println("after error  | a = " + a)
>    System.out.println("           error = " + error)
>    /exit
>
> Normal mode:
>
> jshell execution-local-fails.jsh
>
> before error | a = REPL.$JShell$11$A at 7d9d1a19
> after error  | a = REPL.$JShell$11$A at 7d9d1a19
>             error = 4711
>
>
> Local mode:
>
> jshell --execution local execution-local-fails.jsh
>
> before error | a = REPL.$JShell$11$A at 25df00a0
> after error  | a = null
>             error = 4711
>
>
>
> Is this behaviour expected?
>
> Tested on 9.0.1, 9.0.4 and current 10+44.
>
> Work around in "local mode": use a different
> name for the local variable.
>
> Cheers,
> Christian



More information about the kulla-dev mailing list