user3636050
user3636050

Reputation: 11

java.lang.StackOverFlow Exception

I have a wsdl file. I am parsing the wsdl file and storing the complex types in a map as key value pair. Key is the complex type name and value is an arraylist containing the elements under that particular complex type. A complex type can have another complex type as an element. This complex type has one more complex type and so on..For a large wsdl files, there are many complex types.I am iterating through this map and extracting the elements from it. While iterating, I am calling the same function recursively so that I can get all the elements for a complex type. While doing so, I am getting StackOverflow exception.

Please let me know how to resolve this stackoverflow exception. Is there any other way or solution to achieve the above desired result.

I also wanted to know whether there is a limitation for storing the elements in an arraylist.

Thanks & Regards, Gayatri Shinde

Upvotes: 1

Views: 74

Answers (2)

Fernando
Fernando

Reputation: 309

The arraylist is a heap structure, so the limit would be generally big. The stack is by default a reduced memory area, and you can fill it with the recursive calls. You could either re-design the algorithm not to be recusrive but iterative (keeping trace in a list or other heap structure of the tags you are working in, to simulate recusion) or you could increase your stack size for your application (I think there is an option for than as a parameter to the java interpreter executable)

Upvotes: 1

metacubed
metacubed

Reputation: 7271

I cannot get much of a context from your question, but here's a guess. If one of your complex types A refers to another complex type B, which, some levels down, again refers to A, then the recursive function will keep getting called infinitely. This causes the stack overflow exception.

A -> S -> D -> A -> S -> D -> ......

One possible solution would be to keep a list of already processed types, and then check that list before calling the recursive function on the type.

Upvotes: 1

Related Questions