diff options
author | peterz <peterz@rambler.ru> | 2016-05-10 11:54:21 +0300 |
---|---|---|
committer | petermz <peter.zhelezniakov@gmail.com> | 2016-05-17 17:22:45 +0300 |
commit | 883fdd74d63a54495f4013eef81c9b5ebc850d1c (patch) | |
tree | 6c4d97ead6446ce0ebbe980980454ca3614f7523 | |
parent | 3ea78b7583a5b69065b532697372e669e4bbadce (diff) | |
download | scala-883fdd74d63a54495f4013eef81c9b5ebc850d1c.tar.gz scala-883fdd74d63a54495f4013eef81c9b5ebc850d1c.tar.bz2 scala-883fdd74d63a54495f4013eef81c9b5ebc850d1c.zip |
SI-5463 Check .jars before using them
Make broken JAR files on compiler classpath cause a fatal error
-rw-r--r-- | src/compiler/scala/tools/nsc/classpath/AggregateClassPath.scala | 12 | ||||
-rw-r--r-- | test/files/run/t5463.scala | 21 |
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 + } + } +} |