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

Cannot call private static method from subclass defined in same file

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 9
    • 8u31
    • tools
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_25"
      Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      javac fails to compile subclasses that attempt to call an unqualified private static method from their superclass. This only occurs if there is also a non-private method with the same name as the private static method declared in the superclass.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Attempt to compile the provided source using javac.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The code should compile.
      ACTUAL -
      The code fails to compile.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      src\xxx\StaticFail.java:10: error: method shadow in class StaticFail cannot be applied to given types;
                              shadow(false);
                              ^
        required: no arguments
        found: boolean
        reason: actual and formal argument lists differ in length
      1 error

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class StaticFail {
      private static void shadow(boolean misterBool) {}
      public void shadow() {}

      public static class FailImpl extends StaticFail {
      public void abby() {
      shadow(false);
      }
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Declare static method as protected or change its name.

            sadayapalam Srikanth Adayapalam (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: