You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given version 1.3.1, and a file of size between 100 and 799 bytes, with a cachePercent of 1.
RandomAccessFile raf = new RandomAccessFile(new File("file799bytes.txt"), "r");
new FileWordList(raf, true, 1);
For small files that use a small cache, the cache buffer that is generated can be too small. This is due to how the cache is generated. In the constructor of cache the cacheSize is computed as:
final long cacheSize = (fileSize / 100) * cachePercent;
If this cacheSize is larger than 0, then used in resize(..) to create a ByteBuffer using:
This ByteBuffer is then converted to a longBuffer using:
Assume that the ByteBuffer is generated (cacheSize is larger than 0), then replacing the cacheSize formula in the ByteBuffer allocation, you get this:
The error happens when the ByteBuffer generated by allocate is less than 8 bytes, as asLongBuffer will then convert it to a long buffer of size 0 (allocateSize divided by 8, integer). When trying to putting values in an empty buffer, the BufferOverflowException is thrown.
Edit: It can also fail when the buffer is resized when calling cache.put(..).
A workaround is too disable the cache (cachePercent 0), use a cachePercent of at least 8, or not use small files. A fix would probably be to check for a too small cacheSize (< 8 ), and allocate at least 8 bytes in that case.
The text was updated successfully, but these errors were encountered: