avoid resource leak upon write() exception (Coverity)
This commit is contained in:
parent
be0d6b3fce
commit
ba6c711e85
|
@ -30,7 +30,7 @@
|
|||
|
||||
package org.antlr.v4.runtime.misc;
|
||||
|
||||
import java.awt.Window;
|
||||
import java.awt.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.BufferedWriter;
|
||||
|
@ -94,8 +94,12 @@ public class Utils {
|
|||
public static void writeFile(String fileName, String content) throws IOException {
|
||||
FileWriter fw = new FileWriter(fileName);
|
||||
Writer w = new BufferedWriter(fw);
|
||||
w.write(content);
|
||||
w.close();
|
||||
try {
|
||||
w.write(content);
|
||||
}
|
||||
finally {
|
||||
w.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void waitForClose(final Window window) throws InterruptedException {
|
||||
|
|
|
@ -68,8 +68,12 @@ public class Trees {
|
|||
String ps = getPS(t, ruleNames, fontName, fontSize);
|
||||
FileWriter f = new FileWriter(fileName);
|
||||
BufferedWriter bw = new BufferedWriter(f);
|
||||
bw.write(ps);
|
||||
bw.close();
|
||||
try {
|
||||
bw.write(ps);
|
||||
}
|
||||
finally {
|
||||
bw.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void writePS(Tree t, @Nullable List<String> ruleNames, String fileName)
|
||||
|
|
Loading…
Reference in New Issue