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

Loading class methods using default ClassLoaders returns superclasse's method

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 7u75
    • Fix Version/s: None
    • Component/s: core-libs
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version '"1.7.0_25

      ADDITIONAL OS VERSION INFORMATION :
      windows 7

      A DESCRIPTION OF THE PROBLEM :
      When i try to load a class using bootstrap ClassLoader (see code below) i get some methods from a superclass, it only happens with methods that are overloaded by a subclass.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Method name: foo From class:
      Aclass.Bclass with declared methods:
      java.lang.Integer

      Method name: bar From class:
      Aclass.Bclass with declared methods:
      java.lang.String

      com.nedstat.reporting.consistency.parameters.reflection_test.Aclass.Bclass
      com.nedstat.reporting.consistency.parameters.reflection_test.Aclass
      ACTUAL -
      Aclass.Bclass with declared methods:
      Method name: foo From class:

      Aclass.Bclass with declared methods:
      java.lang.Integer

      Method name: bar From class:
      Aclass.Bclass with declared methods:

      Method name: bar From class:
      Aclass.Bclass with declared methods:
      java.lang.String

      com.nedstat.reporting.consistency.parameters.reflection_test.Aclass.Bclass
      com.nedstat.reporting.consistency.parameters.reflection_test.Aclass

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      //step 1, create this class in a new file:
      class Aclass
      {
        public void foo()
        {
        }
        public void bar()
        {
        }
        public class Bclass extends Aclass
        {
          public void foo(Integer one)
          {
          }
          public void bar(String two)
          {
          }
        }
      }
      //Put this in a new file (this includes the main method):
      public class Tester
      {

        public static void main(String[] args)
        {
          try
          {
            Class<?> clazz = Tester.class.getClassLoader().loadClass("com.nedstat.reporting.consistency.parameters.reflection_test.Aclass$Bclass");
            for (Method method : clazz.getDeclaredMethods())
            {
              System.out.println("Method name: " + method.getName() + " From class: " + method.getDeclaringClass().getCanonicalName() + " with declared methods:");// test
              for (Class<?> param : method.getParameterTypes())
              {
                System.out.println(param.getCanonicalName());
              }
            }

            System.out.println(clazz.getCanonicalName());
            System.out.println(clazz.getSuperclass().getCanonicalName());
          }
          catch (ClassNotFoundException e)
          {
            e.printStackTrace();
          }
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      could not find any

        Attachments

          Activity

            People

            Assignee:
            rpatil Ramanand Patil
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated: