如何调试scalajs链接器错误:不存在的方法java.lang.Class.getDeclaredFields

时间:2016-05-10 06:06:12

标签: scala linker scala.js

将以下方法添加到将案例类映射到Mapjs.Dictionary 后 - 我现在尝试了以下五种或六种变体 - 我的代码编译正常且没有警告,但随后在fastOptJS sjs链接阶段遇到错误。

方法

  def ccToMap(cc: AnyRef) =
    (Map[String, Any]() /: cc.getClass.getDeclaredFields) {
      (a, f) =>
        f.setAccessible(true)
        a + (f.getName -> f.get(cc))
    }

请注意,我尝试的所有变体都以略微不同的方式做同样的事情。

错误

 [info] Fast optimizing /Users/justin/Desktop/arete/jt/client/target/scala-2.11/client-fastopt.js
 [error] Referring to non-existent class java.lang.reflect.Field
 [error]   called from com.jshin47.jtdc.client.module.visualization.DiodeStateVizC$.ccToMap(java.lang.Object)scala.collection.immutable.Map
 [error]   called from com.jshin47.jtdc.client.module.visualization.DiodeStateVizC$.<init>()
 [error]   called from com.jshin47.jtdc.client.module.landing.LandingLocC$$anonfun$2.apply(japgolly.scalajs.react.extra.router.RouterCtl)japgolly.scalajs.react.ReactElement
 [error]   called from com.jshin47.jtdc.client.module.landing.LandingLocC$$anonfun$2.apply(java.lang.Object)java.lang.Object
 [error]   called from scala.collection.LinearSeqOptimized$class.foreach(scala.collection.LinearSeqOptimized,scala.Function1)scala.Unit
 [error]   called from scala.collection.mutable.MutableList.foreach(scala.Function1)scala.Unit
 [error]   called from scala.collection.TraversableLike$WithFilter.map(scala.Function1,scala.collection.generic.CanBuildFrom)java.lang.Object
 [error]   called from scala.collection.immutable.Stream$StreamWithFilter.map(scala.Function1,scala.collection.generic.CanBuildFrom)java.lang.Object
 [error]   called from org.scalajs.testinterface.internal.Slave.org$scalajs$testinterface$internal$Slave$$execute(scala.scalajs.js.Dynamic)scala.Unit
 [error]   called from org.scalajs.testinterface.internal.Slave.handleMsgImpl(java.lang.String,scala.Function0)scala.Unit
 [error]   called from org.scalajs.testinterface.internal.BridgeBase.handleMsg(java.lang.String)scala.Unit
 [error]   called from org.scalajs.testinterface.internal.BridgeBase.$$anonfun$1(java.lang.String)scala.Unit
 [error]   called from org.scalajs.testinterface.internal.BridgeBase.init()scala.Unit
 [error]   called from org.scalajs.testinterface.internal.BridgeBase.$$js$exported$meth$init()java.lang.Object
 [error]   called from org.scalajs.testinterface.internal.BridgeBase.init
 [error]   exported to JavaScript with @JSExport
 [error] involving instantiated classes:
 [error]   com.jshin47.jtdc.client.module.visualization.DiodeStateVizC$
 [error]   com.jshin47.jtdc.client.module.landing.LandingLocC$$anonfun$2
 [error]   scala.collection.mutable.Queue
 [error]   scala.collection.mutable.MutableList
 [error]   scala.collection.TraversableLike$WithFilter
 [error]   scala.collection.immutable.Stream$StreamWithFilter
 [error]   org.scalajs.testinterface.internal.Slave
 [error]   org.scalajs.testinterface.internal.Master
 [error] Referring to non-existent method java.lang.Class.getDeclaredFields()     [java.lang.reflect.Field
 [error]   called from com.jshin47.jtdc.client.module.visualization.DiodeStateVizC$.ccToMap(java.lang.Object)scala.collection.immutable.Map
 [error]   called from com.jshin47.jtdc.client.module.visualization.DiodeStateVizC$.<init>()
 [error]   called from com.jshin47.jtdc.client.module.landing.LandingLocC$$anonfun$2.apply(japgolly.scalajs.react.extra.router.RouterCtl)japgolly.scalajs.react.ReactElement
 [error]   called from com.jshin47.jtdc.client.module.landing.LandingLocC$$anonfun$2.apply(java.lang.Object)java.lang.Object
 [error]   called from scala.collection.LinearSeqOptimized$class.foreach(scala.collection.LinearSeqOptimized,scala.Function1)scala.Unit
 [error]   called from scala.collection.mutable.MutableList.foreach(scala.Function1)scala.Unit
 [error]   called from scala.collection.TraversableLike$WithFilter.map(scala.Function1,scala.collection.generic.CanBuildFrom)java.lang.Object
 [error]   called from scala.collection.immutable.Stream$StreamWithFilter.map(scala.Function1,scala.collection.generic.CanBuildFrom)java.lang.Object
 [error]   called from org.scalajs.testinterface.internal.Slave.org$scalajs$testinterface$internal$Slave$$execute(scala.scalajs.js.Dynamic)scala.Unit
 [error]   called from org.scalajs.testinterface.internal.Slave.handleMsgImpl(java.lang.String,scala.Function0)scala.Unit
 [error]   called from org.scalajs.testinterface.internal.BridgeBase.handleMsg(java.lang.String)scala.Unit
 [error]   called from org.scalajs.testinterface.internal.BridgeBase.$$anonfun$1(java.lang.String)scala.Unit
 [error]   called from org.scalajs.testinterface.internal.BridgeBase.init()scala.Unit
 [error]   called from org.scalajs.testinterface.internal.BridgeBase.$$js$exported$meth$init()java.lang.Object
 [error]   called from org.scalajs.testinterface.internal.BridgeBase.init
 [error]   exported to JavaScript with @JSExport
 [error] involving instantiated classes:
 [error]   com.jshin47.jtdc.client.module.visualization.DiodeStateVizC$
 [error]   com.jshin47.jtdc.client.module.landing.LandingLocC$$anonfun$2
 [error]   scala.collection.mutable.Queue
 [error]   scala.collection.mutable.MutableList
 [error]   scala.collection.TraversableLike$WithFilter
 [error]   scala.collection.immutable.Stream$StreamWithFilter
 [error]   org.scalajs.testinterface.internal.Slave
 [error]   org.scalajs.testinterface.internal.Master
 [trace] Stack trace suppressed: run last client/compile:fastOptJS for the full output.
 [error] (client/compile:fastOptJS) There were linking errors
 [error] Total time: 36 s, completed May 10, 2016 2:01:07 AM

我尝试了什么

由于不熟悉链接器的细节,我只能尝试一些&#34;显而易见的&#34;诊断:

  • 无论我是否调用该方法,都会抛出此错误(它不必在代码路径中,因此在链接方法时会抛出此错误)
  • Map类型本身可以正常作为我试图调用此函数的函数的参数
  • 我知道确定性 iff 此方法(或类似)存在,然后我得到上面的链接器错误。 (没有,没有错误。)

有关如何进行,调试等的任何提示都表示赞赏。

或者,如果没有上述风格(基于反射)功能我可以将case class转换为Map的任何提示,请告知我们