Is this IntelliJ inspection warning a false positive?



I’m looking at ProducerPerformance.java from https://github.com/apache/kafka.

Looking at this part of the file:

        byte[] payload = null;
        Random random = new Random(0);
        if (recordSize != null) {
            payload = new byte[recordSize];
            for (int i = 0; i < payload.length; ++i)
                payload[i] = (byte) (random.nextInt(26) + 65);
        }

There is an inspection saying that “Condition i < payload.length is always false.”

I don’t see how it could always be false. recordSize is an Integer coming from a command-line parameter. Is there something I’m not seeing here?

Answer

This warning happened with IntelliJ IDEA 2020.*. The latest version, 2021.1, fixes this issue.



Source: stackoverflow