Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A better diagnostic error for corrupt or missing JARs.
Augment the IOException with the name of the file we're trying to open. Motivated by a troubleshooting session with partial downloads of JARs from Maven central breaking the Scala build on Martin's laptop. The test case only tests our part of the error message, so as not to be platform / JDK specific. Otherwise, it would check that the correct cause exception was present and accounted for.
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package scala.reflect.io | ||
|
||
import java.io.{IOException, File => JFile} | ||
import org.junit.Assert._ | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.JUnit4 | ||
|
||
@RunWith(classOf[JUnit4]) | ||
class ZipArchiveTest { | ||
|
||
@Test | ||
def corruptZip { | ||
val f = JFile.createTempFile("test", ".jar") | ||
val fza = new FileZipArchive(f) | ||
try { | ||
fza.iterator | ||
} catch { | ||
case x: IOException => | ||
assertTrue(x.getMessage, x.getMessage.contains(f.getPath)) | ||
} finally { | ||
f.delete() | ||
} | ||
} | ||
|
||
@Test | ||
def missingFile { | ||
val f = new JFile("xxx.does.not.exist") | ||
val fza = new FileZipArchive(f) | ||
try { | ||
fza.iterator | ||
} catch { | ||
case x: IOException => | ||
assertTrue(x.getMessage, x.getMessage.contains(f.getPath)) | ||
} | ||
} | ||
} |