Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not initialize class org.jacoco.core.internal.flow.ClassProbesAdapter #42

Open
stanch opened this issue Dec 19, 2014 · 2 comments

Comments

@stanch
Copy link

stanch commented Dec 19, 2014

Hi,

I’m having trouble running jacoco in my project. Here is the trace from last myProject/jacoco:fullClasspath:

java.lang.NoClassDefFoundError: Could not initialize class org.jacoco.core.internal.flow.ClassProbesAdapter
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:81)
    at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:122)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:49)
    at de.johoop.jacoco4sbt.Instrumentation$$anonfun$instrumentAction$3.apply(Instrumentation.scala:46)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    at scala.collection.AbstractTraversable.map(Traversable.scala:105)
    at de.johoop.jacoco4sbt.Instrumentation$class.instrumentAction(Instrumentation.scala:46)
    at de.johoop.jacoco4sbt.JacocoPlugin$jacoco$.instrumentAction(JacocoPlugin.scala:59)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at de.johoop.jacoco4sbt.JacocoPlugin$SharedSettings$$anonfun$settings$5.apply(JacocoPlugin.scala:84)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:35)
    at scala.Function6$$anonfun$tupled$1.apply(Function6.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:235)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

The project aggregates several subprojects, and I get this same error whether the settings are applied to it or just to a single subproject. The settings revelant for tests look like this:

val testSettings = Seq(Test, jacoco.Config).flatMap { conf =>
  Seq(
    parallelExecution in conf := false,
    fork in conf := true,
    javaOptions in conf += "-Xmx2g",
    javaOptions in conf += "-javaagent:" + (dependencyClasspath in Test).value
      .files.find(_.name.endsWith(s"jmockit-${Versions.JMockit}.jar")).get,
    testOptions in conf += Tests.Argument(
      TestFrameworks.JUnit, "--ignore-runners=org.scalatest.junit.JUnitRunner"
    )
  )
} ++ jacoco.settings ++ Seq(
  ScoverageSbtPlugin.ScoverageKeys.coverageHighlighting := false,

  libraryDependencies ++= Seq(
    "org.scalatest" %% "scalatest" % "1.9.2" % "test",
    "de.bwaldvogel" % "mongo-java-server" % "1.2.0" % "test",
    "org.jmockit" % "jmockit" % Versions.JMockit % "test",
    "com.novocode" % "junit-interface" % "0.11" % "test",
    "junit" % "junit" % "4.11" % "test"
  )
)
@peter-fu
Copy link

I guess it might be related to this because of our similar exception stack trace.
jacoco/jacoco#177

@margussipria
Copy link

Just managed to get this same error after upgrading from 3.1.0 to 3.2.0. No info what causes it.

[info] Instrumenting 11 classes to /home/margus.sipria/workspace/project/app/macros/target/scala-2.12/jacoco/instrumented-classes
[debug] instrumenting products: /home/margus.sipria/workspace/project/app/macros/target/scala-2.12/classes
[debug] Found jacoco agent: Vector()
[debug] instrumenting /home/margus.sipria/workspace/project/app/macros/target/scala-2.12/classes/macros/CopyWithId$$typecreator2$1.class
[error] java.lang.NoClassDefFoundError: Could not initialize class org.jacoco.core.internal.flow.ClassProbesAdapter
[error] 	at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:100)
[error] 	at org.jacoco.core.instr.Instrumenter.instrument(Instrumenter.java:123)

There are several files that give this error, but this is one of them:

package macros

import scala.language.experimental.macros

object CopyWithId {
  import scala.reflect.macros.whitebox

  def withId[T, I](entity: T, id: I): T = macro withIdImpl[T, I]

  def withIdImpl[T: c.WeakTypeTag, I: c.WeakTypeTag](c: whitebox.Context)(entity: c.Expr[T], id: c.Expr[I]): c.Expr[T] = {
    import c.universe._

    val tree = reify(entity.splice).tree
    val copy = entity.actualType.member(TermName("copy"))

    copy match {
      case s: MethodSymbol if s.paramLists.flatten.map(_.name).contains(TermName("id")) =>
        c.Expr[T](
          Apply(
            Select(tree, copy),
            AssignOrNamedArg(Ident(TermName("id")), reify(id.splice).tree) :: Nil
          )
        )
      case _ => c.abort(c.enclosingPosition, "No eligible copy method!")
    }
  }
}

Manually upgrading to 0.8.4 resolves problem for me.

add this to project/plugins.sbt after addSbtPlugin("com.github.sbt" % "sbt-jacoco" % "3.2.0")

libraryDependencies ++= Seq(
  "org.jacoco"                  %  "org.jacoco.core"      % "0.8.4",
  "org.jacoco"                  %  "org.jacoco.report"    % "0.8.4",
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants