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

Overloaded static methods in enclosing class may not be found by nested class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8u20
    • tools
    • x86
    • linux

      FULL PRODUCT VERSION :
      java version "1.8.0_20"
      Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
      Java HotSpot(TM) Server VM (build 25.20-b23, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux vxl20046 2.6.32-220.el6.i686 #1 SMP Wed Nov 9 08:02:18 EST 2011 i686 i686 i386 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Overloaded static method in an enclosing class may not be accessed by nested classes extending the containing class if these methods have different access types, for example private and public. It works if all methods are private or if all methods are public. However, if some methods are public and others are private, private methods are not seen. This problem does not occur if the inner class does not extend the containing class.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Try compiling the provided example.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should compile without error.
      ACTUAL -
      Does not compile

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      TestOverloading.java:18: error: incompatible types: int cannot be converted to String
            return test1(1);
                         ^


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class TestOverloading {

        public static String test1(String s) {
          return s;
        }

        private static String test1(Integer i) {
          return i.toString();
        }

        private static class TestOverloadingSubClass extends TestOverloading {

          public String test3() {
            return test1("1");
          }

          public String test4() {
            return test1(1);
          }
        }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Declaring all overloaded methods with the same access type

            dlsmith Dan Smith
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: