This is an automated email from the ASF dual-hosted git repository.
tomsun28 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/master by this push:
new e19e5a33f7 fix(common): parse +Inf/-Inf as real infinity in
StrBuffer.parseDouble (#4362)
e19e5a33f7 is described below
commit e19e5a33f796e7596d18c6c78811453c11c95a9c
Author: Zhao Jianing <[email protected]>
AuthorDate: Mon Oct 5 10:34:11 2026 +0800
fix(common): parse +Inf/-Inf as real infinity in StrBuffer.parseDouble
(#4362)
Signed-off-by: zjncs <[email protected]>
Co-authored-by: tomsun28 <[email protected]>
---
.../collector/collect/prometheus/parser/OnlineParserTest.java | 7 ++-----
.../src/main/java/org/apache/hertzbeat/common/util/StrBuffer.java | 4 ++--
.../test/java/org/apache/hertzbeat/common/util/StrBufferTest.java | 8 ++++----
3 files changed, 8 insertions(+), 11 deletions(-)
diff --git
a/hertzbeat-collector/hertzbeat-collector-basic/src/test/java/org/apache/hertzbeat/collector/collect/prometheus/parser/OnlineParserTest.java
b/hertzbeat-collector/hertzbeat-collector-basic/src/test/java/org/apache/hertzbeat/collector/collect/prometheus/parser/OnlineParserTest.java
index 370ac9a3bd..51ca94a5e5 100644
---
a/hertzbeat-collector/hertzbeat-collector-basic/src/test/java/org/apache/hertzbeat/collector/collect/prometheus/parser/OnlineParserTest.java
+++
b/hertzbeat-collector/hertzbeat-collector-basic/src/test/java/org/apache/hertzbeat/collector/collect/prometheus/parser/OnlineParserTest.java
@@ -108,11 +108,8 @@ class OnlineParserTest {
MetricFamily metricFamily1 =
metricFamilyMap1.get(metricFamilyName);
Set<Double> metricValueSet =
metricFamily2.getMetricList().stream().map(MetricFamily.Metric::getValue).collect(Collectors.toSet());
metricFamily1.getMetricList().forEach(metric -> {
- // this is for something different between two algorithms
above, and both of them is current on this parsing behavior.
- if (!(metric.getValue() == Double.POSITIVE_INFINITY ||
metric.getValue() == Double.NEGATIVE_INFINITY)) {
- if (!metricValueSet.contains(metric.getValue())) {
- fail();
- }
+ if (!metricValueSet.contains(metric.getValue())) {
+ fail();
}
});
});
diff --git
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/util/StrBuffer.java
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/util/StrBuffer.java
index c15bc33594..d58fe09a11 100644
---
a/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/util/StrBuffer.java
+++
b/hertzbeat-common-core/src/main/java/org/apache/hertzbeat/common/util/StrBuffer.java
@@ -153,9 +153,9 @@ public class StrBuffer {
*/
public static double parseDouble(String s) {
if (POSITIVE_INF.equalsIgnoreCase(s)) {
- return POSITIVE_INF_VALUE;
+ return Double.POSITIVE_INFINITY;
} else if (NEGATIVE_INF.equalsIgnoreCase(s)) {
- return NEGATIVE_INF_VALUE;
+ return Double.NEGATIVE_INFINITY;
}
return Double.parseDouble(s);
}
diff --git
a/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/util/StrBufferTest.java
b/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/util/StrBufferTest.java
index 98a5a93341..0bade03c1d 100644
---
a/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/util/StrBufferTest.java
+++
b/hertzbeat-common-core/src/test/java/org/apache/hertzbeat/common/util/StrBufferTest.java
@@ -91,10 +91,10 @@ class StrBufferTest {
assertEquals(123.45, buffer.toDouble());
buffer = new StrBuffer("+inf");
- assertEquals(POSITIVE_INF_VALUE, buffer.toDouble());
+ assertEquals(Double.POSITIVE_INFINITY, buffer.toDouble());
buffer = new StrBuffer("-inf");
- assertEquals(NEGATIVE_INF_VALUE, buffer.toDouble());
+ assertEquals(Double.NEGATIVE_INFINITY, buffer.toDouble());
}
@Test
@@ -144,8 +144,8 @@ class StrBufferTest {
void testParseDouble() {
assertEquals(123.45, StrBuffer.parseDouble("123.45"));
- assertEquals(POSITIVE_INF_VALUE, StrBuffer.parseDouble("+inf"));
- assertEquals(NEGATIVE_INF_VALUE, StrBuffer.parseDouble("-inf"));
+ assertEquals(Double.POSITIVE_INFINITY, StrBuffer.parseDouble("+inf"));
+ assertEquals(Double.NEGATIVE_INFINITY, StrBuffer.parseDouble("-inf"));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]