diff --git a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Audio.java b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Audio.java index cb88360079f..21d06d2dcbc 100644 --- a/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Audio.java +++ b/bundles/org.openhab.core.model.script/src/org/openhab/core/model/script/actions/Audio.java @@ -139,7 +139,7 @@ public static void increaseMasterVolume(@ParamDoc(name = "percent") final float if (newVolume - volume < .01) { // the getMasterVolume() may only returns integers, so we have to make sure that we // increase the volume level at least by 1%. - newVolume += .01; + newVolume += .01f; } if (newVolume > 1) { newVolume = 1; diff --git a/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/java/JavaTest.java b/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/java/JavaTest.java index ff22c06fd2a..df48267e90d 100644 --- a/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/java/JavaTest.java +++ b/bundles/org.openhab.core.test/src/main/java/org/openhab/core/test/java/JavaTest.java @@ -145,7 +145,7 @@ protected boolean waitFor(BooleanSupplier condition) { * @return true on success, false on timeout */ protected boolean waitFor(BooleanSupplier condition, long timeout, long sleepTime) { - int waitingTime = 0; + long waitingTime = 0; boolean rv; while (!(rv = condition.getAsBoolean()) && waitingTime < timeout) { waitingTime += sleepTime; diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/cache/lru/InputStreamCacheWrapper.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/cache/lru/InputStreamCacheWrapper.java index 965b0115db4..3a64ca076cc 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/cache/lru/InputStreamCacheWrapper.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/cache/lru/InputStreamCacheWrapper.java @@ -89,7 +89,10 @@ public int read(byte @Nullable [] b, int off, int len) throws IOException { @Override public long skip(long n) throws IOException { - offset += n; + if (n > Integer.MAX_VALUE || n < Integer.MIN_VALUE) { + throw new IOException("Invalid offset, exceeds Integer range"); + } + offset += (int) n; return n; } @@ -103,7 +106,7 @@ public void close() throws IOException { } public long length() { - Long totalSize = cacheEntry.getTotalSize(); + long totalSize = cacheEntry.getTotalSize(); if (totalSize > 0L) { return totalSize; } 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 2a6e07aa893..b4d0de9920b 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 @@ -127,7 +127,7 @@ protected void setCacheContext(Path cacheDirectory, Storage storage) { * * @return */ - protected Long getTotalSize() { + protected long getTotalSize() { if (completed) { // we already know the total size of the sound return currentSize; } else { @@ -323,7 +323,9 @@ protected int availableFrom(int offset) { return 0; } try { - return Math.max(0, Long.valueOf(fileChannelLocal.size() - offset).intValue()); + long nBytes = Math.min(Integer.MAX_VALUE, Math.max(0, fileChannelLocal.size() - offset)); + // nBytes is for sure in integer range, safe to cast + return (int) nBytes; } catch (IOException e) { logger.debug("Cannot get file length for cache file {}", key); return 0; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/JavaTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/JavaTest.java index 34f188078f5..2f3f72853f7 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/JavaTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/JavaTest.java @@ -52,7 +52,7 @@ protected boolean waitFor(BooleanSupplier condition) { * @return true on success, false on timeout */ protected boolean waitFor(BooleanSupplier condition, long timeout, long sleepTime) { - int waitingTime = 0; + long waitingTime = 0; boolean rv; while (!(rv = condition.getAsBoolean()) && waitingTime < timeout) { waitingTime += sleepTime;