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

Wrong return value of Property.setProperty() when using Properties.defaults

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.4.2
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      Name: jl125535 Date: 04/07/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b45)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b45, mixed mode)

      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux 2.4.19-4GB

      A DESCRIPTION OF THE PROBLEM :
      The javadoc for java.utils.Properties says:
      public Object setProperty(String key, String value)
      Returns:
      the previous value of the specified key in this property list, or null if it did not have one.

      This is wrong. The code is:
      public synchronized Object setProperty(String key, String value) {
              return put(key, value);
          }

      It's obvious that this method doesn't take Properties.defaults into account.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run test case.
      Expected output:
      a =b
        Old value = b
      Actual output:
      a =b
        Old value = null


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Properties.setProperty() returns the value that is returned
      for Properties.getProperty().
      ACTUAL -
      Properties.setProperty() does not return the value returned
      by Properties.getProperty() when the value is only set
      in the Properties.defaults put not in the properties themselves.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.*;

      public class defprop {
          public static void main (String args[]) {
              Properties defprop = new Properties();
              defprop.setProperty("a","b");

              Properties prop = new Properties(defprop);
              System.out.println("a ="+prop.getProperty("a"));
              Object obj = prop.setProperty("a","c ");
              System.out.println("Old value = "+obj);
          }

      }



      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Call getProperties before setProperties.
      It's not a severe bug, but it's just really confusing.
      It would perhaps even be enough to update the javadoc.
      (Incident Review ID: 235458)
      ======================================================================
      ###@###.### 2004-11-17 20:53:58 GMT

        Attachments

          Activity

            People

            • Assignee:
              sherman Xueming Shen
              Reporter:
              jleesunw Jon Lee (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: