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

java.util.jar.Attributes.put() doesn't throw ClassCastException

XMLWordPrintable

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



      Name: ksC84122 Date: 12/25/98


      According to the javadoc, java.util.jar.Attributes.put(Object name,
      Object value) should throw ClassCastException if the name is not an
      Attributes.Name or the value is not a String . JDK 1.2-fcs,
      however, doesn't implement this feature.

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

      public class Test18 {

          public static void main (String argv[]) {
              Attributes attr = new Attributes();
              String s = "SomeValue";
          
              try {
                  attr.put("SomeName", s);
                  System.out.println("Failed: ClassCastException excpected");
                  return;
              } catch (ClassCastException cce) { //OKAY
              }
              try {
                  attr.put( new Attributes.Name("SomeName"), s.getBytes()) ;
                  System.out.println("Failed: ClassCastException excpected");
                  return;
              } catch (ClassCastException cce) { //OKAY
              }
              System.out.println("Passed: OK");
              return;
          }
      }

      ========= Sample run (JDK-1.2-V) ==========
      #>java Test18
      Failed: ClassCastException excpected

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

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: