You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/04/15 14:32:53 UTC

[GitHub] [maven-surefire] Tibor17 commented on a diff in pull request #519: After surefire 2058

Tibor17 commented on code in PR #519:
URL: https://github.com/apache/maven-surefire/pull/519#discussion_r851302841


##########
surefire-api/src/main/java/org/apache/maven/surefire/api/stream/AbstractStreamDecoder.java:
##########
@@ -305,32 +313,24 @@ private String readString( @Nonnull final Memento memento, @Nonnegative final in
         memento.getDecoder().reset();
         final CharBuffer output = memento.getCharBuffer();
         ( (Buffer) output ).clear();
-        final ByteBuffer input = memento.getByteBuffer();
         final List<String> strings = new ArrayList<>();
         int countDecodedBytes = 0;
         for ( boolean endOfInput = false; !endOfInput; )
         {
-            final int bytesToRead = totalBytes - countDecodedBytes;
+            final int bytesToRead = totalBytes - countDecodedBytes; // our wish to read bytes as much as possible
             read( memento, bytesToRead );
-            int bytesToDecode = min( input.remaining(), bytesToRead );
+            final ByteBuffer input = memento.getByteBuffer();
+            int bytesToDecode = min( input.remaining(), bytesToRead ); // our guarantee of available bytes in buffer
             final boolean isLastChunk = bytesToDecode == bytesToRead;
             endOfInput = countDecodedBytes + bytesToDecode >= totalBytes;
-            do
-            {
-                boolean endOfChunk = output.remaining() >= bytesToRead;
-                boolean endOfOutput = isLastChunk && endOfChunk;
-                int readInputBytes = decodeString( memento.getDecoder(), input, output, bytesToDecode, endOfOutput,
-                    memento.getLine().getPositionByteBuffer() );
-                bytesToDecode -= readInputBytes;
-                countDecodedBytes += readInputBytes;
-            }
-            while ( isLastChunk && bytesToDecode > 0 && output.hasRemaining() );
-
-            if ( isLastChunk || !output.hasRemaining() )
-            {
-                strings.add( ( (Buffer) output ).flip().toString() );
-                ( (Buffer) output ).clear();
-            }
+            boolean endOfChunk = output.remaining() >= bytesToRead;
+            boolean endOfOutput = isLastChunk && endOfChunk;
+            int readInputBytes = decodeString( memento.getDecoder(), input, output, bytesToDecode, endOfOutput,
+                memento.getLine().getPositionByteBuffer() );
+            countDecodedBytes += readInputBytes;
+            strings.add( ( (Buffer) output ).flip().toString() );
+            ( (Buffer) output ).clear();
+            memento.getLine().setPositionByteBuffer( 0 );

Review Comment:
   @zoltanmeze  `memento.getLine()` holds the line which could not be properly decoded and it is eligible for printing as a corruption on the console.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org