RFR: 8327512: JShell does not work correctly when a class named Object or Throwable is defined

Jan Lahoda jlahoda at openjdk.org
Thu Mar 14 10:31:55 UTC 2024


When JShell wraps the user's snippets with additional code to make the standalone compilable units, it uses simple names to refer to `Object`, `Throwable` or `SuppressWarnings` in some cases. These may interact with user-defined class of the same names, leading to error while running the next snippet. E.g.:

jshell> class Object{}
|  created class Object

jshell> 1
|  Error:
|  incompatible types: int cannot be converted to Object
|  1
|  ^


The proposal here is to use qualified names when creating the snippet wrappers, and to more carefully produce simple names when analyzing expressions (fully qualified names should be used when a class with the same simple name has been introduced in a snippet).

-------------

Commit messages:
 - 8327512: JShell does not work correctly when a class named Object or Throwable is defined

Changes: https://git.openjdk.org/jdk/pull/18295/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18295&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8327512
  Stats: 82 lines in 6 files changed: 74 ins; 0 del; 8 mod
  Patch: https://git.openjdk.org/jdk/pull/18295.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/18295/head:pull/18295

PR: https://git.openjdk.org/jdk/pull/18295


More information about the kulla-dev mailing list