java.util.jar.Attributes.containsKey(), get() do not throw ClassCastException

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: P4
    • None
    • Affects Version/s: 1.2.0
    • Component/s: tools
    • jar
    • sparc
    • solaris_2.6



      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

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

            Assignee:
            Josh Bloch (Inactive)
            Reporter:
            Kirill Soshalskiy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: