From 6a460c1fb245ebb1c29d121336c54692932b8e48 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 30 Dec 2015 01:34:45 +0100 Subject: [PATCH] Fix in ClasspathFilter --- .../scala/coursier/util/ClasspathFilter.scala | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/core/jvm/src/main/scala/coursier/util/ClasspathFilter.scala b/core/jvm/src/main/scala/coursier/util/ClasspathFilter.scala index 4f7cafe4a..7272a2723 100644 --- a/core/jvm/src/main/scala/coursier/util/ClasspathFilter.scala +++ b/core/jvm/src/main/scala/coursier/util/ClasspathFilter.scala @@ -84,9 +84,23 @@ class ClasspathFilter(parent: ClassLoader, classpath: Set[File], exclude: Boolea override def loadClass(className: String, resolve: Boolean): Class[_] = { - val c = super.loadClass(className, resolve) - if (fromClasspath(c)) c - else throw new ClassNotFoundException(className) + val c = + try super.loadClass(className, resolve) + catch { + case e: LinkageError => + // Happens when trying to derive a shapeless.Generic + // from an Ammonite session launched like + // ./coursier launch com.lihaoyi:ammonite-repl_2.11.7:0.5.2 + // For className == "shapeless.GenericMacros", + // the super.loadClass above - which would be filtered out below anyway, + // raises a NoClassDefFoundError. + null + } + + if (c != null && fromClasspath(c)) + c + else + throw new ClassNotFoundException(className) } override def getResource(name: String): URL = {