Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4200913

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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 1.2.0
    • tools
    • jar
    • sparc
    • solaris_2.6

    Description



      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

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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: