UcasRichard / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
0 stars 0 forks source link

Problems with recursive links when included in an array #63

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
An exception is thrown when trying to load a serialized JavaBean of a
class that contains an array of objects that link back to the bean,
like this:

        public static class Human_WithArrayOfChildren extends AbstractHuman {
                ...
                protected Human_WithArrayOfChildren[] children;

                public Human_WithArrayOfChildren() {
                        children = new Human_WithArrayOfChildren[0];
                }
                ...

                public Human_WithArrayOfChildren[] getChildren() {
                        return children;
                }

                public void setChildren(Human_WithArrayOfChildren[] children) {
                        this.children = children;
                }
        }

(based on the sample code from specification/recursive/Human3.java)

Full test case attached.

Udo

Original issue reported on code.google.com by usnakey...@wegwerfemail.de on 15 Apr 2010 at 11:04

Attachments:

GoogleCodeExporter commented 9 years ago
Since I never use arrays they are not always well covered by tests.

I have started to fix the issue:
http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyam
l/recursive/Human_WithArrayOfChildrenTest.java

As you can see the children array is incomplete. The TODO in line 148 shows 
that one
of the children is missing.
Do you may be have an idea ?

Original comment by aso...@gmail.com on 15 Apr 2010 at 1:20

GoogleCodeExporter commented 9 years ago
I made a clone for this issue since I did not want to push to master :)

Here is changeset:
http://code.google.com/r/alexandermaslov-issue-63/source/detail?r=9a5454ef5687af
d0974e17e04921f24e2f4508cb

main change is : arrays created as arrays straightaway. Not like default 
sequence and after toArray.
so please review those changes. And may be we could use them. Maybe more Array 
oriented tests needed.
All existing seems to pass ;)

Original comment by alexande...@gmail.com on 15 Apr 2010 at 5:31

GoogleCodeExporter commented 9 years ago
Many thanks Alex! Well done!

The fix will be delivered in version 1.7

Original comment by aso...@gmail.com on 15 Apr 2010 at 6:02