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

JShell: Crash on the instantiation of an anonymous class

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • 13
    • 11, 12
    • tools

      Here are three pairs of instantiations, each pair involving a normal class and an anonymous subclass. In the third pair, instantiating the anonymous subclass crashes JShell, presumably because instantiating the normal class is forbidden.

      | Welcome to JShell -- Version 12
      | For an introduction type: /help intro

      jshell> new Object()
      $1 ==> java.lang.Object@457e2f02

      jshell> new Object() {}
      $2 ==> $0@724af044

      jshell> new File("bob")
      $3 ==> bob

      jshell> new File("bob") {}
      $4 ==> bob

      jshell> new PrintStream("bob")
      | Exception java.io.FileNotFoundException: bob (Access is denied)
      | at FileOutputStream.open0 (Native Method)
      | at FileOutputStream.open (FileOutputStream.java:292)
      | at FileOutputStream.<init> (FileOutputStream.java:235)
      | at FileOutputStream.<init> (FileOutputStream.java:124)
      | at PrintStream.<init> (PrintStream.java:226)
      | at (#5:1)

      jshell> new PrintStream("bob") {}
      | Error:
      Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 0, end -2, length 25
              at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3410)
              at java.base/java.lang.String.substring(String.java:1883)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.displayableDiagnostic(JShellTool.java:3516)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.displayDiagnostics(JShellTool.java:3479)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.handleEvent(JShellTool.java:3585)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSource(JShellTool.java:3557)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processSourceCatchingReset(JShellTool.java:1305)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.processInput(JShellTool.java:1203)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.run(JShellTool.java:1176)
              at jdk.jshell/jdk.internal.jshell.tool.JShellTool.start(JShellTool.java:975)
              at jdk.jshell/jdk.internal.jshell.tool.JShellToolBuilder.start(JShellToolBuilder.java:254)
              at jdk.jshell/jdk.internal.jshell.tool.JShellToolProvider.main(JShellToolProvider.java:120)

            rfield Robert Field (Inactive)
            abuckley Alex Buckley
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: