JDK-5061402 : REGRESSION: SwingUtilities.getAncestorOfClass generics problem
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000,windows_xp
  • CPU: x86
  • Submitted: 2004-06-10
  • Updated: 2017-05-16
  • Resolved: 2004-06-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b57Fixed
Description

Name: rmT116609			Date: 06/10/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
In Java 1.5 the API for SwingUtilities.getAncestorOfClass changed to make use of generics.  The class type to search for now must be a subclass of Container where previously it could be an interface.

This did work in 1.4 and earlier as the class passed into the method had no effect on the requirements of the returned class.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attempt to compile the following:

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Successful compile.
ACTUAL -
Compilation error.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Test.java:11: <T>getAncestorOfClass(java.lang.Class<T>,java.awt.Component) in javax.swing.SwingUtilities cannot be applied to (java.lang.Class<Test.TestInterface>,javax.swing.JButton)
    TestInterface ti = (TestInterface)SwingUtilities.getAncestorOfClass( TestInterface.class, b );
                                                    ^
1 error

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import javax.swing.JButton;
import javax.swing.SwingUtilities;
public class Test
{

  public void test()
  {
    JButton b = new JButton();
    // ... do something to build a complex gui where
    //     something implementing TestInterface is a parent of b.
    TestInterface ti = (TestInterface)SwingUtilities.getAncestorOfClass( TestInterface.class, b );
  }

  private interface TestInterface
  {
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None.  Since the class object passed in MUST be for something that subclasses Container no workaround is possible.

Release Regression From : 1.4.2_04
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Incident Review ID: 277051) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-rc FIXED IN: tiger-rc INTEGRATED IN: tiger-b57 tiger-rc
25-06-2004

EVALUATION A valid complaint. We need to relax the constraint on the type of class that can be passed to this method. ###@###.### 2004-06-10
10-06-2004