-
Bug
-
Resolution: Fixed
-
P3
-
5.0u1
-
None
-
b27
-
x86
-
windows_2000
-
Verified
According to the specs J2SE 1.4.2 and 5.0:
Component.setFocusTraversalKeys(int id, Set keystrokes)
"Throws: IllegalArgumentException - .. if any Object in
keystrokes is not an AWTKeyStroke"
However, the J2SE implementations 1.4.2 and 1.5.0 throw ClassCastException
instead of expected IllegalArgumentException.
The code sample below demonstrates the problem:
-------------- TestFT13.java -----------------
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class TestFT13 {
Button button = new Button();
public static void main(String[] args) {
new TestFT13().test();
}
private void test() {
AWTKeyStroke key = AWTKeyStroke.getAWTKeyStrokeForEvent(
new KeyEvent(button, KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_UNDEFINED, 'a'));
HashSet set = new HashSet();
set.add(key);
set.add(new Object());
try {
button.setFocusTraversalKeys(
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, set);
} catch(Exception e) {
if (e instanceof IllegalArgumentException) {
System.out.println("Component: OKAY");
} else {
e.printStackTrace();
System.out.println("Component: unexpected " + e + " thrown instead of IAE");
}
}
}
}
---------------------------------------------------
-------------- Output for 1.4.2 -------------------
e:\c:\jdk1.4.2\bin\java -classpath . TestFT13
java.lang.ClassCastException
at java.awt.Component.setFocusTraversalKeys_NoIDCheck(Component.java:5802)
at java.awt.Component.setFocusTraversalKeys(Component.java:5742)
at TestFT13.test(TestFT13.java:20)
at TestFT13.main(TestFT13.java:9)
Component: unexpected java.lang.ClassCastException thrown instead of IAE
---------------------------------------------------
###@###.### 2004-11-16 11:00:40 GMT
Component.setFocusTraversalKeys(int id, Set keystrokes)
"Throws: IllegalArgumentException - .. if any Object in
keystrokes is not an AWTKeyStroke"
However, the J2SE implementations 1.4.2 and 1.5.0 throw ClassCastException
instead of expected IllegalArgumentException.
The code sample below demonstrates the problem:
-------------- TestFT13.java -----------------
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class TestFT13 {
Button button = new Button();
public static void main(String[] args) {
new TestFT13().test();
}
private void test() {
AWTKeyStroke key = AWTKeyStroke.getAWTKeyStrokeForEvent(
new KeyEvent(button, KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_UNDEFINED, 'a'));
HashSet set = new HashSet();
set.add(key);
set.add(new Object());
try {
button.setFocusTraversalKeys(
KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, set);
} catch(Exception e) {
if (e instanceof IllegalArgumentException) {
System.out.println("Component: OKAY");
} else {
e.printStackTrace();
System.out.println("Component: unexpected " + e + " thrown instead of IAE");
}
}
}
}
---------------------------------------------------
-------------- Output for 1.4.2 -------------------
e:\c:\jdk1.4.2\bin\java -classpath . TestFT13
java.lang.ClassCastException
at java.awt.Component.setFocusTraversalKeys_NoIDCheck(Component.java:5802)
at java.awt.Component.setFocusTraversalKeys(Component.java:5742)
at TestFT13.test(TestFT13.java:20)
at TestFT13.main(TestFT13.java:9)
Component: unexpected java.lang.ClassCastException thrown instead of IAE
---------------------------------------------------
###@###.### 2004-11-16 11:00:40 GMT
- relates to
-
JDK-7133207 Regression: ClassCastException thrown from Component.setFocusTraversalKeys_NoIDCheck instead of IAE
-
- Closed
-
-
JDK-6195831 KeyboardFocusManager.setDefaultFocusTraversalKeys(..) throws ClassCastException instead of IAE
-
- Closed
-