United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6459806 Behaviour of java.awt.AWTEventMulticaster.getListeners(,null) is invalid
JDK-6459806 : Behaviour of java.awt.AWTEventMulticaster.getListeners(,null) is invalid

Details
Type:
Bug
Submit Date:
2006-08-14
Status:
Closed
Updated Date:
2012-03-22
Project Name:
JDK
Resolved Date:
2006-08-21
Component:
client-libs
OS:
generic
Sub-Component:
java.awt
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Relates:

Sub Tasks

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);
                                     
2006-08-14
EVALUATION

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



Hardware and Software, Engineered to Work Together