You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2023/01/20 17:05:23 UTC
[sis] 01/02: Fix an `EOFException` occuring randomly during some tests.
This is an automated email from the ASF dual-hosted git repository.
desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git
commit 2172755ae0f84fc315a981dd5cb4c2759fc9552c
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Fri Jan 20 11:10:01 2023 +0100
Fix an `EOFException` occuring randomly during some tests.
---
.../java/org/apache/sis/internal/storage/io/FileCacheByteChannel.java | 2 +-
.../java/org/apache/sis/internal/storage/io/ComputedInputStream.java | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/FileCacheByteChannel.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/FileCacheByteChannel.java
index 96fb66993e..5557d651ac 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/FileCacheByteChannel.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/FileCacheByteChannel.java
@@ -543,10 +543,10 @@ public abstract class FileCacheByteChannel implements SeekableByteChannel {
* Transfer bytes from the input stream to the buffer. The bytes are also copied to the temporary file.
* We try to use `dst` instead of `buffer` in call to `cache(…)` because the former may be a direct buffer.
*/
- final ByteBuffer slice = dst.slice();
count = c.input.read(buffer.array(), Math.addExact(buffer.arrayOffset(), buffer.position()), buffer.remaining());
if (count > 0) {
position += count;
+ final ByteBuffer slice = dst.slice();
if (buffer != dst) {
dst.put(buffer.limit(count)); // Transfer from temporary buffer to destination buffer.
} else {
diff --git a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/io/ComputedInputStream.java b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/io/ComputedInputStream.java
index 47106d17cd..566ff663b5 100644
--- a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/io/ComputedInputStream.java
+++ b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/io/ComputedInputStream.java
@@ -113,8 +113,8 @@ final class ComputedInputStream extends InputStream {
return -1;
}
if (count != 0) {
- final int end = Math.min(offset + random.nextInt(count) + 1, length);
- count = end - offset;
+ count = Math.min(random.nextInt(count) + 1, length - position);
+ final int end = offset + count;
while (offset < end) {
bytes[offset++] = valueAt(position++);
}