From 370a4c55c6e31e4279191f9a14d542e24c6131be Mon Sep 17 00:00:00 2001 From: Ben Liblit Date: Sat, 5 Aug 2023 17:26:32 -0400 Subject: [PATCH] Ensure that a jar file is closed On Windows we get into trouble if this jar file is left open. Windows refuses to delete an open file, which then causes post-test `@TempDir` cleanup to fail. --- .../core/tests/shrike/FloatingPointsTest.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/src/test/java/com/ibm/wala/core/tests/shrike/FloatingPointsTest.java b/core/src/test/java/com/ibm/wala/core/tests/shrike/FloatingPointsTest.java index 9ec6a63241..260514fabb 100644 --- a/core/src/test/java/com/ibm/wala/core/tests/shrike/FloatingPointsTest.java +++ b/core/src/test/java/com/ibm/wala/core/tests/shrike/FloatingPointsTest.java @@ -150,16 +150,18 @@ public void emitTo(Output w) { } private void write() throws IllegalStateException, IOException, InvalidClassFileException { - // Write all modified classes - for (ClassInstrumenter ci2 : classInstrumenters) { - if (ci2.isChanged()) { - ClassWriter cw = ci2.emitClass(); - instrumenter.outputModifiedClass(ci2, cw); + try { + // Write all modified classes + for (ClassInstrumenter ci2 : classInstrumenters) { + if (ci2.isChanged()) { + ClassWriter cw = ci2.emitClass(); + instrumenter.outputModifiedClass(ci2, cw); + } } + } finally { + // Finally write the instrumented jar + instrumenter.close(); } - - // Finally write the instrumented jar - instrumenter.close(); } private void setValidationInstrumenter() throws IOException {