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

script fails with AbstractMethodError after 1st successful run #8433

Closed
scabug opened this issue Mar 20, 2014 · 16 comments
Closed

script fails with AbstractMethodError after 1st successful run #8433

scabug opened this issue Mar 20, 2014 · 16 comments

Comments

@scabug
Copy link

scabug commented Mar 20, 2014

the following script succeeds once after being edited, but fails thereafter with java.lang.AbstractMethodError: Main$$anon$1$Strategy.updateRank(Ljava/lang/Object;Lscala/math/Numeric;)V

#!/bin/sh
exec scala "$0"
!#
Surf.main(args)

/** this trait compiled separately and added to the classpath:
trait Rankable {
  var rank:Double = 0.0
  import Numeric.Implicits._
  def updateRank[T:Numeric](r:T){ rank += r.toDouble }
}
*/

object Surf extends App {
  val strats = List[Strategy](Strategy("name1"))
  strats.sortBy { - _.score }.zipWithIndex.foreach { case (c,i) => c.updateRank(i) }
  strats.foreach { printf("%s\n",_) }
}

class Strategy(name:String) extends Rankable {
  import Strategy._
  def score = 1
  override def toString = "%4.2f: %s".format(rank,name)
}

object Strategy {
  def apply(name:String):Strategy = new Strategy(name)
}

If trait Rankable is uncommented, the script works fine every time.
A (bad performance) workaround is to pass -nc in the hash-bang section:

exec scala -nc "$0"

@scabug
Copy link
Author

scabug commented Mar 20, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8433?orig=1
Reporter: Phil Walker (philwalk9)
Affected Versions: 2.11.0-M7, 2.11.0-RC1
Attachments:

@scabug
Copy link
Author

scabug commented Mar 20, 2014

Phil Walker (philwalk9) said:
I listed this as Minor because there's a workaround, but it cost me half a day to track down the cause, and the workaround suffers from long launch delays, so it's not very usable.

@scabug
Copy link
Author

scabug commented Mar 20, 2014

Phil Walker (philwalk9) said:
The problem appears when running the script under Scala 2.11.0-RC1, whether the trait is compiled under 2.10.3 or 2.11.0-RC1.
The problem disappears under both scala versions if the trait is uncommented (ie. not separately compiled.)

@scabug
Copy link
Author

scabug commented Mar 20, 2014

@adriaanm said:
I can't reproduce with 2.11.0-RC1, tried both Java 6 and Java 7.
Can you provide step by step instructions, specifying exactly what the classpath was, and which classes were on it?

@scabug
Copy link
Author

scabug commented Mar 21, 2014

@som-snytt said:
And whether the test uses CLASSPATH or -cp. I also tried mixing 2.10 and 2.11.

@scabug
Copy link
Author

scabug commented Mar 21, 2014

Phil Walker (philwalk9) said (edited on Mar 21, 2014 7:21:15 PM UTC):
Thanks for looking into this!

The tarball I sent by email to Adrian contains all files needed to reproduce the problem.

It contains several required jar files, plus a scala script, and a shell script that creates the necessary command line.

The comments in testrun.sh explain usage, and testrun.sh also unsets CLASSPATH to reduce environment side-effects.

Here's my test command line (enforced by testrun.sh, but documented here as well):

scala -cp javaxt-core.jar:joda-convert-1.5.jar:joda-time-2.3.jar:nscala-time_2.10-0.8.0.jar:vbloo.jar ./abstractMethodBug.sc

abstractMethodBug.sc # the scala script
testrun.sh # wrapper to launch scala script

vbloo.jar
joda-time-2.3.jar
nscala-time_2.10-0.8.0.jar
joda-convert-1.5.jar
javaxt-core.jar

Let me know if I can assist further.

  • Phil

@scabug
Copy link
Author

scabug commented Mar 24, 2014

@adriaanm said:
Reproduction received via email from Phil.

@scabug
Copy link
Author

scabug commented Mar 24, 2014

@adriaanm said:
I can reproduce, and it does look like a bug in the compilation daemon.

@scabug
Copy link
Author

scabug commented May 7, 2014

Phil Walker (philwalk9) said:
FYI, this problem also exists with 2.11.0.
This affects several of my scripts, so please let me know if I can assist in any way.

@scabug
Copy link
Author

scabug commented May 8, 2014

@som-snytt said:
Nothing magical, but expressed as a partest DirectTest:
https://github.com/som-snytt/scala/blob/issue/8433-fsc/test/files/run/t8433.scala

@scabug
Copy link
Author

scabug commented May 9, 2014

@som-snytt said:
BTW, a workaround is to move the trait out of the object core and into a package.

@scabug
Copy link
Author

scabug commented May 9, 2014

Phil Walker (philwalk9) said:
ahh, thanks for the suggestion, I'll do that.

@scabug
Copy link
Author

scabug commented Aug 5, 2014

@gkossakowski said:
The 2.11.2 is out so I'm rescheduling the issue for 2.11.3.

@scabug
Copy link
Author

scabug commented Nov 4, 2014

@retronym said:
Updating fix-by version to 2.11.5.

@scabug
Copy link
Author

scabug commented Nov 13, 2016

@som-snytt said:
The passing partest scala/scala#5525

@scabug
Copy link
Author

scabug commented Nov 14, 2016

@lrytz said:
Seems to be fixed in 2.12.0 (scala/scala#5525)

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

1 participant