Skip to content

Commit e403e15

Browse files
committed
handle IOException for deleteIfExists
1 parent 29f0374 commit e403e15

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

compiler/test/dotty/tools/dotc/classpath/MultiReleaseJarTest.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@ package dotty.tools.dotc.classpath
22

33
import dotty.tools.dotc.core.Contexts.Context
44

5-
import java.io.ByteArrayOutputStream
5+
import java.io.{ByteArrayOutputStream, IOException}
66
import java.nio.file.{FileSystems, Files, Path}
77
import java.util.jar.Attributes
88
import java.util.jar.Attributes.Name
99

10-
import org.junit.Test
1110
import org.junit.Assert._
11+
import org.junit.Test
1212

13-
import scala.util.Properties
1413
import scala.collection.JavaConverters._
14+
import scala.util.Properties
1515

1616
class MultiReleaseJarTest extends dotty.tools.backend.jvm.DottyBytecodeTest {
17+
1718
@Test
1819
def mrJar(): Unit = {
1920
if (!Properties.isJavaAtLeast("9")) { println("skipping mrJar() on old JDK"); return }
@@ -61,7 +62,10 @@ class MultiReleaseJarTest extends dotty.tools.backend.jvm.DottyBytecodeTest {
6162
if Properties.isJavaAtLeast("10") then
6263
assertEquals(Set("foo1", "foo2", "bar1", "bar2"), apiMethods(jar3, "10"))
6364
} finally
64-
List(jar1, jar2, jar3).foreach(Files.deleteIfExists)
65+
List(jar1, jar2, jar3).forall(path =>
66+
try Files.deleteIfExists(path)
67+
catch case _: IOException => false
68+
)
6569
}
6670

6771
@Test
@@ -82,7 +86,6 @@ class MultiReleaseJarTest extends dotty.tools.backend.jvm.DottyBytecodeTest {
8286
assertTrue(classExists("java.lang.invoke.LambdaMetafactory", "9"))
8387
}
8488

85-
8689
private def createManifest = {
8790
val manifest = new java.util.jar.Manifest()
8891
manifest.getMainAttributes.put(Name.MANIFEST_VERSION, "1.0")
@@ -92,6 +95,7 @@ class MultiReleaseJarTest extends dotty.tools.backend.jvm.DottyBytecodeTest {
9295
val manifestBytes = os.toByteArray
9396
manifestBytes
9497
}
98+
9599
private def createZip(zipLocation: Path, content: List[(String, Array[Byte])]): Unit = {
96100
val env = new java.util.HashMap[String, String]()
97101
Files.deleteIfExists(zipLocation)
@@ -113,4 +117,5 @@ class MultiReleaseJarTest extends dotty.tools.backend.jvm.DottyBytecodeTest {
113117
zipfs.close()
114118
}
115119
}
120+
116121
}

0 commit comments

Comments
 (0)