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

getReturnType() of java.lang.reflect.Method returns wrong value

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • 9
    • 7u51
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.7.0_51"
      Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux ip-172-31-23-54 3.2.0-40-virtual #64-Ubuntu SMP Mon Mar 25 21:42:18 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Given a class C that inherits an Interface with generic parameters.

      Given that C overrides an interface method M with generic parameters.

      If we call getDeclaredMethods() on Class<C> instance it returns two versions os M if C has more than one method.

      But if C has only the overriden method M then getDeclaredMethods returns OK.


      ADDITIONAL REGRESSION INFORMATION:
      java version "1.7.0_45"
      Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
      Java HotSpot(TM) Server VM (build 24.45-b08, mixed mode)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See source code: note that the lines printed shows "execute" twice.

      If you remove "public void someMethod" then "execute" appears only once.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Class.getDeclaredMethods() should return only the declared methods.
      ACTUAL -
      Class.getDeclaredMethods() should return the same method twice.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.lang.reflect.Method;


      public class ExpressionsTest {

      interface Expression<Input, Output> {
      Output execute(Input parameters);
      }

      class ExpressionImpl implements Expression<String, Integer> {
      @Override
      public Integer execute(String parameter) {
      return parameter.length();
      }

      public void someMethod() {
      }
      }

      public static void main(String... args) throws NoSuchMethodException, SecurityException {
      for (Method method : ExpressionImpl.class.getDeclaredMethods()) {
      System.out.println(method);
      }
      }

      }

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

            jfranck Joel Borggrén-Franck (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: