openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mprud...@apache.org
Subject svn commit: r540199 - in /incubator/openjpa/trunk/openjpa-lib/src: main/java/org/apache/openjpa/lib/conf/Value.java test/java/org/apache/openjpa/lib/conf/TestValue.java
Date Mon, 21 May 2007 16:35:29 GMT
Author: mprudhom
Date: Mon May 21 09:35:28 2007
New Revision: 540199

URL: http://svn.apache.org/viewvc?view=rev&rev=540199
Log:
OPENJPA-237 Copy aliases array so it can't get modified by reference

Added:
    incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/TestValue.java
  (with props)
Modified:
    incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java

Modified: incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java?view=diff&rev=540199&r1=540198&r2=540199
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java
(original)
+++ incubator/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Value.java
Mon May 21 09:35:28 2007
@@ -100,9 +100,13 @@
     /**
      * 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;
     }
 
     /**

Added: incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/TestValue.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/TestValue.java?view=auto&rev=540199
==============================================================================
--- incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/TestValue.java
(added)
+++ incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/TestValue.java
Mon May 21 09:35:28 2007
@@ -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]);
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-lib/src/test/java/org/apache/openjpa/lib/conf/TestValue.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message