0

I have large xml tree with following structure:

<?xml version="1.0"?>
<SampleElem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <Children>
      <SampleElem>
         <Children/>
         <Id>1</Id>
         <Value>Test2</Value>
      </SampleElem>
   </Children>
   <Id>-1</Id>
   <Value>Test1</Value>
</SampleElem>

I am trying to deserialize it using simpleframework:

Serializer serializer = new Persister();
SampleElem root = serializer.read(SampleElem.class, someStream, false);

After some time application stopped with error. Log from device:

E/AndroidRuntime(13591): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(13591): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime(13591):    at android.os.AsyncTask$3.done(AsyncTask.java:200)
E/AndroidRuntime(13591):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
E/AndroidRuntime(13591):    at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
E/AndroidRuntime(13591):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
E/AndroidRuntime(13591):    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
E/AndroidRuntime(13591):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
E/AndroidRuntime(13591):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
E/AndroidRuntime(13591):    at java.lang.Thread.run(Thread.java:1019)
E/AndroidRuntime(13591): Caused by: java.lang.StackOverflowError
E/AndroidRuntime(13591):    at java.lang.StringBuilder.append(StringBuilder.java:217)
E/AndroidRuntime(13591):    at java.lang.reflect.Modifier.toString(Modifier.java:285)
E/AndroidRuntime(13591):    at java.lang.reflect.Method.toString(Method.java:538)
E/AndroidRuntime(13591):    at java.lang.reflect.Method.equals(Method.java:361)
E/AndroidRuntime(13591):    at org.apache.harmony.lang.annotation.AnnotationFactory.invoke(AnnotationFactory.java:307)
E/AndroidRuntime(13591):    at $Proxy1.inline(Native Method)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.ElementListLabel.getConverter(ElementListLabel.java:160)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.CacheLabel.getConverter(CacheLabel.java:280)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readVariable(Composite.java:604)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readUnion(Composite.java:549)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readElement(Composite.java:532)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readElements(Composite.java:445)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.read(Composite.java:201)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.read(Composite.java:148)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.CompositeList.populate(CompositeList.java:175)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.CompositeList.read(CompositeList.java:120)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readVariable(Composite.java:623)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readUnion(Composite.java:549)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readElement(Composite.java:532)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readElements(Composite.java:445)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.read(Composite.java:201)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.read(Composite.java:148)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.CompositeList.populate(CompositeList.java:175)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.CompositeList.read(CompositeList.java:120)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readVariable(Composite.java:623)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readUnion(Composite.java:549)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readElement(Composite.java:532)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readElements(Composite.java:445)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.read(Composite.java:201)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.read(Composite.java:148)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.CompositeList.populate(CompositeList.java:175)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.CompositeList.read(CompositeList.java:120)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readVariable(Composite.java:623)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
E/AndroidRuntime(13591):    at org.simpleframework.xml.core.Compos

Data is completely correct, input xml is fully valid. Do you have any ideas?

Thanks!

UPDATE:

What about TreeStrategy? How it should be used? Have you any examples?

asolovyov
  • 903
  • 1
  • 10
  • 21
  • Can be a memory issue because the tree is too big? Did you try with smaller ones? – Evans May 07 '13 at 21:45
  • Yes, tree has large hierarchical length, but I can't split it. I need to handle whole tree. Smaller tree works fine. – asolovyov May 07 '13 at 21:54
  • Then try to increase the stack size of the JVM with -Xss. Check the question and the answers in this link http://stackoverflow.com/questions/3700459/how-to-increase-to-java-stack-size – Evans May 07 '13 at 22:00
  • Thanks, but I cant apply it because I am working on Android mobile platform. Furthermore, increasing of stack size does not resolve problem. – asolovyov May 07 '13 at 22:07
  • https://groups.google.com/d/msg/android-developers/CZbicbW2bCU/PtavBOnYJuQJ how to increase stack size in android. – Eluvatar May 07 '13 at 22:21

3 Answers3

1

You can't change the default stack size, or the stack size of an existing thread, on Android. You can, however, set the stack size at the time a thread is created. Using the full constructor:

public Thread(ThreadGroup group, Runnable runnable, String threadName, long stackSize)

you can set the stack size up to 256KB.

So the strategy in your case would be to create a new thread with a deep stack, and run this parsing code on that thread.

fadden
  • 51,356
  • 5
  • 116
  • 166
0

Change your stack size by passing the following JVM argument:

-Xss128m

Since, you're XML file is large and the parser seems to be doing a recursion (probably because <SampleElem> can have <SampleElem> as a child) stack size needs to be increased. The default size is 512 KB only.

Note: If the parsing still fails with 128m; keep doubling the size (like 256m, then 512m etc.)

Ravi K Thapliyal
  • 51,095
  • 9
  • 76
  • 89
0

The most satisfactory solution in my case was rewrite my xml schema to linear structure. It reduced total memory requirements for deserializing tree.

Thanks all for comments.

asolovyov
  • 903
  • 1
  • 10
  • 21