java.util.jar.Attributes.put(Object name, Object value) doesn't throw ClassCastException ----------------------------------------------------------------------------------------
Key: HARMONY-79 URL: http://issues.apache.org/jira/browse/HARMONY-79 Project: Harmony Type: Bug Components: Classlib Reporter: Svetlana Samoilenko According to the j2se 1.4 and 1.5 specification method java.util.jar.Attributes.put throws ClassCastException - if the name is not a Attributes.Name or the value is not a String. Harmony doesn't throw ClassCastException 1) if the name is not a Attributes.Name 2) if the value is not a String Code to reproduce: import java.util.jar.Attributes; public class test2 { public static void main(String[] args) { Attributes att=new Attributes(); try { att.put(new Object(), new String("") ); } catch ( ClassCastException e) { System.out.println("ClassCastException if the name is not a Attributes.Name "); }; try { att.put(new Attributes.Name("IMPLEMENTATION_VENDOR"), new Object()); } catch ( ClassCastException e) { System.out.println("ClassCastException if the value is not a String"); return; }; System.out.println("Wrong. Must be ClassCastException"); } } Steps to Reproduce: 1. Build Harmony (check-out on 2006-01-30) j2se subset as described in README.txt. 2. Compile test2.java using BEA 1.4 javac > javac -d . test2.java 3. Run java using compatible VM (J9) > java -showversion test2 Output: C:\tmp>C:\jrockit-j2sdk1.4.2_04\bin\java.exe -showversion test2 java version "1.4.2_04" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32, Native Threads, GC strategy: parallel) ClassCastException if the name is not a Attributes.Name ClassCastException if the value is not a String C:\tmp>C:\harmony\trunk\deploy\jre\bin\java -showversion test2 (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable. Wrong. Must be ClassCastException Siggested fix: to change the line 232 in archive/src/main/java/java/util/jar/Attributes.java as follows: 232 return map.put((Name) key, (String) value); Suggested junit test case: ------------------------ AttributesTest.java ------------------------------------------------- import java.util.jar.*; import junit.framework.*; public class AttributesTest extends TestCase { public static void main(String[] args) { junit.textui.TestRunner.run(AttributesTest.class); } public void test_put () { Attributes att=new Attributes(); // ClassCastException if the name is not a Attributes.Name try { att.put(new Object(), new String("") ); } catch ( ClassCastException e) { // expected }; //ClassCastException if the value is not a String try { att.put(new Attributes.Name("IMPLEMENTATION_VENDOR"), new Object()); } catch ( ClassCastException e) { // expected }; } } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira