summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@typesafe.com>2016-05-23 15:50:29 +0200
committerLukas Rytz <lukas.rytz@typesafe.com>2016-05-23 15:50:29 +0200
commit8e92ba0eb8c1e651c56493d00bc478ae7a3e9f39 (patch)
treea75c79945455e381f73016fac52c060051e23757
parent95f57600a7498f269d32743788c89d4d65f93700 (diff)
parent883fdd74d63a54495f4013eef81c9b5ebc850d1c (diff)
downloadscala-8e92ba0eb8c1e651c56493d00bc478ae7a3e9f39.tar.gz
scala-8e92ba0eb8c1e651c56493d00bc478ae7a3e9f39.tar.bz2
scala-8e92ba0eb8c1e651c56493d00bc478ae7a3e9f39.zip
Merge pull request #5153 from petermz/ticket/5463
SI-5463 Check .jars before using them
-rw-r--r--src/compiler/scala/tools/nsc/classpath/AggregateClassPath.scala12
-rw-r--r--test/files/run/t5463.scala21
2 files changed, 32 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/classpath/AggregateClassPath.scala b/src/compiler/scala/tools/nsc/classpath/AggregateClassPath.scala
index 6b435542a3..a1af3413ea 100644
--- a/src/compiler/scala/tools/nsc/classpath/AggregateClassPath.scala
+++ b/src/compiler/scala/tools/nsc/classpath/AggregateClassPath.scala
@@ -6,6 +6,7 @@ package scala.tools.nsc.classpath
import java.net.URL
import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer
+import scala.reflect.internal.FatalError
import scala.reflect.io.AbstractFile
import scala.tools.nsc.util.ClassPath
import scala.tools.nsc.util.ClassRepresentation
@@ -72,7 +73,16 @@ case class AggregateClassPath(aggregates: Seq[ClassPath]) extends ClassPath {
getDistinctEntries(_.sources(inPackage))
override private[nsc] def list(inPackage: String): ClassPathEntries = {
- val (packages, classesAndSources) = aggregates.map(_.list(inPackage)).unzip
+ val (packages, classesAndSources) = aggregates.map { cp =>
+ try {
+ cp.list(inPackage)
+ } catch {
+ case ex: java.io.IOException =>
+ val e = new FatalError(ex.getMessage)
+ e.initCause(ex)
+ throw e
+ }
+ }.unzip
val distinctPackages = packages.flatten.distinct
val distinctClassesAndSources = mergeClassesAndSources(classesAndSources: _*)
ClassPathEntries(distinctPackages, distinctClassesAndSources)
diff --git a/test/files/run/t5463.scala b/test/files/run/t5463.scala
new file mode 100644
index 0000000000..30b8306156
--- /dev/null
+++ b/test/files/run/t5463.scala
@@ -0,0 +1,21 @@
+import scala.reflect.internal.FatalError
+import scala.tools.partest.DirectTest
+
+object Test extends DirectTest {
+
+ def code = "class A"
+
+ override def show(): Unit = {
+ // Create a broken JAR file and put it on compiler classpath
+ val jarpath = testOutput.path + "/notajar.jar"
+ scala.reflect.io.File(jarpath).writeAll("This isn't really a JAR file")
+
+ val classpath = List(sys.props("partest.lib"), jarpath, testOutput.path) mkString sys.props("path.separator")
+ try {
+ compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(code)
+ throw new Error("Compilation should have failed");
+ } catch {
+ case ex: FatalError => // this is expected
+ }
+ }
+}