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

The java.net.URLConnection.setRequestProperty allows null key

XMLWordPrintable

    • sparc
    • solaris_2.5



      Name: yyC67448 Date: 02/23/98



      The java.net.URLConnection.setRequestProperty(String key, String value) allows
      null key parameter.

      Method's behavior for null key parameter is not documented.


      Here is the javadoc comments for methods setRequestProperty and
      getRequestProperty


          /**
           * Sets the general request property.
           *
           * @param key the keyword by which the request is known
           * (e.g., "<code>accept</code>").
           * @param value the value associated with it.
           * @since JDK1.0
           */



          /**
           * Returns the value of the named general request property for this
           * connection.
           *
           * @return the value of the named general request property for this
           * connection.
           * @since JDK1.0
           */



      Here is the test demonstrating the bug:

      ------------------------ Test.java ---------------------------------------
      import java.net.*;

      class test
      {
        public static void main(String args[])
        {
          URL url = null;
          URLConnection conn = null;
          String key = null;
          String value = "iso-8859-5";
         

          try {
           url = new URL("http://web2.javasoft.com/index.html");
           conn = url.openConnection();
          } catch(Exception e)
          {
      System.out.println("Failed. Unexpected exception :" + e);
      System.exit(-1);
          }


          try {
             conn.setRequestProperty(key, value);
          } catch(NullPointerException e)
          {
           System.out.println("Passed. OKAY");
           System.exit(0);
          }
          catch(Exception e)
          {
            System.out.println("Failed. Unexpected exception :" + e);
      System.exit(-1);
          }
          
          if( value.equals(conn.getRequestProperty(key) ) )
          {
           System.out.println("getRequestProperty(null) = value");
          }
              
          System.out.println("Failed. No exceptions.");


        }
         
      }

      ------------------------- Output from the test ----------------------------
      getRequestProperty(null) = value
      Failed. No exceptions.
      ---------------------------------------------------------------------------

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

            mmcclosksunw Michael Mccloskey (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: