JDK-4706164 : java.awt.AWTKeyStroke.getAWTKeyStrokeForEvent: null reaction
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_7
  • CPU: sparc
  • Submitted: 2002-06-21
  • Updated: 2017-05-16
  • Resolved: 2003-10-23
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 b26Fixed
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
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger tiger-beta FIXED IN: tiger tiger-beta INTEGRATED IN: tiger-b26 tiger-beta
14-06-2004

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
20-09-2003

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
22-05-2003