United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4706164 : java.awt.AWTKeyStroke.getAWTKeyStrokeForEvent: null reaction

Details
Type:
Bug
Submit Date:
2002-06-21
Status:
Resolved
Updated Date:
2003-10-23
Project Name:
JDK
Resolved Date:
2003-10-23
Component:
client-libs
OS:
solaris_7
Sub-Component:
java.awt
CPU:
sparc
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.0
Fixed Versions:
5.0 (b26)

Related Reports

Sub Tasks

Description

Name: sdR10048			Date: 06/21/2002


JDK1.4.0rc-b92 doc for
java.awt.AWTKeyStroke.getAWTKeyStrokeForEvent(KeyEvent anEvent)
says nothing about situation when anEvent == null:

---
public static AWTKeyStroke getAWTKeyStrokeForEvent(KeyEvent??anEvent)

Returns an AWTKeyStroke which represents the stroke which generated a given KeyEvent.

This method obtains the key char from a KeyTyped event,
and the key code from a KeyPressed or KeyReleased event.
The KeyEvent modifiers are obtained for all three types of KeyEvent.


Parameters:
anEvent - the KeyEvent from which to obtain the AWTKeyStroke

Returns:
the AWTKeyStroke that precipitated the event
---

This reaction should be specified as required in
http://java.sun.com/j2se/javadoc/writingapispecs/index.html#method.

======================================================================

                                    

Comments
EVALUATION

Currently, null is not checked, so an NPE is thrown from within the function.  
The other versions of getAWTKeyStroke throw IAE when a parameter is null.  
Perhaps it would be best to match the other functions in this class.  

Commit to fix in Tiger (JCK spec). 
###@###.### 2002-08-28

We should also change the doc for javax.swing.KeyStroke.getKeyStrokeForEvent 
in the same way.  The two methods should match each other in spec and behavior. 
Swing's KeyStroke has always thrown an NPE in this case.  I don't think we 
ought to change this behavior now.  Instead, it might be better to document 
the existing behavior in AWTKeyStroke and KeyStroke: 

@throws NullPointerException if <code>anEvent</code> is null 

###@###.### 2003-03-17

Note: when we do this, we should also specify in the equals() method that 
false will be returned if anObject is null.  

###@###.### 2003-05-22

Specification for Object.equals mathod explains null parameter value behavior:
"* For any non-null reference value x, x.equals(null) should return false."

###@###.### 2003-05-22
                                     
2003-05-22
SUGGESTED FIX

------- KeyStroke.java -------
*** /tmp/sccs.aWaOzi    Sat Sep 20 14:56:21 2003
--- KeyStroke.java      Sat Sep 20 14:56:11 2003
***************
*** 202,207 ****
--- 202,208 ----
       * obtained for all three types of KeyEvent.
       *
       * @param anEvent the KeyEvent from which to obtain the KeyStroke
+      * @throws NullPointerException if <code>anEvent</code> is null
       * @return the KeyStroke that precipitated the event
       */
      public static KeyStroke getKeyStrokeForEvent(KeyEvent anEvent) {

------- AWTKeyStroke.java -------
*** /tmp/sccs.EjaGAi    Sat Sep 20 15:00:12 2003
--- AWTKeyStroke.java   Sat Sep 20 14:54:42 2003
***************
*** 402,407 ****
--- 402,408 ----
       *
       * @param anEvent the <code>KeyEvent</code> from which to
       *      obtain the <code>AWTKeyStroke</code>
+      * @throws NullPointerException if <code>anEvent</code> is null
       * @return the <code>AWTKeyStroke</code> that precipitated the event
       */
      public static AWTKeyStroke getAWTKeyStrokeForEvent(KeyEvent anEvent) {

###@###.### 2003-09-20
                                     
2003-09-20
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger
tiger-beta

FIXED IN:
tiger
tiger-beta

INTEGRATED IN:
tiger-b26
tiger-beta


                                     
2004-06-14



Hardware and Software, Engineered to Work Together