JDK-8211694 : JShell: Redeclared variable should be reset
  • Type: Bug
  • Component: tools
  • Sub-Component: jshell
  • Affected Version: 9,10,11,12
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2018-10-03
  • Updated: 2020-12-10
  • Resolved: 2018-10-25
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 12
11.0.11-oracleFixed 12 b18Fixed
Description
A DESCRIPTION OF THE PROBLEM :
The result of line 13 of the test of the redeclared variable ������a������ that previously contained a non-null value and compare against the results of lines 4 and 19.
 
My current thinking is that lines 10 and 16 are both setting a to null, so the instanceof test on subsequent lines (13 and 19) should evaluate to false in both cases


1. jshell> Integer a;
2. a ==> null
3.
4. jshell> a instanceof Integer;
5. $2 ==> false
6.
7. jshell> a = 1;
8. a ==> 1
9.
10. jshell> Integer a;
11. a ==> null
12.
13. jshell> a instanceof Integer;
14. $5 ==> true
15.
16. jshell> a = null;
17. a ==> null
18.
19. jshell> a instanceof Integer;
20. $7 ==> false


FREQUENCY : always



Comments
Fix Request (11u) This fixes the surprising bug in jshell, and provides grounds for clean JDK-8223688 backport. Patch applies cleanly to 11u, new test fails without the patch, passes with it. Additional tier{1,2} and jdk/jshell testing passes.
04-08-2020

Sent for review -- Please review --- Bug: https://bugs.openjdk.java.net/browse/JDK-8211694 Webrev: http://cr.openjdk.java.net/~rfield/8211694v0.webrev/ See query to kulla-dev: http://mail.openjdk.java.net/pipermail/kulla-dev/2018-October/002316.html Thanks, Robert
25-10-2018

Either redeclaring a variable should not reset it (the intended behavior) and the value of the redeclare should be the current value (error). Or redeclaring should reset it (probably more rational behavior) (error). Either way there is an error. Given that a redeclare to a different type resets and the displayed value is the reset value (currently always). The correct behavior would be to reset on redeclare. Current behavior --- jshell> Integer a a ==> null jshell> a a ==> null jshell> a instanceof Integer $3 ==> false jshell> a = 1 a ==> 1 jshell> a a ==> 1 jshell> Integer a a ==> null jshell> a a ==> 1
10-10-2018

Reported behavior is same in all JDK 9, 10, 11 and latest 12-ea+13. When reference variable's value is null after re-declaration, it should not show as instance of some specific type.
04-10-2018