Skip to content

JSONFormat.defaultFormat doesn't handle null values #5092

@scabug

Description

@scabug
import scala.util.parsing.json.JSONObject
println(new JSONObject(Map("test" -> null)))

will throw an exception:

java.lang.NullPointerException
        at scala.util.parsing.json.JSONFormat$$anonfun$1.apply(Parser.scala:59)
        at scala.util.parsing.json.JSONFormat$$anonfun$1.apply(Parser.scala:55)
        at scala.util.parsing.json.JSONObject$$anonfun$toString$1.apply(Parser.scala:96)
        at scala.util.parsing.json.JSONObject$$anonfun$toString$1.apply(Parser.scala:96)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
        at scala.collection.immutable.Map$Map1.foreach(Map.scala:118)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:194)
        at scala.collection.immutable.Map$Map1.map(Map.scala:106)
        at scala.util.parsing.json.JSONObject.toString(Parser.scala:96)
        at scala.util.parsing.json.JSONType.toString(Parser.scala:33)
        at java.lang.String.valueOf(String.java:2826)
        at java.io.PrintStream.println(PrintStream.java:771)
        at scala.Console$.println(Console.scala:244)

This is works in 2.8, so it's clearly a regression.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions