Skip to content

Handle IOException when calling deleteIfExists #13791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions compiler/test/dotty/tools/dotc/classpath/MultiReleaseJarTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package dotty.tools.dotc.classpath

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

import java.io.ByteArrayOutputStream
import java.io.{ByteArrayOutputStream, IOException}
import java.nio.file.{FileSystems, Files, Path}
import java.util.jar.Attributes
import java.util.jar.Attributes.Name

import org.junit.Test
import org.junit.Assert._
import org.junit.Test

import scala.util.Properties
import scala.collection.JavaConverters._
import scala.util.Properties

class MultiReleaseJarTest extends dotty.tools.backend.jvm.DottyBytecodeTest {

@Test
def mrJar(): Unit = {
if (!Properties.isJavaAtLeast("9")) { println("skipping mrJar() on old JDK"); return }
Expand Down Expand Up @@ -61,7 +62,10 @@ class MultiReleaseJarTest extends dotty.tools.backend.jvm.DottyBytecodeTest {
if Properties.isJavaAtLeast("10") then
assertEquals(Set("foo1", "foo2", "bar1", "bar2"), apiMethods(jar3, "10"))
} finally
List(jar1, jar2, jar3).foreach(Files.deleteIfExists)
List(jar1, jar2, jar3).forall(path =>
try Files.deleteIfExists(path)
catch case _: IOException => false
)
}

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


private def createManifest = {
val manifest = new java.util.jar.Manifest()
manifest.getMainAttributes.put(Name.MANIFEST_VERSION, "1.0")
Expand All @@ -92,6 +95,7 @@ class MultiReleaseJarTest extends dotty.tools.backend.jvm.DottyBytecodeTest {
val manifestBytes = os.toByteArray
manifestBytes
}

private def createZip(zipLocation: Path, content: List[(String, Array[Byte])]): Unit = {
val env = new java.util.HashMap[String, String]()
Files.deleteIfExists(zipLocation)
Expand All @@ -113,4 +117,5 @@ class MultiReleaseJarTest extends dotty.tools.backend.jvm.DottyBytecodeTest {
zipfs.close()
}
}

}