You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by jo...@apache.org on 2014/03/18 21:11:15 UTC
svn commit: r1579026 - in /cayenne/main/trunk/cayenne-server/src:
main/java/org/apache/cayenne/exp/parser/ASTList.java
test/java/org/apache/cayenne/exp/parser/ASTListTest.java
Author: johnthuss
Date: Tue Mar 18 20:11:14 2014
New Revision: 1579026
URL: http://svn.apache.org/r1579026
Log:
Fix possible ArrayStoreException in ASTList when using Arrays.asList(...)
Added:
cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTListTest.java
Modified:
cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTList.java
Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTList.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTList.java?rev=1579026&r1=1579025&r2=1579026&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTList.java (original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/exp/parser/ASTList.java Tue Mar 18 20:11:14 2014
@@ -179,7 +179,7 @@ public class ASTList extends SimpleNode
this.values = new Object[size];
System.arraycopy((Object[]) value, 0, this.values, 0, size);
} else if (value instanceof Collection) {
- this.values = ((Collection) value).toArray();
+ this.values = ((Collection) value).toArray(new Object[((Collection) value).size()]);
} else if (value instanceof Iterator) {
List values = new ArrayList();
Iterator it = (Iterator) value;
Added: cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTListTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTListTest.java?rev=1579026&view=auto
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTListTest.java (added)
+++ cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/exp/parser/ASTListTest.java Tue Mar 18 20:11:14 2014
@@ -0,0 +1,49 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+package org.apache.cayenne.exp.parser;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.Persistent;
+
+public class ASTListTest extends TestCase {
+
+ public void testConstructorWithCollection() {
+ ObjectId objectId = new ObjectId("Artist", "ARTIST_ID", 1);
+ Persistent artist = mock(Persistent.class);
+ when(artist.getObjectId()).thenReturn(objectId);
+
+ ASTList exp = new ASTList(Arrays.asList(artist));
+ assertNotNull(exp);
+
+ List<Persistent> collection = new ArrayList<Persistent>();
+ collection.add(artist);
+ exp = new ASTList(collection);
+ assertNotNull(exp);
+ }
+
+}