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

Inaccessible instance error in enum falsely flagged as static context

    Details

    • Type: Bug
    • Status: New
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8, 13
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
      https://stackoverflow.com/questions/41311361/nested-enum-is-static#41311454 describes the following program:

      enum EnumImpl {
          B {
              public void method() {
                  System.out.println(s);
              }
              //public static int b; //(2)Illegal static declaration in inner class
          };
          public abstract void method();
          private int s;
      }

      The compiler error message is:

      non-static variable s cannot be referenced from a static context

      This message is misleading. If "private" is removed from the declaration of s, the class compiles as it should. The reason for failure should be described as "s has private access in EnumImpl".


      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: