This is an automated email from the ASF dual-hosted git repository.

olamy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


The following commit(s) were added to refs/heads/master by this push:
     new 1b62680a2 [SUREFIRE-2167] Strip grouping separators before parsing 
elapsed time (#3599)
1b62680a2 is described below

commit 1b62680a2cb03511c5c7b8d367df7a8abf5028ed
Author: Arturo Bernal <[email protected]>
AuthorDate: Sun Nov 22 03:52:17 2026 +0100

    [SUREFIRE-2167] Strip grouping separators before parsing elapsed time 
(#3599)
    
    Float.parseFloat(), introduced by the SUREFIRE-2167 simplification,
    rejects a grouping separator (e.g. "1,323.333"), unlike the previous
    NumberFormat.getInstance(ENGLISH) it replaced. JUnit 5's own
    LegacyXmlReportGeneratingListener writes elapsed times with a grouping
    separator once they reach 1000 seconds, so any report it produces for
    a long-running suite could never be re-parsed by surefire-report-parser
    (e.g. via maven-surefire-report-plugin), aborting with a bare
    NumberFormatException wrapped in a SAXException.
    
    Strip the separator before parsing at all three call sites (testsuite
    and testcase time attributes, and the legacy <time> element).
---
 .../plugins/surefire/report/TestSuiteXmlParser.java    |  7 ++++---
 .../surefire/report/TestSuiteXmlParserTest.java        | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git 
a/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java
 
b/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java
index aa2dc63b1..04ef920df 100644
--- 
a/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java
+++ 
b/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java
@@ -113,7 +113,7 @@ public void startElement(String uri, String localName, 
String qName, Attributes
                         currentSuite = defaultSuite;
                         String timeStr = attributes.getValue("time");
                         if (timeStr != null) {
-                            
defaultSuite.setTimeElapsed(Float.parseFloat(timeStr));
+                            
defaultSuite.setTimeElapsed(Float.parseFloat(timeStr.replaceAll(",", "")));
                         } else {
                             consoleLogger.warning("No time attribute found on 
testsuite element");
                         }
@@ -156,7 +156,7 @@ public void startElement(String uri, String localName, 
String qName, Attributes
                         
testCase.setFullClassName(currentSuite.getFullClassName())
                                 .setClassName(currentSuite.getName())
                                 .setFullName(currentSuite.getFullClassName() + 
"." + testCase.getName())
-                                .setTime(timeStr != null ? 
Float.parseFloat(timeStr) : 0.0f);
+                                .setTime(timeStr != null ? 
Float.parseFloat(timeStr.replaceAll(",", "")) : 0.0f);
 
                         if (currentSuite != defaultSuite) {
                             currentSuite.setTimeElapsed(testCase.getTime() + 
currentSuite.getTimeElapsed());
@@ -228,7 +228,8 @@ public void endElement(String uri, String localName, String 
qName) throws SAXExc
                 break;
             case "time":
                 try {
-                    
defaultSuite.setTimeElapsed(Float.parseFloat(currentElement.toString()));
+                    defaultSuite.setTimeElapsed(
+                            
Float.parseFloat(currentElement.toString().replaceAll(",", "")));
                 } catch (NumberFormatException e) {
                     throw new SAXException("Failed to parse time value", e);
                 }
diff --git 
a/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java
 
b/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java
index dabeafd93..e5fc9ab0d 100644
--- 
a/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java
+++ 
b/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java
@@ -220,6 +220,24 @@ void testParse() throws Exception {
         assertThat(tests.get(3).hasError(), is(false));
     }
 
+    @Test
+    void testParseTimeWithGroupingSeparator() throws Exception {
+        // JUnit 5's LegacyXmlReportGeneratingListener writes elapsed times >= 
1000 seconds with a grouping
+        // separator, e.g. time="1,323.333", which is what the 
pre-SUREFIRE-2167 NumberFormat-based parser
+        // tolerated but plain Float.parseFloat does not.
+        TestSuiteXmlParser testSuiteXmlParser = new 
TestSuiteXmlParser(consoleLogger);
+        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
+                + "<testsuite failures=\"0\" time=\"1,323.333\" errors=\"0\" 
skipped=\"0\" tests=\"1\" name=\"longRunning.LongTest\">\n"
+                + "  <testcase time=\"1,000.0\" 
classname=\"longRunning.LongTest\" name=\"longRunningTest\"/>\n"
+                + "</testsuite>";
+        InputStream byteArrayIs = new ByteArrayInputStream(xml.getBytes());
+        List<ReportTestSuite> parse = testSuiteXmlParser.parse(new 
InputStreamReader(byteArrayIs, UTF_8));
+        assertThat(parse.size(), is(1));
+        ReportTestSuite report = parse.get(0);
+        assertThat(report.getTimeElapsed(), is(1323.333f));
+        assertThat(report.getTestCases().get(0).getTime(), is(1000.0f));
+    }
+
     @Test
     void testParser() throws Exception {
         TestSuiteXmlParser parser = new TestSuiteXmlParser(consoleLogger);

Reply via email to