简体   繁体   English

类型安全配置-空指针异常

[英]Typesafe config - Null Pointer Exception

I am manually constructing the classpath for my Play/Scala/Akka application so I can use the ScalaTest runner to test my application during different stages of a CI pipeline without the need to recompile. 我正在为Play / Scala / Akka应用程序手动构造类路径,因此我可以使用ScalaTest运行器在CI管道的不同阶段测试应用程序,而无需重新编译。 However, I get the following error: 但是,出现以下错误:

java.lang.NullPointerException:
  at com.typesafe.config.impl.Parseable$ParseableResources.rawParseValue(Parseable.java:509)
  at com.typesafe.config.impl.Parseable$ParseableResources.rawParseValue(Parseable.java:492)
  at com.typesafe.config.impl.Parseable.parseValue(Parseable.java:171)
  at com.typesafe.config.impl.Parseable.parseValue(Parseable.java:165)
  at com.typesafe.config.impl.Parseable.parse(Parseable.java:204)
  at com.typesafe.config.impl.ConfigImpl$1.call(ConfigImpl.java:368)
  at com.typesafe.config.impl.ConfigImpl$1.call(ConfigImpl.java:365)
  at com.typesafe.config.impl.ConfigImpl$LoaderCache.getOrElseUpdate(ConfigImpl.java:58)
  at com.typesafe.config.impl.ConfigImpl.computeCachedConfig(ConfigImpl.java:86)
  at com.typesafe.config.impl.ConfigImpl.defaultReference(ConfigImpl.java:365)

Here is the command I am running: 这是我正在运行的命令:

/usr/lib/jvm/java-7-openjdk//bin/java -Xmx256M -Xms32M -Xbootclasspath/a:$BOOTCP -classpath '""' -Dscala.home=/usr/opt/scala -Dscala.usejavacp=true -jar /home/nick/repos/testrunnnertest/lib/scalatest.jar -R target/scala-2.10/test-classes -o 

The value for $BOOTCP is a massive list of dependencies including the application jars, the dependencies in .ivy2 and the folders containing the config files (/conf, /test/resources). $ BOOTCP的值是大量依赖项列表,包括应用程序jar,.ivy2中的依赖项以及包含配置文件(/ conf,/ test / resources)的文件夹。 I copied this command from the Scala shell script. 我从Scala shell脚本复制了此命令。 I also used the value for $BOOTCP as the value for -classpath, but I still had the same problem. 我还使用了$ BOOTCP的值作为-classpath的值,但是我仍然遇到相同的问题。

This problem only happens when I run my acceptance tests which are spinning up a Play Framework Test Server. 仅当我运行正在逐步扩展Play框架测试服务器的验收测试时,才会发生此问题。 So it seems likely that it is a problem loading the main application configs in /conf rather than the /test/resources configs which appear to load find when the Unit and Integration tests happily run. 因此,将主要应用程序配置加载到/ conf中而不是似乎在单元测试和集成测试运行时似乎加载的/ test / resources配置中似乎是一个问题。

Coming to this question pretty late, but did you ever figure it out? 这个问题来得很晚,但是您有没有解决? Which typesafe config version is on your classpath? 您的类路径上有哪个类型安全的配置版本?

Line 509 on master doesn't look like it could be quite the right line: https://github.com/typesafehub/config/blob/master/config/src/main/java/com/typesafe/config/impl/Parseable.java#L509 master上的509行看起来不太正确: https//github.com/typesafehub/config/blob/master/config/src/main/java/com/typesafe/config/impl/Parseable的.java#L509

so you may have a version with slightly different source. 因此您的版本可能与来源略有不同。

Version 1.0.2 line 509 looks maybe more likely: https://github.com/typesafehub/config/blob/v1.0.2/config/src/main/java/com/typesafe/config/impl/Parseable.java#L509 版本1.0.2的第509行看起来可能更有可能: https : //github.com/typesafehub/config/blob/v1.0.2/config/src/main/java/com/typesafe/config/impl/Parseable.java#L509

On that line most likely the class loader is null I guess? 在那条线上,类加载器很可能是null我猜? It's supposed to come from here in that trace: https://github.com/typesafehub/config/blob/v1.0.2/config/src/main/java/com/typesafe/config/impl/ConfigImpl.java#L365 Which in turn comes from: https://github.com/typesafehub/config/blob/v1.0.2/config/src/main/java/com/typesafe/config/ConfigFactory.java#L380 它应该来自此处的跟踪: https : //github.com/typesafehub/config/blob/v1.0.2/config/src/main/java/com/typesafe/config/impl/ConfigImpl.java#L365其中反过来来自: https : //github.com/typesafehub/config/blob/v1.0.2/config/src/main/java/com/typesafe/config/ConfigFactory.java#L380

So one theory is that the thread has no context class loader set in the case where it throws an exception. 因此,一种理论是,在线程引发异常的情况下,该线程没有设置上下文类加载器。 I can't tell you why that's the case in your scenario, if it is, but perhaps it is a lead. 我无法告诉您为什么会出现这种情况(如果有的话),但也许是领先优势。

I don't think typesafe config should throw NPE this "late" in any case so I created https://github.com/typesafehub/config/issues/155 to fix this up. 我不认为typesafe配置在任何情况下都不应将此NPE丢掉,因此我创建了https://github.com/typesafehub/config/issues/155来解决此问题。 However it most likely is ultimately a problem in play and/or how you're setting things up that the thread context class loader is null and no other class loader was provided to ConfigFactory methods. 但是,很可能最终会在游戏中和/或您如何设置事情时出现问题,即线程上下文类加载器为null且没有其他类加载器提供给ConfigFactory方法。

This is assuming that the NPE is from a null class loader, I don't think that's necessarily the problem, but it looks plausible from that stack trace. 这是假设NPE来自空类加载器,我认为这不一定是问题所在,但从该堆栈跟踪看,它似乎是合理的。

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

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