You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by to...@apache.org on 2004/01/20 18:19:18 UTC
cvs commit: ws-axis/java/test/encoding TestDeser.java
tomj 2004/01/20 09:19:18
Modified: java/src/org/apache/axis/encoding/ser ArrayDeserializer.java
java/test/encoding TestDeser.java
Log:
Do not use eager allocation in the Array deserializer.
This will have a side effect: if the XML claims an array has a size of 4,
but there are only 3 elements provided, Axis will return an array of
size 3. We will not allocate slots for array positions beyond the last
one we have data for.
Change the array test to reflect this difference.
Revision Changes Path
1.42 +12 -8 ws-axis/java/src/org/apache/axis/encoding/ser/ArrayDeserializer.java
Index: ArrayDeserializer.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/ArrayDeserializer.java,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- ArrayDeserializer.java 28 Nov 2003 03:57:51 -0000 1.41
+++ ArrayDeserializer.java 20 Jan 2004 17:19:17 -0000 1.42
@@ -344,10 +344,13 @@
// Create an ArrayListExtension class to store the ArrayList
// plus converted objects.
ArrayList list = new ArrayListExtension(arrayClass, length);
- // ArrayList lacks a setSize(), so...
- for (int i = 0; i < length; i++) {
- list.add(null);
- }
+
+ // This is expensive as our array may not grown this big.
+ // Prevents problems when XML claims a huge size
+ // that it doesn't actually fill.
+ //for (int i = 0; i < length; i++) {
+ // list.add(null);
+ //}
value = list;
}
@@ -378,17 +381,17 @@
Messages.getMessage("badOffset00", offset));
}
- curIndex =
+ curIndex =
convertToIndex(offset.substring(leftBracketIndex + 1,
rightBracketIndex),
"badOffset00");
}
-
+
if (log.isDebugEnabled()) {
log.debug("Exit: ArrayDeserializer::startElement()");
}
}
-
+
/**
* onStartChild is called on each child element.
@@ -750,7 +753,8 @@
}
}
ArrayListExtension(Class arrayClass, int length) {
- super(length);
+ // Sanity check the array size, 50K is big enough to start
+ super(length > 50000 ? 50000 : length);
this.arrayClass = arrayClass;
// Don't use the array class as a hint
// if it can't be instantiated
1.47 +12 -1 ws-axis/java/test/encoding/TestDeser.java
Index: TestDeser.java
===================================================================
RCS file: /home/cvs/ws-axis/java/test/encoding/TestDeser.java,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- TestDeser.java 24 Dec 2003 12:36:50 -0000 1.46
+++ TestDeser.java 20 Jan 2004 17:19:18 -0000 1.47
@@ -303,7 +303,6 @@
list.add("abc");
list.add(null);
list.add("def");
- list.add(null);
deserialize("<result xsi:type=\"soapenc:Array\" " +
"soapenc:arrayType=\"xsd:string[4]\"> " +
"<item soapenc:position=\"[0]\" xsi:type=\"xsd:string\">abc</item>" +
@@ -312,6 +311,18 @@
list, true);
}
+ public void testHugeSparseArray() throws Exception {
+ ArrayList list = new ArrayList(4);
+ list.add("abc");
+ list.add(null);
+ list.add("def");
+ deserialize("<result xsi:type=\"soapenc:Array\" " +
+ "soapenc:arrayType=\"xsd:string[50000000]\"> " +
+ "<item soapenc:position=\"[0]\" xsi:type=\"xsd:string\">abc</item>" +
+ "<item soapenc:position=\"[2]\" xsi:type=\"xsd:string\">def</item>" +
+ "</result>",
+ list, true);
+ }
public void testMap() throws Exception {
HashMap m = new HashMap();
m.put("abcKey", "abcVal");