[maven-surefire] branch cli updated: fixed NPE with non-threadsafe java.util.Scanner

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[maven-surefire] branch cli updated: fixed NPE with non-threadsafe java.util.Scanner

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

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


The following commit(s) were added to refs/heads/cli by this push:
     new 8c57e0c  fixed NPE with non-threadsafe java.util.Scanner
8c57e0c is described below

commit 8c57e0c4cdd76537ce9c5d4cda50d836f9990921
Author: tibordigana <[hidden email]>
AuthorDate: Mon Dec 2 06:14:55 2019 +0100

    fixed NPE with non-threadsafe java.util.Scanner
---
 .../maven/surefire/extensions/util/LineConsumerThread.java     | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/util/LineConsumerThread.java b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/util/LineConsumerThread.java
index f0f39f3..efce286 100644
--- a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/util/LineConsumerThread.java
+++ b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/util/LineConsumerThread.java
@@ -34,7 +34,8 @@ import java.util.concurrent.CountDownLatch;
  */
 public final class LineConsumerThread extends Thread implements Closeable
 {
-    private final Scanner scanner;
+    private final Charset encoding;
+    private final ReadableByteChannel channel;
     private final StreamConsumer consumer;
     private final CountDownLatch endOfStreamsCountdown;
     private volatile boolean disabled;
@@ -52,15 +53,16 @@ public final class LineConsumerThread extends Thread implements Closeable
     {
         setName( threadName );
         setDaemon( true );
-        scanner = new Scanner( channel, encoding.name() );
+        this.channel = channel;
         this.consumer = consumer;
         this.endOfStreamsCountdown = endOfStreamsCountdown;
+        this.encoding = encoding;
     }
 
     @Override
     public void run()
     {
-        try ( Scanner stream = scanner )
+        try ( Scanner stream = new Scanner( channel, encoding.name() ) )
         {
             boolean isError = false;
             while ( stream.hasNextLine() )
@@ -98,6 +100,6 @@ public final class LineConsumerThread extends Thread implements Closeable
     @Override
     public void close() throws IOException
     {
-        scanner.close();
+        channel.close();
     }
 }