From 3ddbdb25ed274bcd3a9fc02899efee6bc6de72eb Mon Sep 17 00:00:00 2001 From: Gwendal Roulleau Date: Wed, 30 Aug 2023 14:23:35 +0200 Subject: [PATCH] [cache] Fix concurrent use of a cache entry (#3785) Closes #3507 Fix some rare case where the concurrent readings of a cache entry can fail. Signed-off-by: Gwendal Roulleau --- .../java/org/openhab/core/cache/lru/LRUMediaCacheEntry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/cache/lru/LRUMediaCacheEntry.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/cache/lru/LRUMediaCacheEntry.java index 8bf60773cc8..04bb68dba93 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/cache/lru/LRUMediaCacheEntry.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/cache/lru/LRUMediaCacheEntry.java @@ -296,7 +296,7 @@ protected byte[] read(int start, int sizeToRead) throws IOException { } } // the cache file is now filled, get bytes from it. - long maxToRead = Math.min(currentSize, sizeToRead); + long maxToRead = Math.min(fileChannelLocal.size(), sizeToRead); ByteBuffer byteBufferFromChannelFile = ByteBuffer.allocate((int) maxToRead); int byteReadNumber = fileChannelLocal.read(byteBufferFromChannelFile, Integer.valueOf(start).longValue()); logger.trace("Read {} bytes from the filechannel", byteReadNumber);