-
Bug
-
Resolution: Fixed
-
P3
-
6
-
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".
------------------------
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".