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

(ann) Cannot reference field of inner class in an anonymous class

    Details

    • Subcomponent:
    • Resolved In Build:
      b37
    • CPU:
      x86_64
    • OS:
      linux_ubuntu
    • Verification:
      Verified

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0_11"
        Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
        Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Linux cnl1478 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

        A DESCRIPTION OF THE PROBLEM :
        Annotation values on an inner class in an anonymous class cannot reference attributes of that inner class.

        REGRESSION. Last worked in version 7u65

        ADDITIONAL REGRESSION INFORMATION:
        java version "1.7.0_65"
        Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
        Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Invoke javac with the attached source file as an argument

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        It should compile just fine.
        ACTUAL -
        Compilation fails with one error.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        .../J8Issue.java:13: error: cannot find symbol
                    @Annotation(AnonymousClass.ID)
                                              ^
          symbol: variable ID
          location: class <anonymous OuterBaseClass>.AnonymousClass
        1 error

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        public class J8Issue
        {
            public static void main(String[] args) {
                Object withAttribute = new OuterBaseClass()
                {
                    private void method() {
                        // This compiles OK in Java 7 update 50, 60 and 65, and Java 8 update 5 and 11
                        System.out.println(AnonymousClass.ID);
                    }

                    // This compiles OK in Java 7 update 50, 60 and 65
                    // This WONT compile in Java 8 update 5 and 11
                    @Annotation(AnonymousClass.ID)
                    abstract class AnonymousClass
                    {
                        static final String ID = "B";
                    }
                };
            }
        }

        class OuterBaseClass
        {
        }

        @interface Annotation
        {
            String value();
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Copy the value of the referenced field and put it at the Annotation's value. That requires duplication, and is therefore not preferable.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  jfranck Joel Borggrén-Franck
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: