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

The "getDeclaredMethods" function returns a inherited method

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.8.0_66"
      Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      MAC OS X 10.8.5

      A DESCRIPTION OF THE PROBLEM :
      The "getDeclaredMethods" function should return only the methods that are declared in the input class A. However, when the modifier of the superclass of A is "abstract class" (without public), the function also returns the methods of the superclass.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public interface Posicion {
          public void obtenerCoordenadaX();
          public void obtenerCoordenadaY();
      }

      abstract class Vehiculo implements Posicion {
          public void obtenerCoordenadaX(){};
          public void obtenerCoordenadaY(){};
      }

      public class Coche extends Vehiculo {
      }

      import java.lang.reflect.Method;

      public class TestCase {
          public static void main(String[] args) {
              Class<?> clazz = Coche.class;
              Method[] methods = clazz.getDeclaredMethods();
          }
      }
      ---------- END SOURCE ----------

        1. Coche.java
          0.0 kB
          Pallavi Sonal
        2. Posicion.java
          0.1 kB
          Pallavi Sonal
        3. TestGetDeclaredMethods.java
          0.3 kB
          Pallavi Sonal
        4. Vehiculo.java
          0.1 kB
          Pallavi Sonal

            darcy Joe Darcy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: