Hi,
We are using Smack 4.1.x releases and every day we are receiving a few crash reports like the one below.
java.lang.OutOfMemoryError
java.lang.Object[] of length 2147483647 exceeds the VM limit
I believe it’s because of the processHandledCount method in XMPPTCPConnection class:
https://github.com/igniterealtime/Smack/blob/92968e16304a3a4c138010580c46d2e7c8a 00743/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java# L1792
The crash may happen because of two reasons:
-
there is not enough memory to allocate
-
the array length exceeds platform limit (https://plumbr.eu/outofmemoryerror/requested-array-size-exceeds-vm-limit)
As you may know, the SMUtils.calculateDelta may return value bigger than Integer.MAX_VALUE in case if serverHandledStanzasCount is bigger than handledCount.
I’m not entirely sure what should be the best way to fix the issue but I believe it should be enough to get rid of initial ArrayList capacity at all or use the handledCount as initial capacity if we really want to avoid unnecessary calls to increase ArrayList capacity during the iteration in the next steps. What do you think about it?