outputting empty map - throws exception

30 views
Skip to first unread message

Uday Bhaskar Sarma Seetamraju

unread,
May 16, 2019, 10:08:25 PM5/16/19
to yamlbeans-users

In my code, the final output can be an "EMPTY" LinkedHashMap (as in.. it was created as new LinkedHashMap<String,Object>() ).

Can the yamlbeans library handle "empty" LinkedHashMap, without throwing Exception?

______________________________________________________________________________

(My code's debug output line): final output is of type java.util.LinkedHashMap

(My code's debug output line): saving the final output= {}

(My code's debug output line): invoking writer.write()

(My code's debug output line): invoking writer.close()


com.esotericsoftware.yamlbeans.YamlException: Error writing YAML.

at com.esotericsoftware.yamlbeans.YamlWriter.writeInternal(YamlWriter.java:100)

at com.esotericsoftware.yamlbeans.YamlWriter.clearAnchors(YamlWriter.java:115)

at com.esotericsoftware.yamlbeans.YamlWriter.close(YamlWriter.java:124)

at org.ASUX.yaml.Cmd.main(Cmd.java:195)

Caused by: com.esotericsoftware.yamlbeans.emitter.EmitterException: Expected no event but found: <document start explicit='false' version='null' tags='null'>

at com.esotericsoftware.yamlbeans.emitter.Emitter$4.expect(Emitter.java:177)

at com.esotericsoftware.yamlbeans.emitter.Emitter.emit(Emitter.java:87)

at com.esotericsoftware.yamlbeans.YamlWriter.writeValue(YamlWriter.java:225)

at com.esotericsoftware.yamlbeans.YamlWriter.writeInternal(YamlWriter.java:97)

... 4 more


____________________________________________________________________________


The only configuration code I have is:-

            writer.getConfig().writeConfig.setWriteClassname(YamlConfig.WriteClassName.NEVER);


Also, 

Uday Bhaskar Sarma Seetamraju

unread,
May 16, 2019, 10:31:00 PM5/16/19
to yamlbeans-users
Found the root cause.
Multiple threads.
One thread invoked yamlwriter.close().
Another thread kept writing to yamlwriter .. without any errors.
Exception got thrown when yamlwriter.close() was invoked.

Fixed my code.
Works now.
Reply all
Reply to author
Forward
0 new messages