joy32812 / snakeyaml

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

Auto-generation of alias/anchor leads to unwanted recursion #173

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a Map<String,Map<String,Object>>() rootMap.
2. Create a second Map<String,Object)() enclosedMap.
3. make a value in the enclosedMap identical as one of key of the rootMap
Example : 
enclosedMap.put("world","test");
rootMap.put("test",enclosedMap);

4. dump the object with the options :
            yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
            yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

My representer only set custom value for 2 class, it don't touch on the map.

5. Reload the object, and you end with an infinite loop.

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

  test:
    world: 'test'

and I get 

  test: &id001
    world: *id001

What version of SnakeYAML are you using? On what Java version?

1.9 for SnakeYAML and 1.7 for Java.

Please provide any additional information below. (Often a failing test is
the best way to describe the problem.)

Original issue reported on code.google.com by antoin...@gmail.com on 29 Mar 2013 at 8:55

GoogleCodeExporter commented 9 years ago
I have just added a test based on your code: 
http://code.google.com/p/snakeyaml/source/detail?r=0a7263bcccbbad371c8c925cc0381
6c91010dfa7

As you can see, the code works as expected. The anchor is not created:
http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyam
l/issues/issue173/RecursiveAnchorTest.java

Please provide a test which gives more information.

Original comment by py4fun@gmail.com on 30 Mar 2013 at 8:22

GoogleCodeExporter commented 9 years ago
I don't understand what happened to make SnakeYaml add anchor like it did ...

I can send you a bunch of file that have been "corrupted" because of this, and 
I don't have any idea on how it did happen.

I can't even reproduce it. The more annoying it happened to the user of my 
application not in my test case. 

Could an heavy load generate that kind of error ?

My application is a plugin for Bukkit.

Original comment by antoin...@gmail.com on 30 Mar 2013 at 8:26

GoogleCodeExporter commented 9 years ago
Any load can not make such an error.
It may happen when the value is not a string (like "test"), but more complex 
(like a JavaBean). But this is again no bug.
Without a test we cannot do much here.
You probably have a lot of custom code (Representer, Constructor).

Original comment by py4fun@gmail.com on 30 Mar 2013 at 9:37

GoogleCodeExporter commented 9 years ago
Thi is my constructor : 
https://github.com/Belphemur/AdminCmd/blob/master/src/main/java/be/Balor/Tools/C
onfiguration/File/YamlConstructor.java

And this is my representer : 
https://github.com/Belphemur/AdminCmd/blob/master/src/main/java/be/Balor/Tools/C
onfiguration/File/ExtendedRepresenter.java

Original comment by antoin...@gmail.com on 30 Mar 2013 at 9:43

GoogleCodeExporter commented 9 years ago
This is a lot of code. You can try to remove the code (peace by peace) to 
identify the peace which causes the problem.

Original comment by py4fun@gmail.com on 31 Mar 2013 at 11:51

GoogleCodeExporter commented 9 years ago
The issue is closed because it cannot be reproduced

Original comment by py4fun@gmail.com on 10 Jul 2013 at 2:49