Use try-with-resources instead of manual try/finally
This commit is contained in:
@@ -77,15 +77,11 @@ public class DxChecker {
|
||||
|
||||
private static String generateExceptionMessage(Throwable e) {
|
||||
StringWriter writer = new StringWriter();
|
||||
PrintWriter printWriter = new PrintWriter(writer);
|
||||
try {
|
||||
try (PrintWriter printWriter = new PrintWriter(writer)) {
|
||||
e.printStackTrace(printWriter);
|
||||
String stackTrace = writer.toString();
|
||||
Matcher matcher = STACK_TRACE_PATTERN.matcher(stackTrace);
|
||||
return matcher.replaceAll("");
|
||||
}
|
||||
finally {
|
||||
printWriter.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.util.ArrayUtil;
|
||||
import kotlin.text.StringsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -185,8 +186,7 @@ public final class InTextDirectivesUtils {
|
||||
List<String> result = new ArrayList<String>();
|
||||
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new StringReader(fileText));
|
||||
try {
|
||||
try (BufferedReader reader = new BufferedReader(new StringReader(fileText))) {
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
@@ -198,11 +198,10 @@ public final class InTextDirectivesUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} catch(IOException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw ExceptionUtilsKt.rethrow(e);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -812,8 +812,8 @@ public class KotlinTestUtils {
|
||||
private static boolean compileJavaFiles(@NotNull Collection<File> files, List<String> options, @Nullable File javaErrorFile) throws IOException {
|
||||
JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
|
||||
DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<JavaFileObject>();
|
||||
StandardJavaFileManager fileManager = javaCompiler.getStandardFileManager(diagnosticCollector, Locale.ENGLISH, Charset.forName("utf-8"));
|
||||
try {
|
||||
try (StandardJavaFileManager fileManager =
|
||||
javaCompiler.getStandardFileManager(diagnosticCollector, Locale.ENGLISH, Charset.forName("utf-8"))) {
|
||||
Iterable<? extends JavaFileObject> javaFileObjectsFromFiles = fileManager.getJavaFileObjectsFromFiles(files);
|
||||
|
||||
JavaCompiler.CompilationTask task = javaCompiler.getTask(
|
||||
@@ -832,8 +832,6 @@ public class KotlinTestUtils {
|
||||
assertEqualsToFile(javaErrorFile, errorsToString(diagnosticCollector, false));
|
||||
}
|
||||
return success;
|
||||
} finally {
|
||||
fileManager.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user