0

I have a Java project which is building in SBT under JDK7. When I switch the JDK to JDK8 (SBT runs under JDK8 and targets JDK8 bytecode), I get an error which, whilst emitting from SBT's incremental compiler, seems to emananate from a call to Class.getDeclaredMethods on one of the already-compiled classes. Note, the source is 1.7-compatible source code in either case. I have made no changes to the source code

SBT version 0.13.5 and JDK 1.8.0_05

I reproduce the stack trace below. It's completely reproducible but is "odd" from a few angles. I mention these as they might help investigate the problem.

  • I have created a class which calls Class.forName on the "offending" class and calls getDeclaredMethods. This works - there is no obvious issue with the .class file

  • I presume due to some issue with SBT caching its internal analysis, certain sequences of commands work:

Example 1:

ptp-server> clean
ptp-server> compile //this will fail

Example 2:

ptp-server> clean
ptp-server> compile //This will fail
ptp-server> compile //This then works

Example 3:

ptp-server> clean
ptp-server> compile //This will fail
ptp-server> clean
ptp-server> compile //This then works

Here's the stack trace:

java.lang.VerifyError: Bad local variable type
Exception Details:
  Location:
    gsa/jerusalem/naming/ptp/PTPServerEodPositionHelper.fillResponse(Lgsa/jerusalem/protocol/ptp/PTPResponse;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lgsa/jerusalem/protocol/ptp/PTPCommand;Ljava/lang/String;)V @73: aload
  Reason:
    Type top (current frame, locals[7]) is not assignable to reference type
  Current Frame:
    bci: @73
    flags: { }
    locals: { 'gsa/jerusalem/naming/ptp/PTPServerEodPositionHelper', 'gsa/jerusalem/protocol/ptp/PTPResponse', 'java/lang/String', 'java/lang/String', 'java/lang/String', 'gsa/jerusalem/protocol/ptp/PTPCommand', 'java/lang/String', top, '[Ljava/lang/String;', 'java/lang/String', 'gsa/shared/datetime/XDate' }
stack: { 'java/util/logging/Logger', 'java/lang/String', '[Ljava/lang/Object;', '[Ljava/lang/Object;', integer }

...

at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2688)
    at java.lang.Class.getDeclaredMethods(Class.java:1962)
    at sbt.ClassToAPI$.structure(ClassToAPI.scala:72)
    at sbt.ClassToAPI$.x$2$lzycompute$1(ClassToAPI.scala:61)
    at sbt.ClassToAPI$.x$2$1(ClassToAPI.scala:61)
    at sbt.ClassToAPI$.instance$lzycompute$1(ClassToAPI.scala:61)
    at sbt.ClassToAPI$.sbt$ClassToAPI$$instance$1(ClassToAPI.scala:61)
    at sbt.ClassToAPI$$anonfun$5.apply(ClassToAPI.scala:62)
    at sbt.ClassToAPI$$anonfun$5.apply(ClassToAPI.scala:62)
    at xsbti.SafeLazy$Impl._t$lzycompute(SafeLazy.scala:18)
    at xsbti.SafeLazy$Impl._t(SafeLazy.scala:16)
    at xsbti.SafeLazy$Impl.get(SafeLazy.scala:22)
    at sbt.ClassToAPI$$anonfun$process$1.apply(ClassToAPI.scala:21)
    at sbt.ClassToAPI$$anonfun$process$1.apply(ClassToAPI.scala:21)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
    at scala.collection.mutable.ListBuffer.foreach(ListBuffer.scala:45)
    at sbt.ClassToAPI$.process(ClassToAPI.scala:21)
    at sbt.compiler.AggressiveCompile$$anonfun$3.sbt$compiler$AggressiveCompile$$anonfun$$readAPI$1(AggressiveCompile.scala:127)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2$$anonfun$apply$mcV$sp$2$$anonfun$apply$6.apply(AggressiveCompile.scala:135)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2$$anonfun$apply$mcV$sp$2$$anonfun$apply$6.apply(AggressiveCompile.scala:135)
    at sbt.classfile.Analyze$$anonfun$apply$9.apply(Analyze.scala:42)
    at sbt.classfile.Analyze$$anonfun$apply$9.apply(Analyze.scala:41)
    at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:772)
    at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:98)
    at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:98)
    at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala:226)
    at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:39)
    at scala.collection.mutable.HashMap.foreach(HashMap.scala:98)
    at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:771)
    at sbt.classfile.Analyze$.apply(Analyze.scala:41)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2$$anonfun$apply$mcV$sp$2.apply(AggressiveCompile.scala:135)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2$$anonfun$apply$mcV$sp$2.apply(AggressiveCompile.scala:133)
    at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:772)
    at scala.collection.immutable.List.foreach(List.scala:318)
    at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:771)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2.apply$mcV$sp(AggressiveCompile.scala:133)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2.apply(AggressiveCompile.scala:133)
    at sbt.compiler.AggressiveCompile$$anonfun$3$$anonfun$compileJava$1$2.apply(AggressiveCompile.scala:133)
    at sbt.compiler.AggressiveCompile.sbt$compiler$AggressiveCompile$$timed(AggressiveCompile.scala:162)
    at sbt.compiler.AggressiveCompile$$anonfun$3.compileJava$1(AggressiveCompile.scala:132)
    at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:139)
    at sbt.compiler.AggressiveCompile$$anonfun$3.apply(AggressiveCompile.scala:86)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:38)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:36)
    at sbt.inc.IncrementalCommon.cycle(IncrementalCommon.scala:31)
    at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:39)
    at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:38)
    at sbt.inc.Incremental$.manageClassfiles(Incremental.scala:66)
    at sbt.inc.Incremental$.compile(Incremental.scala:38)
    at sbt.inc.IncrementalCompile$.apply(Compile.scala:26)
    at sbt.compiler.AggressiveCompile.compile2(AggressiveCompile.scala:153)
    at sbt.compiler.AggressiveCompile.compile1(AggressiveCompile.scala:70)
    at sbt.compiler.AggressiveCompile.apply(AggressiveCompile.scala:45)
    at sbt.Compiler$.apply(Compiler.scala:74)
    at sbt.Compiler$.apply(Compiler.scala:65)
    at sbt.Defaults$.sbt$Defaults$$compileTaskImpl(Defaults.scala:773)
    at sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:765)
    at sbt.Defaults$$anonfun$compileTask$1.apply(Defaults.scala:765)
    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:744)
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449

1 Answers1

0

Maybe, your files are encoded by UTF-8 with BOM header. Drop BOM and then retry.

L.Ben
  • 13
  • 2