小编Ash*_*tal的帖子

scala.ScalaReflectionException:JavaMirror 中的类 java.sql.Timestamp 和 ClasspathFilter

我有一个单元测试,它基本上使用案例类将数据帧转换为数据集。

当我使用 jdk-8 运行该测试时,它通过了但当我使用 jdk 10 或 11 时,它失败了:“scala.ScalaReflectionException: class java.sql.Timestamp in JavaMirror with ClasspathFilter” 我没有从失败中获得任何其他信息信息。我的单元测试看起来像:

  "A dataFrameToDataSet function" should "return DataSet[AssetTagAsset] from dataframe that contains Asset data" in {

val assetTagAssets = Map[Long, AssetTagAsset](
  (
    1L,
    new AssetTagAsset(
      asset_tag_asset_id = 1L,
      asset_tag_asset_uuid = "test",
      asset_id = 1L,
      asset_tag_id = 1L,
      sticky = "abc",
      added_date = Option(Timestamp.valueOf("2018-04-17 10:10:50")),
      added_user_id = Option(1L),
      region = "sjc01",
      environment = "eng",
      pod = "p05"
    )
  )
)

val DecimalType = DataTypes.createDecimalType(38, 10)

val assetTagAssetSchema …
Run Code Online (Sandbox Code Playgroud)

java unit-testing scala apache-spark

6
推荐指数
0
解决办法
734
查看次数

Optional.ofNullable() 中的空指针异常

我正在尝试将 Optional.OfNullable 方法中的集合转换为字符串,例如:

test.setAbc(Optional.ofNullable(rule.getSampleSet().toString()).orElse(null));
Run Code Online (Sandbox Code Playgroud)

但如果sampleSetnull它会给我一个NullPointerException. 谁能告诉我如何使用.map方法解决这个问题Optional

我知道一种通过事先检查可空性来做到这一点的传统方法:

if(rule.getSampeSet != null)
Run Code Online (Sandbox Code Playgroud)

但我很想知道我们是否可以在一行中完成。

java optional

1
推荐指数
1
解决办法
510
查看次数

标签 统计

java ×2

apache-spark ×1

optional ×1

scala ×1

unit-testing ×1