RFR: JDK-8239536: Can't use `java.util.List` object after importing `java.awt.List`

Jan Lahoda jan.lahoda at oracle.com
Thu Feb 20 19:33:14 UTC 2020


Hi,

Here:
https://mail.openjdk.java.net/pipermail/kulla-dev/2020-February/002482.html

The following JShell session was reported:

```
$ jshell
|  Welcome to JShell -- Version 14
|  For an introduction type: /help intro

jshell> var a = List.of("aa")
a ==> [aa]

jshell> a
a ==> [aa]

jshell> import java.awt.List

jshell> a
|  Error:
|  cannot find symbol
|    symbol:   variable a
|  a
|  ^

jshell> var b = java.util.List.of("bb")
|  Error:
|  type java.awt.List does not take parameters
|  var b = java.util.List.of("bb");
|  ^----------^
```

There seem to be too bugs here:
-doing import java.awt.List will re-evaluate the first snippet (which is 
expected, I believe); the re-evaluation will fail, but JShell using the 
normal/default feedback will say nothing about that failure. I believe 
it would be better if it told user that updating the snippet failed

-for 'var b = java.util.List.of("bb")', the engine will generate a field 
for "b", and use "List" as the type of the field - but given the most 
up-to-date import, the List will be interpreted as java.awt.List, and 
hence the snippet will fail. I believe the engine should use 
fully-qualified names for the synthetic field types.

A similar session with the proposed patch:
```
|  Welcome to JShell -- Version 15-internal
|  For an introduction type: /help intro

jshell> var a = List.of("aa")
a ==> [aa]

jshell> a
a ==> [aa]

jshell> import java.awt.List
|    update replaced variable a which cannot be referenced until this 
error is corrected:
|      cannot find symbol
|        symbol:   method of(java.lang.String)
|      var a = List.of("aa");
|              ^-----^

jshell> var b = java.util.List.of("bb")
b ==> [bb]

jshell> b
b ==> [bb]
```

Proposed webrev: http://cr.openjdk.java.net/~jlahoda/8239536/webrev.00/
JBS: https://bugs.openjdk.java.net/browse/JDK-8239536

How does this look?

Thanks,
     Jan


More information about the kulla-dev mailing list