We have a method to convert the date in milliseconds in long format to byte array so that we can send it to network.
We were using below method to convert from long to byte in java. But our java was 32 bit, and thus we were converting the long to array of 4 bytes.
private static byte[] longToBytes(final long value) {
final byte[] bytes = new byte[4];
for (int i = 0; i < bytes.length; ++i) {
final int offset = (bytes.length - i - 1) * 8;
bytes[i] = (byte) (((value & (0xff << offset)) >>> offset));
}
return bytes;
}
But now since the java got updated to 64 bit, we are getting warning for this conversion from coverity. That the expression is evaluated using 32 bit airthmatic and then used in type long. So information loss could happen.
Now, I dont want to use byte array with 8 bytes bcoz I dont know what it will do to our underlying protocol and how it is expecting the byte array size. But I wanted to know in which case can it cause issue. Can date be of 64 bits? Any thoughts on the possible concerns in using this code?