The Yaml.loadType(File ) API doesn't seem to close the file inputstream. So if you have code such as:
File myFile = new File("someYamlFile");
HashSet<String> foo = (HashSet<String>)Yaml.loadType(myFile, HashSet.class);
myFile.delete();
You will not able to remove the yamlFile until the program exits.
Logged In: YES
user_id=14058
Originator: NO
I concur. Something like this seems to work in the meantime:
YamlDecoder decoder = null;
try {
decoder = new YamlDecoder(new FileInputStream(getFile()));
myInstance = (MyType) decoder.readObjectOfType(MyType.class);
}
catch (IOException ioe) {
// handle exception..
}
finally {
if (decoder != null) {
decoder.close();
}
}
Better workaround:
try {
InputStream in = new BufferedInputStream ( new FileInputStream ( profileFile ) );
MyType mt = Yaml.loadType ( in, MyType.class );
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
The bug occurs in YamlConfig.loadType ( File, Class<T> ), which reads:
return loadType(new YamlDecoder(new FileInputStream(file), this), clazz)
but should look more like the code above.