JDK-6992717 : methods inherited from non-public super class are volatile
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 6u21
  • Priority: P5
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2010-10-18
  • Updated: 2012-09-28
  • Resolved: 2010-10-18
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
1.6.0_21-b07

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
If a class extends a non-public super class, the methods inherited will be volatile, and the getDeclaringClass() of such methods will be subclass, not superclass.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile the java files: javac *.java
then run Child: java Child

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
public static void Child.main(java.lang.String[]), declaring class is class Child
public int Father.getID(), declaring class is class Father
ACTUAL -
public static void Child.main(java.lang.String[]), declaring class is class Child
public int Child.getID(), declaring class is class Child
        isVolatile

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Father.java:
class Father {
  protected int id;

  public int getID() {
    return id;
  }

}

Child.java:
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Child extends Father {
  public static void main(String[] args) {
    Method[] ms = Child.class.getMethods();
    for (Method m : ms) {
      if (!m.getDeclaringClass().equals(Object.class)) {
        String oo = m.toString();
        System.out.println(oo);

        if (Modifier.isVolatile(m.getModifiers())) {
          System.out.println("\tisVolatile, and its declaring class is "
            + m.getDeclaringClass());
        }
      }

    }
  }

}

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

CUSTOMER SUBMITTED WORKAROUND :
make superclass public. Then run Child can get the expected result.

Comments
EVALUATION The modifiers for "volatile" and a *bridge method* overlap. A bridge method is added when a public class extends a non-public class to allow the inherited methods to be called reflectively; see 6342411. Closing as not a bug.
18-10-2010