[ 
https://issues.apache.org/jira/browse/NIFI-16142?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Daniel Stieglitz updated NIFI-16142:
------------------------------------
    Status: Patch Available  (was: In Progress)

> Replace the use of bitwise operators to read a long from a byte array with 
> Java API alternatives
> ------------------------------------------------------------------------------------------------
>
>                 Key: NIFI-16142
>                 URL: https://issues.apache.org/jira/browse/NIFI-16142
>             Project: Apache NiFi
>          Issue Type: Improvement
>            Reporter: Daniel Stieglitz
>            Assignee: Daniel Stieglitz
>            Priority: Minor
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> In a handful of places, a long is read from a byte array using bit-wise 
> operators assuming BigEndian e.g. in {{FlowFileUnpackagerV3}} lines 130-137
> {code:java}
> return (((long) readBuffer[0] << 56)
>                 + ((long) (readBuffer[1] & 255) << 48)
>                 + ((long) (readBuffer[2] & 255) << 40)
>                 + ((long) (readBuffer[3] & 255) << 32)
>                 + ((long) (readBuffer[4] & 255) << 24)
>                 + ((readBuffer[5] & 255) << 16)
>                 + ((readBuffer[6] & 255) << 8)
>                 + ((readBuffer[7] & 255)));{code}
> which is hard to read. In addition there are some unnecessary casts when 
> using this method. Although  all casts were kept in PR 
> #[11440|[https://github.com/apache/nifi/pull/11440]], that was only for 
> consistency so one wouldn't have to wonder why some lines have casts and 
> others do not, but ideally unnecessary ones should not be included. 
> There are Java API  alternatives for reading a long from a byte array e.g. 
> {{java.nio.ByteBuffer}} (which uses by default BigEndian) or 
> {{{}java.lang.invoke.VarHandle{}}}. This ticket aims to replace the bit-wise 
> operators approach with the use of one of the Java alternatives.



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

Reply via email to