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

java.util.jar.Attributes.putAll() does not comply to Map interface spec

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.2.0
    • Fix Version/s: 1.3.0
    • Component/s: tools
    • Labels:
    • Subcomponent:
      jar
    • Resolved In Build:
      kestrel
    • CPU:
      sparc
    • OS:
      solaris_2.6
    • Verification:
      Verified

      Description



      Name: ksC84122 Date: 01/06/99


      According to the javadoc (for java.util.Map.putAll(Map t)), java.util.jar.Attributes.putAll(Map
      attr) should throw ClassCastException if "if the class of a key or value in the specified
      map prevents it from being stored in this map." Key class in the Attributes Map is
      Attributes.Name, so any other object can not be put as a key and ClassCastException should be
      thrown in such a case. However, ClassCastException is not thrown in such a case in JDK 1.2-fcs.
      See also Bug Id: 4199913.

      According to the javadoc (for java.util.Map.putAll(Map t)), java.util.jar.Attributes.putAll(Map
      attr) should throw NullPointerException if "this map does not permit null keys or values, and the
      specified key or value is null." Null keys should not be permitted for Attribute names (see Bug Id:
      4199920). This means that putAll(Map attr) should throw NullPointerException if attr contains null
      keys. Currently putAll(Map attr) does not throw NullPointerException if attr contains null keys in
      JDK 1.2-fcs.

      A test example which demonstrates this problem.
      ===== Test21.java ========
      import java.util.jar.Attributes;
      import java.util.HashMap;

      public class Test21 {

          public static void main (String argv[]) {
              Attributes attr = new Attributes();
              HashMap hm = new HashMap();
          
              hm.put("NewName", "NewValue");
              try { attr.putAll(hm);
                  System.out.println("Failed: ClassCastException expected");
                  return;
              } catch (ClassCastException cce) { //OKAY
              }
          
              hm.clear();
              hm.put(null, null);
              try { attr.putAll(hm);
                  System.out.println("Failed: NullPointerException expected");
                  return;
              } catch (NullPointerException npe) { //OKAY
              }

              System.out.println("Passed");
              return;
          }
      }


      ========= Sample run (JDK-fcs) ==========
      #>java Test21
      Failed: ClassCastException expected

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

        Attachments

          Activity

            People

            Assignee:
            zlisunw Zhenghua Li (Inactive)
            Reporter:
            ksoshals Kirill Soshalskiy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: