StackOverflowErrors are not debuggable

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

StackOverflowErrors are not debuggable

rsom@certifydatasystems.com
Hi,

This is my code:
import groovy.json.JsonBuilder

public class JsonSo {
  private static class Parent {
    List<Child> children = []
    String name
  }
  private static class Child {
    Parent parent
    String name
  }
  public static void main(String[] args) {
    def p = new Parent(name: 'Billy Ray')
    def c = new Child(name: 'Miley')
    p.children << c
    c.parent = p

    def j = new JsonBuilder(p)
    println j.toString()
  }
}

when I run it, I get a StackOverflowError, which is expected. However from the stack trace, I have no way of knowing which line in my code caused the SO to occur. Is there some flag I can set somewhere that makes it easier to debug these?

For keeping the mail sane, I'm not pasting the stacktrace.

R,
rahul

smime.p7s (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: StackOverflowErrors are not debuggable

Andrew Eisenberg
I don't know about any compiler flag, but I'd recommend just firing
this script up in your favorite IDE and setting a few breakpoints.
This should help you see what's going on.

On Thu, Apr 4, 2013 at 6:20 AM, Rahul Somasunderam
<[hidden email]> wrote:

> Hi,
>
> This is my code:
> import groovy.json.JsonBuilder
>
> public class JsonSo {
>   private static class Parent {
>     List<Child> children = []
>     String name
>   }
>   private static class Child {
>     Parent parent
>     String name
>   }
>   public static void main(String[] args) {
>     def p = new Parent(name: 'Billy Ray')
>     def c = new Child(name: 'Miley')
>     p.children << c
>     c.parent = p
>
>     def j = new JsonBuilder(p)
>     println j.toString()
>   }
> }
>
> when I run it, I get a StackOverflowError, which is expected. However from
> the stack trace, I have no way of knowing which line in my code caused the
> SO to occur. Is there some flag I can set somewhere that makes it easier to
> debug these?
>
> For keeping the mail sane, I'm not pasting the stacktrace.
>
> R,
> rahul

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: StackOverflowErrors are not debuggable

Andrey Bloschetsov
You have infinite loop, It looks like this (schematically):

print P {
  print children.each {
    print C {
      print parent {
        print children.each {
          print C {
            // etc
          }
        }
      }
    }
  }
}

2013/4/4 Andrew Eisenberg <[hidden email]>:

> I don't know about any compiler flag, but I'd recommend just firing
> this script up in your favorite IDE and setting a few breakpoints.
> This should help you see what's going on.
>
> On Thu, Apr 4, 2013 at 6:20 AM, Rahul Somasunderam
> <[hidden email]> wrote:
>> Hi,
>>
>> This is my code:
>> import groovy.json.JsonBuilder
>>
>> public class JsonSo {
>>   private static class Parent {
>>     List<Child> children = []
>>     String name
>>   }
>>   private static class Child {
>>     Parent parent
>>     String name
>>   }
>>   public static void main(String[] args) {
>>     def p = new Parent(name: 'Billy Ray')
>>     def c = new Child(name: 'Miley')
>>     p.children << c
>>     c.parent = p
>>
>>     def j = new JsonBuilder(p)
>>     println j.toString()
>>   }
>> }
>>
>> when I run it, I get a StackOverflowError, which is expected. However from
>> the stack trace, I have no way of knowing which line in my code caused the
>> SO to occur. Is there some flag I can set somewhere that makes it easier to
>> debug these?
>>
>> For keeping the mail sane, I'm not pasting the stacktrace.
>>
>> R,
>> rahul
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>



--
Andrey Bloschetsov

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email