Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8198573

JShell: class replace loses instances

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 11
    • 9, 10, 11
    • tools
    • None
    • b03

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

      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:

      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.

      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@7d9d1a19
      > after error | a = REPL.$JShell$11$A@7d9d1a19
      > error = 4711
      >
      >
      > Local mode:
      >
      > jshell --execution local execution-local-fails.jsh
      >
      > before error | a = REPL.$JShell$11$A@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

            rfield Robert Field (Inactive)
            rfield Robert Field (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: