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

anonymous class gets garbled view of private methods within scope

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux_ubuntu

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_18"
      OpenJDK Runtime Environment (IcedTea6 1.8.2) (6b18-1.8.2-4ubuntu2)
      OpenJDK 64-Bit Server VM (build 16.0-b13, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux shinobi-desk 2.6.32-23-server #37-Ubuntu SMP Fri Jun 11 09:11:11 UTC 2010 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      An anonymous class does not see a private method of the immediately enclosing class that is overloaded with a more visible (public, protected, or default) method of the same name.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try to compile the supplied code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The code should compile.
      ACTUAL -
      The code doesn't compile.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      C.java:7: foo() in C cannot be applied to (int)
      new C() {{ foo( n + 1 ); }};
      ^
      1 error


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      class C {
              static final void foo() {}
              static final void baz() {}

              private static final void foo( final int n ) {
                      new C() {{ foo( n + 1 ); }};
              }

              private static final void bar( final int n ) {
                      new C() {{ bar( n + 1 ); }};
              }

              static final void baz( final int n ) {
                      new C() {{ baz( n + 1 ); }};
              }
      }


      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Increase the visibility of the private method, or rename it -- observe that, in the example code supplied, there's an error for foo, but not for bar (no overloads) or baz (not private).

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dlsmith Dan Smith
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: