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

JShell: gives a compiler error evaluating an expression of inaccessible type

    XMLWordPrintable

Details

    • b34
    • generic
    • generic

    Description

      FULL PRODUCT VERSION :
      java version "9.0.1"
      Java(TM) SE Runtime Environment (build 9.0.1+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.15063]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      not relevant

      A DESCRIPTION OF THE PROBLEM :
      Given the source code, there is no point, why `new Top().n` can't be called from the JShell. Nested inside a call to print, the expression works.

      jshell> /o Inner.java

      jshell> new Top()
      $8 ==> Top@5702b3b1

      jshell> new Top().n
      | Error:
      | Top.Inner has private access in Top
      | new Top().n
      | ^

      jshell> System.out.println(new Top().n)
      REPL.$JShell$12$Top$Inner@4b952a2d

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See description

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      jshell> new Top().n
      $9 ==> Top$Inner@4b952a2d
      ACTUAL -
      jshell> new Top().n
      | Error:
      | Top.Inner has private access in Top
      | new Top().n
      | ^

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      see interaction above

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      // This is the code in a file named Inner.java

      class Top {
          private class Inner { }
          Inner n = new Inner();
      }
      ---------- END SOURCE ----------

      Attachments

        Activity

          People

            rfield Robert Field (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: