From naokikishida at gmail.com Thu Feb 20 08:37:05 2020 From: naokikishida at gmail.com (kishida naoki) Date: Thu, 20 Feb 2020 17:37:05 +0900 Subject: Can't use `java.util.List` object after importing `java.awt.List` Message-ID: We can' t use `java.util.List` object after importing `java.awt.List` I mean that JShell behaves strangely when we have two same named classes from different packages. The below is run on JDK 14 ea 36 ``` $ 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"); | ^----------^ ``` -- Naoki Kishida From sundararajan.athijegannathan at oracle.com Thu Feb 20 09:02:21 2020 From: sundararajan.athijegannathan at oracle.com (sundararajan.athijegannathan at oracle.com) Date: Thu, 20 Feb 2020 14:32:21 +0530 Subject: Can't use `java.util.List` object after importing `java.awt.List` In-Reply-To: References: Message-ID: Hi, Thanks for reporting this issue. I filed a bug -> https://bugs.openjdk.java.net/browse/JDK-8239536 PS. Reproduced with the latest jdk repo as well. -Sundar On 20/02/20 2:07 pm, kishida naoki wrote: > We can' t use `java.util.List` object after importing `java.awt.List` > I mean that JShell behaves strangely when we have two same named classes > from different packages. > > The below is run on JDK 14 ea 36 > > ``` > $ 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"); > | ^----------^ > ``` > From naokikishida at gmail.com Thu Feb 20 09:10:55 2020 From: naokikishida at gmail.com (kishida naoki) Date: Thu, 20 Feb 2020 18:10:55 +0900 Subject: Can't use `java.util.List` object after importing `java.awt.List` In-Reply-To: References: Message-ID: Hi, Thank you for filing. -- Naoki Kishida 2020?2?20?(?) 18:02 : > Hi, > > Thanks for reporting this issue. I filed a bug -> > https://bugs.openjdk.java.net/browse/JDK-8239536 > > PS. Reproduced with the latest jdk repo as well. > > -Sundar > > On 20/02/20 2:07 pm, kishida naoki wrote: > > We can' t use `java.util.List` object after importing `java.awt.List` > > I mean that JShell behaves strangely when we have two same named classes > > from different packages. > > > > The below is run on JDK 14 ea 36 > > > > ``` > > $ 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"); > > | ^----------^ > > ``` > > > From jan.lahoda at oracle.com Thu Feb 20 19:33:14 2020 From: jan.lahoda at oracle.com (Jan Lahoda) Date: Thu, 20 Feb 2020 20:33:14 +0100 Subject: RFR: JDK-8239536: Can't use `java.util.List` object after importing `java.awt.List` Message-ID: <7897b679-0d7e-44f8-4fb9-65e16cdb0115@oracle.com> 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 From robert.field at oracle.com Thu Feb 20 20:04:57 2020 From: robert.field at oracle.com (Robert Field) Date: Thu, 20 Feb 2020 12:04:57 -0800 Subject: RFR: JDK-8239536: Can't use `java.util.List` object after importing `java.awt.List` In-Reply-To: <7897b679-0d7e-44f8-4fb9-65e16cdb0115@oracle.com> References: <7897b679-0d7e-44f8-4fb9-65e16cdb0115@oracle.com> Message-ID: Fix looks good. I'd add this final check from the transcript in the RFR: jshell> var b = java.util.List.of("bb") b ==> [bb] To the test. No need to re-review. -Robert On 2/20/20 11:33 AM, Jan Lahoda wrote: > > jshell> var b = java.util.List.of("bb") > b ==> [bb]