[ 
https://issues.apache.org/jira/browse/SUREFIRE-1454?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16434620#comment-16434620
 ] 

ASF GitHub Bot commented on SUREFIRE-1454:
------------------------------------------

abaxanean closed pull request #180: SUREFIRE-1454 fix for empty array
URL: https://github.com/apache/maven-surefire/pull/180
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
 
b/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
index 23d372c75..b0665bd1e 100644
--- 
a/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
+++ 
b/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/StringUtils.java
@@ -239,6 +239,10 @@ else if ( ch >= 'A' )
     public static EncodedArray escapeBytesToPrintable( final byte[] header, 
final byte[] input, final int off,
                                                        final int len )
     {
+        if ( input.length == 0 )
+        {
+            return EncodedArray.EMPTY;
+        }
         if ( off < 0 || len < 0 || off >= input.length || len > input.length 
|| off > len )
         {
             throw new IndexOutOfBoundsException(
@@ -359,6 +363,8 @@ public static boolean startsWith( StringBuffer buffer, 
String pattern )
      */
     public static final class EncodedArray
     {
+        private static final EncodedArray EMPTY = new EncodedArray( new 
byte[]{}, 0 );
+
         private final byte[] array;
         private final int size;
 
diff --git 
a/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/StringUtilsTest.java
 
b/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/StringUtilsTest.java
index dea6c9b1a..96e5ed31a 100644
--- 
a/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/StringUtilsTest.java
+++ 
b/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/StringUtilsTest.java
@@ -110,4 +110,13 @@ public void testEscapeWithHeader()
 
         assertArrayEquals( expectedResult, actualResult );
     }
+
+    public void testEmptyByteArray()
+    {
+        byte[] header = { (byte) 'a' };
+        byte[] input = {};
+        EncodedArray encodedArray = StringUtils.escapeBytesToPrintable( 
header, input, 0, input.length );
+        assertEquals( 0, encodedArray.getSize() );
+        assertEquals( 0, encodedArray.getArray().length );
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Speedup Standard Output if Tests
> --------------------------------
>
>                 Key: SUREFIRE-1454
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1454
>             Project: Maven Surefire
>          Issue Type: Improvement
>          Components: Maven Failsafe Plugin, Maven Surefire Plugin, process 
> forking
>            Reporter: Tibor Digana
>            Assignee: Tibor Digana
>            Priority: Major
>             Fix For: 2.21.0
>
>
> Currently, surefire creates a new byte array with size of the input *3 for 
> saving the unescaped input. This made surefire way slower than running a test 
> directly in eclipse or with gradle, if it used standardout or error heavily.
> By using a list for saving the elements and converting them to an array 
> afterwards, this problem is solved, and stdout-heavy surefire tests get 
> faster.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to