Name: ksC84122 Date: 01/06/99
According to the javadoc (for java.util.Map.containsKey(Object key)),
java.util.jar.Attributes.containsKey(Object key) should throw ClassCastException
"if the key is of an inappropriate type for this map." The only appropriate type
for the key is Attributes.Name, so any other object should cause throwing
ClassCastException. java.util.jar.Attributes.containsKey(String) does not throw
ClassCastException in JDK 1.2-fcs, which is wrong.
java.util.jar.Attributes.get(Object name) also does not throw ClassCastException,
when name is not Attributes.Name.
A test example which demonstrates this problem.
===== Test22.java ========
import java.util.jar.Attributes;
public class Test22 {
public static void main (String argv[]) {
Attributes attr = new Attributes();
try {
attr.containsKey("some_key");
System.out.println("Failed: ClassCastException expected");
return;
} catch (ClassCastException cce) { //OKAY
}
try {
attr.get("some_key");
System.out.println("Failed: ClassCastException expected");
return;
} catch (ClassCastException cce) { //OKAY
}
System.out.println("Passed");
return;
}
}
========= Sample run (JDK-1.2-fcs) ==========
#>java Test22
Failed: ClassCastException expected
======================================================================
- duplicates
-
JDK-4199920 Spec clarification in Map interface
-
- Resolved
-