[java] record Closeable example from #49

Summary:
This previous FP does not occur anymore, make sure it doesn't regress.
https://github.com/facebook/infer/issues/49

Reviewed By: dulmarod

Differential Revision: D8442842

fbshipit-source-id: b3fde1ad1
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent f540aa47a3
commit 398e97183f

@ -10,6 +10,9 @@ package codetoanalyze.java.infer;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.Closeable; import java.io.Closeable;
import java.io.File;
import java.io.FileWriter;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.util.Map; import java.util.Map;
@ -219,4 +222,28 @@ public class CloseableAsResourceExample {
map.put(key, res); map.put(key, res);
} }
public static void closeCloseable(Closeable closeable) {
try {
if (closeable != null) {
closeable.close();
}
} catch (Exception ex) {}
}
public void finallyCloseOk(File file, String fileContent) {
if (!file.exists()) {
FileWriter writer = null;
try {
writer = new FileWriter(file);
writer.write(fileContent);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
closeCloseable(writer);
}
}
}
} }

Loading…
Cancel
Save