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

uncaught exception during compilation: java.lang.AssertionError: assertion failed: value stubbing #6640

Closed
scabug opened this issue Nov 9, 2012 · 22 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Nov 9, 2012

Here's a compiler crasher reported on the Specs2 mailing list. I did not rule out the possibility of a dependency problem on specs2 RC2 artifact.

// build.sbt
scalaVersion := "2.10.0-RC2"

libraryDependencies += "org.specs2" % "specs2_2.10.0-RC2" % "1.12.2"

resolvers += "specs2-resolver-0" at "https://oss.sonatype.org/content/repositories/releases"
// src/test/scala/ResourceSpec.scala

import java.io.Closeable
import org.specs2.mock.Mockito
import org.specs2.mutable.Specification

class ResourceSpec extends Specification with Mockito {

  "a" should {
    "b" in {        
      val mockResource = mock[Closeable]
    }
  }
}

When one executes sbt test, it results in:


[error] 
[error]      while compiling: /home/dcs/tmp/crasher/src/test/scala/ResourceSpec.scala
[error]         during phase: typer
[error]      library version: version 2.10.0-RC2
[error]     compiler version: version 2.10.0-RC2
[error]   reconstructed args: -bootclasspath /usr/lib/jvm/jdk1.7.0_07/jre/lib/resources.jar:/usr/lib/jvm/jdk1.7.0_07/jre/lib/rt.jar:/usr/lib/jvm/jdk1.7.0_07/jre/lib/sunrsasign.jar:/usr/lib/jvm/jdk1.7.0_07/jre/lib/jsse.jar:/usr/lib/jvm/jdk1.7.0_07/jre/lib/jce.jar:/usr/lib/jvm/jdk1.7.0_07/jre/lib/charsets.jar:/usr/lib/jvm/jdk1.7.0_07/jre/lib/jfr.jar:/usr/lib/jvm/jdk1.7.0_07/jre/classes:/home/dcs/.sbt/boot/scala-2.10.0-RC2/lib/scala-library.jar -d /home/dcs/tmp/crasher/target/scala-2.10/test-classes -classpath /home/dcs/tmp/crasher/target/scala-2.10/test-classes:/home/dcs/tmp/crasher/target/scala-2.10/classes:/home/dcs/.ivy2/cache/org.specs2/specs2_2.10.0-RC2/jars/specs2_2.10.0-RC2-1.12.2.jar:/home/dcs/.ivy2/cache/org.specs2/specs2-scalaz-core_2.10.0-RC2/jars/specs2-scalaz-core_2.10.0-RC2-6.0.1.jar
[error] 
[error]   last tree to typer: Literal(Constant(a))
[error]               symbol: null
[error]    symbol definition: null
[error]                  tpe: String("a")
[error]        symbol owners: 
[error]       context owners: value <local ResourceSpec> -> class ResourceSpec -> package <empty>
[error] 
[error] == Enclosing template or block ==
[error] 
[error] Template( // val <local ResourceSpec>: <notype> in class ResourceSpec
[error]   "Specification", "Mockito" // parents
[error]   ValDef(
[error]     private
[error]     "_"
[error]     <tpt>
[error]     <empty>
[error]   )
[error]   // 2 statements
[error]   DefDef( // def <init>(): ResourceSpec in class ResourceSpec
[error]     <method>
[error]     "<init>"
[error]     []
[error]     List(Nil)
[error]     <tpt> // tree.tpe=ResourceSpec
[error]     Block( // tree.tpe=Unit
[error]       Apply( // def <init>(): Object in class Object, tree.tpe=Object
[error]         ResourceSpec.super."<init>" // def <init>(): Object in class Object, tree.tpe=()Object
[error]         Nil
[error]       )
[error]       ()
[error]     )
[error]   )
[error]   Apply(
[error]     "a"."should"
[error]     Apply(
[error]       "b"."in"
[error]       Block(
[error]         ValDef(
[error]           0
[error]           "mockResource"
[error]           <tpt>
[error]           TypeApply(
[error]             "mock"
[error]             "Closeable"
[error]           )
[error]         )
[error]         ()
[error]       )
[error]     )
[error]   )
[error] )
[error] 
[error] == Expanded type of tree ==
[error] 
[error] ConstantType(value = Constant(a))
[error] 
[error] uncaught exception during compilation: java.lang.AssertionError
java.lang.AssertionError: assertion failed: value stubbing
	at scala.reflect.internal.Types$ThisType.<init>(Types.scala:1388)
	at scala.reflect.internal.Types$UniqueThisType.<init>(Types.scala:1409)
	at scala.reflect.internal.Types$ThisType$.apply(Types.scala:1413)
	at scala.reflect.internal.pickling.UnPickler$Scan.readType(UnPickler.scala:330)
@scabug
Copy link
Author

scabug commented Nov 9, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6640?orig=1
Reporter: @dcsobral
Affected Versions: 2.10.0-RC2
Other Milestones: 2.10.0
Attachments:

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@gaydenko said:
Thanks to Daniel Sobral - he has directed me here as far as I have similar issue. Please look at

https://groups.google.com/forum/#!topic/scala-user/FHSlXMklNso

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@retronym said:
The cause of the problem is a missing JAR on the classpath.

If you move the mock call to the top level, you get a more accurate error message.

info] Compiling 1 Scala source to /Users/jason/code/scratch1/target/scala-2.10/classes...
[error] bad symbolic reference to class MockSettings in package mockito (a classfile may be missing)
[error] one error found

After adding the following:

libraryDependencies += "org.mockito" % "mockito-all" % "1.9.0"

Both the reduced and originally reported files compile successfully.

But no doubt we should issue this error in both cases. It will be interesting to piece together the circumstances that lead do that assertion error during unpickling.

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@dcsobral said:
Glad to know. Downgrade priority?

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@retronym said:
I'd still call it critical, this is a huge time waster for people. Not a blocker, although we have to see if Andrew's problem can be solved with an expanded classpath.

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@gaydenko said (edited on Nov 9, 2012 6:59:35 PM UTC):
I have attached AllBuild.scala sbt project file. Am not sure how to modify deps. Hints?

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@dcsobral said:
Just to make it clear to anyone browsing this ticket, it's not a matter of a "more helpful error message". The compiler crashes instead of producing an error message.

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@retronym said:
Andrew: Try this:

~/code/scratch1 diff -u AllBuild.scala AllBuild2.scala 
--- AllBuild.scala	2012-11-09 21:57:00.000000000 +0100
+++ AllBuild2.scala	2012-11-09 21:59:29.000000000 +0100
@@ -10,6 +10,7 @@
   private lazy val mailDep = "javax.mail" % "mail" % "1.4.5"
   private lazy val swingDep = "org.scala-lang" % "scala-swing" % scalaInUse
   private lazy val junitDep = "junit" % "junit" % "4.8.2"
+  private lazy val scalaActorDep = "org.scala-lang" % "scala-actors" % scalaInUse
 
   override lazy val settings = super.settings ++ Seq(
     scalaVersion := scalaInUse,
@@ -29,7 +30,7 @@
 
   lazy val  zgsLib = Project("zgs-lib", file("zgs-kit/zgs-lib")) settings(
     name := "zgs-lib",
-    libraryDependencies ++= Seq(swingDep, mailDep)
+    libraryDependencies ++= Seq(swingDep, mailDep, scalaActorDep)
   )

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@gaydenko said:
Modularization in practice :) Jason, thanks, it did. And it is funny I don't use actors. But use swing, and last one does use actors. Ugh..

Daniel, aha, any compiler exception is a compiler bug.

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@retronym said:
Andrew: It appears that the references from Scala Swing to scala.actor are really some historical hangover. I've created a ticket to either remove them or fix it's POM to declare a dependency.

Are you by any chance referring to scala.swing.SwingWorker in your code? I'd like to figure out specifically which class you're referring to that brings in this dependency.

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@gaydenko said (edited on Nov 9, 2012 10:02:20 PM UTC):
Jason, no, I don't use scala.swing.SwingWorker, but I have own internal wrapper around javax.swing.SwingWorker:

import javax.swing.SwingWorker
import scala.swing._
...

protected class SwiWorker[T](parent : Component, msg : String, job : => Answer[T], showPost : Boolean, 
                  postMsg : String, postJob : Answer[T] => Unit) extends SwingWorker[Answer[T],AnyRef] {
   ...
}

Probably this import list is dangerous at some point: scala.swing package contains SwingWorker also.

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@retronym said:
It would be super useful if you could reproduce the problem in a cut-down project with just that one file. I'm not sure how many problems we are really dealing with here.

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@gaydenko said:
Jason, sure! Just can't reduce yet. Will try further.

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@adriaanm said (edited on Nov 9, 2012 10:22:02 PM UTC):
when running under -Ydebug, I think this may be relevant:

[warn] creating stub symbol for value stubbing in package mockito (a classfile may be missing)

the assertion

java.lang.AssertionError: assertion failed: value stubbing
	at scala.reflect.internal.Types$ThisType.<init>(Types.scala:1388)

fails because we created a StubSymbol hoping that we could keep going a bit longer
except we shouldn't have

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@gaydenko said:
It is a minimal project. Commenting out of "import scala.swing._" eliminates the exception.

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@adriaanm said:
Thanks, Andrew. I think my comment above pinpoints the problem.

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@retronym said:
@andrew; Thanks for the project, that will help me figure whether the Swing to Actors dependency is intentional or an oversight.

@adriaan: I'd suspected that, but couldn't muster the right keywords to find the commit. (Even when the universe was handing it to me on a plate: OP's crasher failed at a package "java.lang.AssertionError: assertion failed: value stubbing"!)

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@adriaanm said:
Yeah, a StubSymbol called "stubbing"? You can't make that shit up.

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@retronym said (edited on Nov 9, 2012 11:00:24 PM UTC):
@andrew:

Indeed, scala-swing's dependency on scala-actors is an historical accident. I've raised #6441 to remedy this.

Rather than depending on that actors JAR, you could change your code from:

import scala.swing._
import javax.swing.SwingWorker

abstract class SwiWorker[T] extends SwingWorker[T,AnyRef] 

To:

import scala.swing._

abstract class SwiWorker[T] extends javax.swing.SwingWorker[T,AnyRef] 

This will stop the compiler from searching for SwingWorker under the wildcard import scala.swing._.

This would also work:

import scala.swing.{SwingWorker => _, _}
import javax.swing.SwingWorker

abstract class SwiWorker[T] extends SwingWorker[T,AnyRef] 

@scabug
Copy link
Author

scabug commented Nov 9, 2012

@gaydenko said:
Jason, thanks! FQN variant is closer to me :)

@scabug
Copy link
Author

scabug commented Nov 10, 2012

@retronym said:
scala/scala#1607

@scabug
Copy link
Author

scabug commented Nov 17, 2012

@som-snytt said:
I encountered this just doing a random test compile using the partest source, scalac -d junk $(find ./src/partest -name "*.scala"), without ant.jar. Thanks for the fix. I checked it out locally; is the reporting intended to be verbose (56 errors on PartestTask)?

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

2 participants