Skip to content

Commit ff46962

Browse files
committed
SonarQube fixes
1 parent 9e4f180 commit ff46962

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

api/src/main/java/io/kafbat/ui/service/metrics/scrape/jmx/JmxMetricsFormatter.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
public class JmxMetricsFormatter {
1818

1919
// 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
2121
"([^,=:\\*\\?]+)=(\"(?:[^\\\\\"]*(?:\\\\.)?)*\"|[^,=:\"]*)"
2222
);
2323

@@ -78,17 +78,20 @@ private static LinkedHashMap<String, String> getLabelsMap(ObjectName mbeanName)
7878
throw new IllegalArgumentException("MBean key property list too long: " + properties);
7979
}
8080

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);
8992
}
90-
match.reset(properties);
9193
}
94+
9295
return keyProperties;
9396
}
9497

0 commit comments

Comments
 (0)