简体   繁体   English

从子类型到超类型的ClassCastException(在Scala中)

[英]ClassCastException from subtype to supertype (in scala)

We are encountering a strange error consistently only on one dev machine, for others it works fine (personally I cannot reproduce the issue): 我们仅在一台开发机上始终遇到一个奇怪的错误,对于其他开发机来说,它运行正常(我个人无法重现该问题):

Caused by: java.lang.ClassCastException: scala.collection.immutable.$colon$colon cannot be cast to scala.collection.Seq
    at scala.Option.map (Option.scala:163)
    at com.lightbend.lagom.maven.RunAllMojo.$anonfun$execute$15 (ServiceMojos.scala:402)

Seq is a linear supertype of :: ( $colon$colon ) per https://www.scala-lang.org/api/2.12.0/scala/collection/immutable/$colon$colon.html . Seq是每个https://www.scala-lang.org/api/2.12.0/scala/collection/immutable/$colon$colon.html::$colon$colon )的线性超类型。 We use Lagom 1.6.0-M2 for Java DSLs, with Scala 2.12. 我们将Lagom 1.6.0-M2用于Java DSL,并使用Scala 2.12。 Java version: Java版本:

openjdk version "1.8.0_212"
OpenJDK Runtime Environment Corretto-8.212.04.2 (build 1.8.0_212-b04)
OpenJDK 64-Bit Server VM Corretto-8.212.04.2 (build 25.212-b04, mixed mode)

It happens during lagom dev-server bootstrap. 它发生在lagom dev-server引导期间。 Purging and redownloading the maven repo (especially scala-lang and lagom deps) did not solve this problem, so this might not be due to a corrupted file. 清除并重新下载Maven存储库(尤其是scala-lang和lagom deps)不能解决此问题,因此这可能不是由于文件损坏引起的。

I diffed the scala jars on my machine with the ones on the bad machine, and they were the same. 我将机器上的scala jar与坏机器上的scala jar进行了比较,它们是相同的。

What could cause a ClassCastException from a subtype to supertype, where should we start to investigate this issue? 是什么可能导致ClassCastException从子类型变为超类型,我们应该从哪里开始研究此问题?

It was a classloader issue as Alexey said . 正如Alexey所说,这是一个类加载器问题。

The core problem was that a maven plugin used the <extensions>true</extensions> config, which messed up the classloaders somehow. 核心问题是一个maven插件使用了<extensions>true</extensions>配置,这以某种方式弄乱了类加载器。

The actual issue was fixed, removing the extension flag solved the problem: 实际问题已解决,删除扩展标记解决了该问题:

https://discuss.lightbend.com/t/java-lang-classcastexception-scala-collection-immutable-colon-colon-cannot-be-cast-to-scala-collection-seq-during-runall/4821/3 https://discuss.lightbend.com/t/java-lang-classcastexception-scala-collection-immutable-colon-colon-cannot-be-cast-to-scala-collection-seq-during-runall/4821/3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM