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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git


The following commit(s) were added to refs/heads/master by this push:
     new aa47951bd fix: Make stopInstant be in sync with stopTimeNanos for 
split (#1610)
aa47951bd is described below

commit aa47951bd0223d674d2b85d06ccc6f7f1749a682
Author: Lars Helge Ă˜verland <[email protected]>
AuthorDate: Wed Mar 4 20:22:06 2026 +0100

    fix: Make stopInstant be in sync with stopTimeNanos for split (#1610)
    
    * fix: Make stopInstant in sync with stopTimeNanos
    
    * Fix trailing whitespace
    
    ---------
    
    Co-authored-by: Gary Gregory <[email protected]>
---
 .../java/org/apache/commons/lang3/time/StopWatch.java   |  3 ++-
 .../org/apache/commons/lang3/time/StopWatchTest.java    | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/lang3/time/StopWatch.java 
b/src/main/java/org/apache/commons/lang3/time/StopWatch.java
index 72b072069..4604a72c0 100644
--- a/src/main/java/org/apache/commons/lang3/time/StopWatch.java
+++ b/src/main/java/org/apache/commons/lang3/time/StopWatch.java
@@ -689,6 +689,7 @@ public void split() {
             throw new IllegalStateException("Stopwatch is not running.");
         }
         stopTimeNanos = System.nanoTime();
+        stopInstant = Instant.now();
         splitState = SplitState.SPLIT;
         splits.add(new Split(String.valueOf(splits.size()), 
Duration.ofNanos(stopTimeNanos - startTimeNanos)));
     }
@@ -710,6 +711,7 @@ public void split(final String label) {
             throw new IllegalStateException("Stopwatch is not running.");
         }
         stopTimeNanos = System.nanoTime();
+        stopInstant = Instant.now();
         splitState = SplitState.SPLIT;
         splits.add(new Split(label, Duration.ofNanos(stopTimeNanos - 
startTimeNanos)));
     }
@@ -835,5 +837,4 @@ public void unsplit() {
         splitState = SplitState.UNSPLIT;
         splits.remove(splits.size() - 1);
     }
-
 }
diff --git a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java 
b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
index bffb29acb..944e1d10d 100644
--- a/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/StopWatchTest.java
@@ -19,6 +19,7 @@
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -422,6 +423,22 @@ void testSplitsWithStringLabels() {
         assertThrows(IllegalStateException.class, watch::unsplit);
     }
 
+    @Test
+    void testSplitGetStopInstant() {
+      final StopWatch watch = StopWatch.createStarted();
+      watch.split();
+      assertNotNull(watch.getStopTime());
+      assertNotNull(watch.getStopInstant());
+    }
+
+    @Test
+    void testSplitWithLabelGetStopInstant() {
+      final StopWatch watch = StopWatch.createStarted();
+      watch.split("one");
+      assertNotNull(watch.getStopTime());
+      assertNotNull(watch.getStopInstant());
+    }
+
     @Test
     void testStatic() {
         final StopWatch watch = StopWatch.createStarted();

Reply via email to