+act - Adds a non-blocking, bounded, MPSC mailbox with tests.

You need something like this:

        long size;
        do {
            /*
             * It is possible for a thread to be interrupted or reschedule between the read of the producer
             * and consumer indices, therefore protection is required to ensure size is within valid range.
             */
            final long currentConsumerIndex = getDeq().count;
            final long currentProducerIndex = getEnq().count;
            size = (int)(currentProducerIndex - currentConsumerIndex);
        } while (size > capacity); // you can't exceed capacity, which is an int

        return size;
I was similarly caught out in JCTools and set right by @mjpt777 :-)