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

javax.script.SimpleBindings behavior of method put(String, Object) contradicts spec

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 6
    • core-libs
    • None
    • b53
    • generic
    • generic
    • Verified

      The spec for method javax.script.SimpleBindings.put(String, Object) says:
      ------------------------
      public Object put(String name,
                        Object value)
          Sets the specified key/value in the underlying map field.

          Specified by:
              put in interface Map<String,Object>
          Specified by:
              put in interface Bindings

          Parameters:
              name - Name of value
              value - Value to set.
          Returns:
              Previous value for the specified key. Returns null if key was previously unset.
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
          Throws:
              NullPointerException - if the name is null.
              IllegalArgumentException - if the name is empty
      -------------------------------------------
      In fact, the method does not return previous value for the specified key. Here is a short example:

      import java.util.HashMap;
      import javax.script.SimpleBindings;

      public class Test {
          
          public static void main(String[] argv) {
              HashMap<String, Object> map = new HashMap<String, Object>();
              SimpleBindings binds = new SimpleBindings();
              map.put("key", "oldvalue");
              binds.put("key", "oldvalue");
              System.out.println("HashMap returned: " + map.put("key", "newvalue"));
              System.out.println("SimpleBindings returned: " +
                      binds.put("key", "newvalue"));
          }
      }

      Results:
      HashMap returned: oldvalue
      SimpleBindings returned: newvalue


      As you can see the method SimpleBindings.put(String,Object) returns "newvalue" instead of "oldvalue".

            duke J. Duke
            agavrilosunw Alexey Gavrilov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: