From 1aa9a40127269bbb7f6a9aae03a3c57726dfabee Mon Sep 17 00:00:00 2001 From: Brian Harrington Date: Thu, 21 Nov 2024 07:11:01 -0600 Subject: [PATCH] lwcapi: fix npe when samples missing If the payload didn't include a samples key, then it would get set to `null` and result in errors. Default to an empty list. --- .../main/scala/com/netflix/atlas/lwcapi/EvaluateApi.scala | 2 +- .../scala/com/netflix/atlas/lwcapi/EvaluateApiSuite.scala | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/atlas-lwcapi/src/main/scala/com/netflix/atlas/lwcapi/EvaluateApi.scala b/atlas-lwcapi/src/main/scala/com/netflix/atlas/lwcapi/EvaluateApi.scala index 5b74ace21..a6e518199 100644 --- a/atlas-lwcapi/src/main/scala/com/netflix/atlas/lwcapi/EvaluateApi.scala +++ b/atlas-lwcapi/src/main/scala/com/netflix/atlas/lwcapi/EvaluateApi.scala @@ -88,7 +88,7 @@ object EvaluateApi { id: String, @JsonDeserialize(`using` = classOf[SortedTagMapDeserializer]) tags: SortedTagMap, value: Double, - samples: List[List[Any]] + samples: List[List[Any]] = Nil ) case class EvaluateRequest( diff --git a/atlas-lwcapi/src/test/scala/com/netflix/atlas/lwcapi/EvaluateApiSuite.scala b/atlas-lwcapi/src/test/scala/com/netflix/atlas/lwcapi/EvaluateApiSuite.scala index e03c4a0b1..148d57881 100644 --- a/atlas-lwcapi/src/test/scala/com/netflix/atlas/lwcapi/EvaluateApiSuite.scala +++ b/atlas-lwcapi/src/test/scala/com/netflix/atlas/lwcapi/EvaluateApiSuite.scala @@ -88,4 +88,10 @@ class EvaluateApiSuite extends MUnitRouteSuite { assertEquals(response.status, StatusCodes.OK) } } + + test("item samples decode") { + val json = """{"id":"1","tags":{"name":"test"},"value":1.0}""" + val expected = EvaluateApi.Item("1", SortedTagMap("name" -> "test"), 1.0, Nil) + assertEquals(Json.decode[EvaluateApi.Item](json), expected) + } }