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

ASF GitHub Bot commented on GROOVY-12139:
-----------------------------------------

paulk-asert merged PR #2675:
URL: https://github.com/apache/groovy/pull/2675




> Primitive array Varargs Java incompatibility (fix needed also for classic 
> bytecode)
> -----------------------------------------------------------------------------------
>
>                 Key: GROOVY-12139
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12139
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 6.0.0-alpha-2, 5.0.7
>            Reporter: Steve Eady
>            Assignee: Eric Milles
>            Priority: Major
>
> Groovy is not parsing primitive arrays sent into a varargs parameter the same 
> way it is being parsed in Java 17.0.7
> If the input value is a byte array of the string "test"...
> Groovy is slicing it up into a 2d array of dimensions [4][1]
> an array of size 4 each containing an array of size 1
> In java, the value is being slide up into a 2d array of dimensions [1][4]
> an array of size 1 containing an array of size 4.
> This was detected when trying to pass in a byte[] value into a varargs of 
> (byte[]... args)
> in a Spring library.
> Here are the test cases for Groovy vs Java
> {code:groovy}
> class VarArgsTestGroovy {
>   static void main(String[] args) {
>     byte[] bytes = "test".bytes
>     test(bytes)
>   }
>   static test(byte[]... byteArrays) {
>     assert byteArrays.length == 4
>     (0..3).each {
>       assert byteArrays[it].length == 1
>     }
> }
> {code}
> {code:java}
> public class VarArgsTestJava {
>   public static void main(String[] args) {
>     byte[] bytes = "test".getBytes();
>     test(bytes);
>     }
>   static void test(byte[]... byteArrays) {
>     assert byteArrays.length == 1;
>     assert byteArrays[0].length == 4;
>   }
> }
> {code}
> My current workaround is to pre-create a 2 dimensional array of size[1][value]
> and pass that into the varargs method instead of the original byte array



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to