nlight-jdev / jcouchdb

Automatically exported from code.google.com/p/jcouchdb
Other
0 stars 0 forks source link

Domain classes defined in Groovy cause stack overflow #30

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Apparently Domain classes defined in Groovy cause stack overflow, possibly due 
to the 
"metaClass" properties added by Groovy.

What steps will reproduce the problem?
1. Create a class in Groovy, for example:

class Example implements Serializable {

    private String key
    private String revision

    @json (value = '_id', ignoreIfNull = true)
    public String getKey() { key }
    public void setKey(String key) { this.key = key }

    @json (value = '_rev', ignoreIfNull = true)
    public String getRevision() { revision }
    public void setRevision(String revision) { this.revision = revision }

    boolean equals(o) {
        if (this.is(o)) return true
        if (!(o instanceof Example)) return false
        return key ? key == o.key : o.key == null
    }

    int hashCode() { key ? key.hashCode() : 0 }
}

2. When mapping to JSON, will see the stacktrace below

What is the expected output? What do you see instead?

java.lang.StackOverflowError
    at java.util.HashMap$EntryIterator.<init>(HashMap.java:832)
    at java.util.HashMap$EntryIterator.<init>(HashMap.java:832)
    at java.util.HashMap.newEntryIterator(HashMap.java:846)
    at java.util.HashMap$EntrySet.iterator(HashMap.java:950)
    at java.util.Collections$SynchronizedCollection.iterator(Collections.java:1573)
    at org.svenson.JSON.getJSONifierForClass(JSON.java:472)
    at org.svenson.JSON.dumpObject(JSON.java:333)
    at org.svenson.JSON.dumpObject(JSON.java:428)
    at org.svenson.JSON.dumpObject(JSON.java:428)
    at org.svenson.JSON.dumpObject(JSON.java:428)
    at org.svenson.JSON.dumpObject(JSON.java:428)

What version of the product are you using? On what operating system?

Svenson 1.3.5
Mac OS X, 10.6

Original issue reported on code.google.com by 7za...@gmail.com on 17 Nov 2009 at 6:57

GoogleCodeExporter commented 8 years ago
This is caused by the self-referencing nature of meta classes in groovy and best
solved by setting default ignore properties.

Svenson bug report:  http://code.google.com/p/svenson/issues/detail?id=6&can=1

Solution for that:
http://fforw.de/static/svenson-javadoc/org/svenson/JSON.html#setIgnoredPropertie
s%28java.util.Collection%29

Original comment by ff...@gmx.de on 17 Nov 2009 at 7:43

GoogleCodeExporter commented 8 years ago
closed because of working solution and general groovy support being too special 
for
standard behaviour

Original comment by ff...@gmx.de on 24 Feb 2010 at 3:59