JDK-6459806 : Behaviour of java.awt.AWTEventMulticaster.getListeners(,null) is invalid
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-08-14
  • Updated: 2012-03-22
  • Resolved: 2006-08-21
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.
JDK 6
6 b97Fixed
Related Reports
Relates :  
Description
J2SE           : FAIL - mustang b95
Platform[s]    : FAIL - seems to be all
switch/Mode    : FAIL - default

The method java.awt.AWTEventMulticaster.getListeners contains the following code (since b95):

 public static <T extends EventListener> T[]
        getListeners(EventListener l, Class<T> listenerType)
    {
        if (listenerType == null) {
            throw new RuntimeException ("Listener type should not be null");
        }
...


This is violation of specification, because it says:

"Throws:
    ClassCastException - if listenerType doesn't specify a class or interface that implements java.util.EventListener"

So RuntimeException should be changed to ClassCastException (or specification should be updated).

This method was changed in mustang b95
affected JCK 6.0 tests:

The following tests:

api/java_awt/AWTEventMulticaster/index.html#GetListeners[AWTEventMulticaster0082]
api/java_awt/Button/index.html#getListeners[Button0012]
api/java_awt/Checkbox/index.html#getListeners[Checkbox0041]
api/java_awt/CheckboxMenuItem/descriptions.html#getListeners[CheckboxMenuItem0014]
api/java_awt/Choice/descriptions.html#getListeners[Choice0141]
api/java_awt/Component/descriptions.html#getListeners[Component0001]
api/java_awt/Container/index.html#getListeners[Container0008]
api/java_awt/List/index.html#getListeners[List0047]
api/java_awt/MenuItem/descriptions.html#getListeners[MenuItem0018]
api/java_awt/Scrollbar/index.html#getListeners[Scrollbar0045]
api/java_awt/TextComponent/descriptions.html#getListeners[TextComponent0042]
api/java_awt/TextField/descriptions.html#getListeners[TextField0018]
api/java_awt/Window/index.html#getListeners[Window0029]

Comments
SUGGESTED FIX --- AWTEventMulticaster.java 2006-08-14 15:15:22.000000000 +0400 *************** *** 1004,1010 **** getListeners(EventListener l, Class<T> listenerType) { if (listenerType == null) { ! throw new RuntimeException ("Listener type should not be null"); } int n = getListenerCount(l, listenerType); --- 1004,1010 ---- getListeners(EventListener l, Class<T> listenerType) { if (listenerType == null) { ! throw new NullPointerException ("Listener type should not be null"); } int n = getListenerCount(l, listenerType);
14-08-2006

EVALUATION actually, we should throw NPE instead of RuntimeException, it was a typo :(
14-08-2006