|
17 | 17 | public class JmxMetricsFormatter { |
18 | 18 |
|
19 | 19 | // copied from https://github.com/prometheus/jmx_exporter/blob/b6b811b4aae994e812e902b26dd41f29364c0e2b/collector/src/main/java/io/prometheus/jmx/JmxMBeanPropertyCache.java#L15 |
20 | | - private static final Pattern PROPERTY_PATTERN = Pattern.compile( |
| 20 | + private static final Pattern PROPERTY_PATTERN = Pattern.compile( // NOSONAR |
21 | 21 | "([^,=:\\*\\?]+)=(\"(?:[^\\\\\"]*(?:\\\\.)?)*\"|[^,=:\"]*)" |
22 | 22 | ); |
23 | 23 |
|
@@ -78,17 +78,20 @@ private static LinkedHashMap<String, String> getLabelsMap(ObjectName mbeanName) |
78 | 78 | throw new IllegalArgumentException("MBean key property list too long: " + properties); |
79 | 79 | } |
80 | 80 |
|
81 | | - Matcher match = PROPERTY_PATTERN.matcher(properties); |
82 | | - while (match.lookingAt()) { |
83 | | - String labelName = fixIllegalChars(match.group(1)); // label names should be fixed |
84 | | - String labelValue = match.group(2); |
85 | | - keyProperties.put(labelName, labelValue); |
86 | | - properties = properties.substring(match.end()); |
87 | | - if (properties.startsWith(",")) { |
88 | | - properties = properties.substring(1); |
| 81 | + if (!properties.isBlank()) { |
| 82 | + Matcher match = PROPERTY_PATTERN.matcher(properties); |
| 83 | + while (match.lookingAt()) { |
| 84 | + String labelName = fixIllegalChars(match.group(1)); // label names should be fixed |
| 85 | + String labelValue = match.group(2); |
| 86 | + keyProperties.put(labelName, labelValue); |
| 87 | + properties = properties.substring(match.end()); |
| 88 | + if (properties.startsWith(",")) { |
| 89 | + properties = properties.substring(1); |
| 90 | + } |
| 91 | + match.reset(properties); |
89 | 92 | } |
90 | | - match.reset(properties); |
91 | 93 | } |
| 94 | + |
92 | 95 | return keyProperties; |
93 | 96 | } |
94 | 97 |
|
|
0 commit comments