我有一个 Java 项目,它在JDK7下的SBT中构建。当我将JDK切换到JDK8(SBT在JDK8下运行并且以JDK8字节码为目标)时,我得到一个错误,虽然从SBT的增量编译器中发出,但似乎从一个调用Class.getDeclaredMethods
上发出错误。 已编译的类。注意,在任何一种情况下,源都是1.7兼容的源代码。 我没有对源代码进行任何更改
SBT版本0.13.5和JDK 1.8.0_05
我重现下面的堆栈跟踪。它完全可以重复,但是很奇怪"从几个角度来看。我提到这些可能有助于调查问题。
我创建了一个在{34}犯罪"上调用Class.forName
的类。类和调用getDeclaredMethods
。这有效 - .class
文件没有明显的问题
我认为由于SBT缓存其内部分析的某些问题,某些命令序列有效:
示例1:
ptp-server> clean
ptp-server> compile //this will fail
示例2:
ptp-server> clean
ptp-server> compile //This will fail
ptp-server> compile //This then works
示例3:
ptp-server> clean
ptp-server> compile //This will fail
ptp-server> clean
ptp-server> compile //This then works
这是堆栈跟踪:
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)
答案 0 :(得分:0)
也许,您的文件由带有BOM头的UTF-8编码。删除BOM,然后重试。