From 17f01d1b18b38a7fcdb42c7f99959804d13bbca3 Mon Sep 17 00:00:00 2001 From: Liyun Xiu Date: Fri, 24 May 2024 14:32:32 +0800 Subject: [PATCH 1/2] Add comment to XContentBuilder.toString Signed-off-by: Liyun Xiu --- .../java/org/opensearch/core/xcontent/XContentBuilder.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/core/src/main/java/org/opensearch/core/xcontent/XContentBuilder.java b/libs/core/src/main/java/org/opensearch/core/xcontent/XContentBuilder.java index 976f353100c55..9913b147c05f3 100644 --- a/libs/core/src/main/java/org/opensearch/core/xcontent/XContentBuilder.java +++ b/libs/core/src/main/java/org/opensearch/core/xcontent/XContentBuilder.java @@ -157,6 +157,9 @@ public static XContentBuilder builder(XContent xContent, Set includes, S /** * Returns a string representation of the builder (only applicable for text based xcontent). + * Note: explicitly or implicitly (from debugger) calling toString() could cause XContentBuilder + * to close which is a side effect done by @see BytesReference#bytes(). + * Trying to write more contents after toString() will cause NPE. Use it with cautious. */ @Override public String toString() { From 5cc0a04037fbafaa33611a59bd8bd258d5fc2655 Mon Sep 17 00:00:00 2001 From: Liyun Xiu Date: Fri, 24 May 2024 20:12:58 +0800 Subject: [PATCH 2/2] Fix typo Signed-off-by: Liyun Xiu --- .../main/java/org/opensearch/core/xcontent/XContentBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/core/src/main/java/org/opensearch/core/xcontent/XContentBuilder.java b/libs/core/src/main/java/org/opensearch/core/xcontent/XContentBuilder.java index 9913b147c05f3..552945d085884 100644 --- a/libs/core/src/main/java/org/opensearch/core/xcontent/XContentBuilder.java +++ b/libs/core/src/main/java/org/opensearch/core/xcontent/XContentBuilder.java @@ -159,7 +159,7 @@ public static XContentBuilder builder(XContent xContent, Set includes, S * Returns a string representation of the builder (only applicable for text based xcontent). * Note: explicitly or implicitly (from debugger) calling toString() could cause XContentBuilder * to close which is a side effect done by @see BytesReference#bytes(). - * Trying to write more contents after toString() will cause NPE. Use it with cautious. + * Trying to write more contents after toString() will cause NPE. Use it with caution. */ @Override public String toString() {