Skip to content

Commit

Permalink
Merge pull request #473 from ravwojdyla/fix_classnotfound
Browse files Browse the repository at this point in the history
Fix sbt/sbt#3736. Recurse into classloader of the class not the root
  • Loading branch information
eed3si9n authored Dec 22, 2017
2 parents e943e7f + c45d75a commit 84a5ed1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ compilation works in 1.0.
Guides:

* [Understanding Incremental Recompilation](http://www.scala-sbt.org/0.13/docs/Understanding-Recompilation.html).
* [Scala Lang blog post on Zinc release](https://www.scala-lang.org/blog/2017/01/03/zinc-blog-post.html).
* [Scala Lang blog post on Zinc release](https://www.scala-lang.org/blog/2017/11/03/zinc-blog-1.0.html).
* All the issues and PRs labelled as `docs` will help you understand different
aspects of Zinc. They both count with concrete information that are helpful
to understand tradeoffs and implementation details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ final class ClasspathFilter(parent: ClassLoader, root: ClassLoader, classpath: S
}

@tailrec private[this] def includeLoader(c: ClassLoader, base: ClassLoader): Boolean =
(base ne null) && (
(c eq base) || includeLoader(c, base.getParent)
)
(base ne null) &&
(c ne null) &&
((c eq base) || includeLoader(c.getParent, base))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ final class IncHandler(directory: File, cacheDir: File, scriptedLog: ManagedLogg
val analysis = p.compile(i)
p.discoverMainClasses(Some(analysis.apis)) match {
case Seq(mainClassName) =>
val classpath = i.si.allJars :+ p.classesDir
val classpath: Array[File] = (i.si.allJars :+ p.classesDir) map { _.getAbsoluteFile }
val loader = ClasspathUtilities.makeLoader(classpath, i.si, directory)
val main = p.getMainMethod(mainClassName, loader)
p.invokeMain(loader, main, params)
Expand Down
10 changes: 10 additions & 0 deletions zinc/src/sbt-test/general/classpath-filter/A.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// https://github.com/sbt/sbt/issues/3736
// https://github.com/raboof/sbt-run-classloading/blob/master/src/main/scala/Main.scala
object Main extends App {
Class.forName("scala.Int")

val classLoader = Option(Thread.currentThread.getContextClassLoader).get
Class.forName("scala.Int", true, classLoader)

Class.forName("scala.Int", false, classLoader)
}
1 change: 1 addition & 0 deletions zinc/src/sbt-test/general/classpath-filter/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> run

0 comments on commit 84a5ed1

Please sign in to comment.