summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2013-08-27 18:42:57 -0700
committerGrzegorz Kossakowski <grzegorz.kossakowski@gmail.com>2013-08-27 18:42:57 -0700
commita24fc60deed8fbed062ecd6ff96e434349cca75d (patch)
tree73d82d5f0fe4794cf826efb4f1c8ed221a01b362
parent7817efe2468480317965fc5baece52be392f0f7a (diff)
parent5e8bc196cebcbaf86a63330cf0474909f72a6fe0 (diff)
downloadscala-a24fc60deed8fbed062ecd6ff96e434349cca75d.tar.gz
scala-a24fc60deed8fbed062ecd6ff96e434349cca75d.tar.bz2
scala-a24fc60deed8fbed062ecd6ff96e434349cca75d.zip
Merge pull request #2883 from retronym/topic/junit-zip-archive
A better diagnostic error for corrupt or missing JARs.
-rwxr-xr-xbuild.xml1
-rw-r--r--src/reflect/scala/reflect/io/ZipArchive.scala6
-rw-r--r--test/junit/scala/reflect/io/ZipArchiveTest.scala37
3 files changed, 43 insertions, 1 deletions
diff --git a/build.xml b/build.xml
index f428734ee0..3ab426b809 100755
--- a/build.xml
+++ b/build.xml
@@ -1560,6 +1560,7 @@ TODO:
<target name="test.junit" depends="test.junit.comp">
<stopwatch name="test.junit.timer"/>
<mkdir dir="${test.junit.classes}"/>
+ <echo message="Note: details of failed tests will be output to ${build-junit.dir}"/>
<junit fork="yes" haltonfailure="yes" printsummary="on">
<classpath refid="test.junit.compiler.build.path"/>
<batchtest fork="yes" todir="${build-junit.dir}">
diff --git a/src/reflect/scala/reflect/io/ZipArchive.scala b/src/reflect/scala/reflect/io/ZipArchive.scala
index eabf1dcbab..8260189459 100644
--- a/src/reflect/scala/reflect/io/ZipArchive.scala
+++ b/src/reflect/scala/reflect/io/ZipArchive.scala
@@ -126,7 +126,11 @@ abstract class ZipArchive(override val file: JFile) extends AbstractFile with Eq
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
final class FileZipArchive(file: JFile) extends ZipArchive(file) {
def iterator: Iterator[Entry] = {
- val zipFile = new ZipFile(file)
+ val zipFile = try {
+ new ZipFile(file)
+ } catch {
+ case ioe: IOException => throw new IOException("Error accessing " + file.getPath, ioe)
+ }
val root = new DirEntry("/")
val dirs = mutable.HashMap[String, DirEntry]("/" -> root)
val enum = zipFile.entries()
diff --git a/test/junit/scala/reflect/io/ZipArchiveTest.scala b/test/junit/scala/reflect/io/ZipArchiveTest.scala
new file mode 100644
index 0000000000..1bcd06f5a7
--- /dev/null
+++ b/test/junit/scala/reflect/io/ZipArchiveTest.scala
@@ -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))
+ }
+ }
+}