From fe49d774f133419e27a89419bd5182b2cd2a4a1b Mon Sep 17 00:00:00 2001 From: max-melentyev <119438383+max-melentyev@users.noreply.github.com> Date: Mon, 20 Jan 2025 14:23:34 -0500 Subject: [PATCH] Fix NPE when label value is null Signed-off-by: max-melentyev <119438383+max-melentyev@users.noreply.github.com> --- .../prometheus/metrics/expositionformats/TextFormatUtil.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/prometheus-metrics-exposition-textformats/src/main/java/io/prometheus/metrics/expositionformats/TextFormatUtil.java b/prometheus-metrics-exposition-textformats/src/main/java/io/prometheus/metrics/expositionformats/TextFormatUtil.java index e48f545c5..7fa27135e 100644 --- a/prometheus-metrics-exposition-textformats/src/main/java/io/prometheus/metrics/expositionformats/TextFormatUtil.java +++ b/prometheus-metrics-exposition-textformats/src/main/java/io/prometheus/metrics/expositionformats/TextFormatUtil.java @@ -35,6 +35,9 @@ static void writeTimestamp(Writer writer, long timestampMs) throws IOException { } static void writeEscapedLabelValue(Writer writer, String s) throws IOException { + if (s == null) { + return; + } for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); switch (c) {