src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/StoredScript.java
Print this page
@@ -25,10 +25,11 @@
package jdk.nashorn.internal.runtime;
import java.io.Serializable;
import java.util.Arrays;
+import java.util.LinkedHashMap;
import java.util.Map;
/**
* Class representing a persistent compiled script.
*/
@@ -81,23 +82,35 @@
/**
* Returns a map of class names to class bytes.
* @return map of class bytes
*/
public Map<String, byte[]> getClassBytes() {
- return classBytes;
+ final Map<String, byte[]> clonedMap = new LinkedHashMap<>();
+ for (final Map.Entry<String, byte[]> entry : classBytes.entrySet()) {
+ clonedMap.put(entry.getKey(), entry.getValue().clone());
+ }
+ return clonedMap;
}
/**
* Returns the constants array.
* @return constants array
*/
public Object[] getConstants() {
- return constants;
+ return constants.clone();
}
- Map<Integer, FunctionInitializer> getInitializers() {
- return initializers;
+ /**
+ * Returns the function initializers map.
+ * @return The initializers map.
+ */
+ public Map<Integer, FunctionInitializer> getInitializers() {
+ final Map<Integer, FunctionInitializer> clonedMap = new LinkedHashMap<>();
+ for (final Map.Entry<Integer, FunctionInitializer> entry : initializers.entrySet()) {
+ clonedMap.put(entry.getKey(), new FunctionInitializer(entry.getValue()));
+ }
+ return clonedMap;
}
@Override
public int hashCode() {
int hash = mainClassName.hashCode();