mirror of https://github.com/apache/openjpa.git
OPENJPA-237 Copy aliases array so it can't get modified by reference
git-svn-id: https://svn.apache.org/repos/asf/incubator/openjpa/trunk@540199 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
81e89bcd80
commit
e041fe0d4d
|
@ -100,9 +100,13 @@ public abstract class Value implements Cloneable {
|
|||
/**
|
||||
* Aliases for the value in the form key1, value1, key2, value2, ...
|
||||
* All alias values must be in string form.
|
||||
* <p>
|
||||
* To avoid potential side-effects, this method copies the array passed in.
|
||||
*/
|
||||
public void setAliases(String[] aliases) {
|
||||
this.aliases = aliases;
|
||||
String [] aStrings = new String[aliases.length];
|
||||
System.arraycopy(aliases, 0, aStrings, 0, aStrings.length);
|
||||
this.aliases = aStrings;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package org.apache.openjpa.lib.conf;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TestValue extends TestCase {
|
||||
|
||||
private static class SimpleValue extends Value {
|
||||
|
||||
protected String getInternalString() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Class getValueType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void setInternalObject(Object obj) {
|
||||
|
||||
}
|
||||
|
||||
protected void setInternalString(String str) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void testSetAliasesByValue() {
|
||||
String alias = "alias";
|
||||
String aName = "Johnny";
|
||||
String bName = "Pete";
|
||||
String [] aStrings = { alias, aName };
|
||||
|
||||
SimpleValue sValue = new SimpleValue();
|
||||
sValue.setAliases(aStrings);
|
||||
sValue.setAlias(alias, bName);
|
||||
assertEquals("Did not set the new alias", bName,
|
||||
sValue.getAliases()[1]);
|
||||
assertEquals("Array of aliases not set by value", aName, aStrings[1]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue