From 8700f19a672a7e09694a1ef6a1089e1341e73897 Mon Sep 17 00:00:00 2001 From: Kerem Celik Date: Thu, 29 Aug 2024 16:36:06 +0000 Subject: [PATCH] util-jackson: share PrettyPrinter properly The `PrettyPrinter` configured for a Jackson `ObjectWriter` is shared between all downstream `JsonGenerator`s. To make this thread-safe (in order to prevent multiple generators from corrupting the shared indentation level), a class derived from `PrettyPrinter` can also inherit from `Instantiable`, which basically turns the `ObjectWriter`-level `PrettyPrinter` into a factory that produces a new `PrettyPrinter` for each generator. Since `util-jackson`'s `ArrayElementsOnNewLinesPrettyPrinter` inherits from `DefaultPrettyPrinter`, which has state that must be protected from corruption, we need to abide by this factory pattern. Differential Revision: https://phabricator.twitter.biz/D1167308 --- .../main/scala/com/twitter/util/jackson/ScalaObjectMapper.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util-jackson/src/main/scala/com/twitter/util/jackson/ScalaObjectMapper.scala b/util-jackson/src/main/scala/com/twitter/util/jackson/ScalaObjectMapper.scala index 3925995598..496122b164 100644 --- a/util-jackson/src/main/scala/com/twitter/util/jackson/ScalaObjectMapper.scala +++ b/util-jackson/src/main/scala/com/twitter/util/jackson/ScalaObjectMapper.scala @@ -412,7 +412,7 @@ object ScalaObjectMapper { private[jackson] object ArrayElementsOnNewLinesPrettyPrinter extends DefaultPrettyPrinter { _arrayIndenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE - override def createInstance(): DefaultPrettyPrinter = this + override def createInstance(): DefaultPrettyPrinter = new DefaultPrettyPrinter(this) } /**