You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/05/17 14:44:33 UTC
(commons-compress) branch master updated (84788735b -> aab830d13)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
from 84788735b Use try-with-resources
new cff82b424 Use try-with-resources
new 6a5d4ba3b Better internal name
new aab830d13 Avoid NullPointerException in java.nio.channels.spi.AbstractInterruptibleChannel.close() when calling org.apache.commons.compress.archivers.zip.FileRandomAccessOutputStream.close()
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/changes/changes.xml | 1 +
.../archivers/zip/FileRandomAccessOutputStream.java | 4 +++-
.../utils/MultiReadOnlySeekableByteChannel.java | 20 ++++++++++----------
.../zip/FileRandomAccessOutputStreamTest.java | 15 ++++++++++++---
.../ZipSplitReadOnlySeekableByteChannelTest.java | 7 ++++---
5 files changed, 30 insertions(+), 17 deletions(-)
(commons-compress) 02/03: Better internal name
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 6a5d4ba3b4326b3ccd26b431af64e73f59301ec8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri May 17 10:26:06 2024 -0400
Better internal name
---
.../utils/MultiReadOnlySeekableByteChannel.java | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannel.java b/src/main/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannel.java
index c6e02c2e2..e7bcae73f 100644
--- a/src/main/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannel.java
+++ b/src/main/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannel.java
@@ -99,7 +99,7 @@ public class MultiReadOnlySeekableByteChannel implements SeekableByteChannel {
return new MultiReadOnlySeekableByteChannel(Arrays.asList(channels));
}
- private final List<SeekableByteChannel> channels;
+ private final List<SeekableByteChannel> channelList;
private long globalPosition;
@@ -112,13 +112,13 @@ public class MultiReadOnlySeekableByteChannel implements SeekableByteChannel {
* @throws NullPointerException if channels is null
*/
public MultiReadOnlySeekableByteChannel(final List<SeekableByteChannel> channels) {
- this.channels = Collections.unmodifiableList(new ArrayList<>(Objects.requireNonNull(channels, "channels")));
+ this.channelList = Collections.unmodifiableList(new ArrayList<>(Objects.requireNonNull(channels, "channels")));
}
@Override
public void close() throws IOException {
IOException first = null;
- for (final SeekableByteChannel ch : channels) {
+ for (final SeekableByteChannel ch : channelList) {
try {
ch.close();
} catch (final IOException ex) {
@@ -134,7 +134,7 @@ public class MultiReadOnlySeekableByteChannel implements SeekableByteChannel {
@Override
public boolean isOpen() {
- return channels.stream().allMatch(SeekableByteChannel::isOpen);
+ return channelList.stream().allMatch(SeekableByteChannel::isOpen);
}
/**
@@ -159,8 +159,8 @@ public class MultiReadOnlySeekableByteChannel implements SeekableByteChannel {
}
globalPosition = newPosition;
long pos = newPosition;
- for (int i = 0; i < channels.size(); i++) {
- final SeekableByteChannel currentChannel = channels.get(i);
+ for (int i = 0; i < channelList.size(); i++) {
+ final SeekableByteChannel currentChannel = channelList.get(i);
final long size = currentChannel.size();
final long newChannelPos;
@@ -200,7 +200,7 @@ public class MultiReadOnlySeekableByteChannel implements SeekableByteChannel {
}
long globalPosition = relativeOffset;
for (int i = 0; i < channelNumber; i++) {
- globalPosition += channels.get(i).size();
+ globalPosition += channelList.get(i).size();
}
return position(globalPosition);
@@ -216,8 +216,8 @@ public class MultiReadOnlySeekableByteChannel implements SeekableByteChannel {
}
int totalBytesRead = 0;
- while (dst.hasRemaining() && currentChannelIdx < channels.size()) {
- final SeekableByteChannel currentChannel = channels.get(currentChannelIdx);
+ while (dst.hasRemaining() && currentChannelIdx < channelList.size()) {
+ final SeekableByteChannel currentChannel = channelList.get(currentChannelIdx);
final int newBytesRead = currentChannel.read(dst);
if (newBytesRead == -1) {
// EOF for this channel -- advance to next channel idx
@@ -243,7 +243,7 @@ public class MultiReadOnlySeekableByteChannel implements SeekableByteChannel {
throw new ClosedChannelException();
}
long acc = 0;
- for (final SeekableByteChannel ch : channels) {
+ for (final SeekableByteChannel ch : channelList) {
acc += ch.size();
}
return acc;
(commons-compress) 03/03: Avoid NullPointerException in java.nio.channels.spi.AbstractInterruptibleChannel.close() when calling org.apache.commons.compress.archivers.zip.FileRandomAccessOutputStream.close()
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit aab830d131e9df3f1ca2e4701d25d7ededb5f62a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri May 17 10:44:28 2024 -0400
Avoid NullPointerException in
java.nio.channels.spi.AbstractInterruptibleChannel.close() when calling
org.apache.commons.compress.archivers.zip.FileRandomAccessOutputStream.close()
---
src/changes/changes.xml | 1 +
.../archivers/zip/FileRandomAccessOutputStream.java | 4 +++-
.../archivers/zip/FileRandomAccessOutputStreamTest.java | 15 ++++++++++++---
3 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 8c3c6fc0f..bcf059fa2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -57,6 +57,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">ArArchiveOutputStream implicit narrowing conversion in compound assignment.</action>
<action type="fix" issue="COMPRESS-679" dev="ggregory" due-to="Mikaƫl MECHOULAM, Gary Gregory">Regression on parallel processing of 7zip files.</action>
<action type="fix" issue="COMPRESS-675" dev="ggregory" due-to="Tim Allison, Gary Gregory">Regression in pack200's Archive class -- underlying InputStream is now closed.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Avoid NullPointerException in java.nio.channels.spi.AbstractInterruptibleChannel.close() when calling org.apache.commons.compress.archivers.zip.FileRandomAccessOutputStream.close().</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump org.apache.commons:commons-parent from 66 to 69 #495, #508.</action>
<action type="update" dev="ggregory" due-to="Dependabot, Gary Gregory">Bump org.ow2.asm:asm from 9.6 to 9.7 #504.</action>
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStream.java
index 7083998c4..319d2f6fa 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStream.java
@@ -52,7 +52,9 @@ class FileRandomAccessOutputStream extends RandomAccessOutputStream {
@Override
public void close() throws IOException {
- channel.close();
+ if (channel.isOpen()) {
+ channel.close();
+ }
}
@Override
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStreamTest.java
index 7cccd2514..1c563c250 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/FileRandomAccessOutputStreamTest.java
@@ -48,10 +48,20 @@ public class FileRandomAccessOutputStreamTest extends AbstractTempDirTest {
}
}
+ @Test
+ public void testClose() throws IOException {
+ final Path file = newTempPath("testChannel");
+ try (FileRandomAccessOutputStream stream = new FileRandomAccessOutputStream(file)) {
+ assertNotNull(stream.channel());
+ stream.close();
+ stream.close();
+ }
+ }
+
@Test
public void testWrite() throws IOException {
- final FileChannel channel = mock(FileChannel.class);
- final FileRandomAccessOutputStream stream = new FileRandomAccessOutputStream(channel);
+ FileChannel channel = mock(FileChannel.class);
+ FileRandomAccessOutputStream stream = new FileRandomAccessOutputStream(channel);
when(channel.write((ByteBuffer) any())).thenAnswer(answer -> {
((ByteBuffer) answer.getArgument(0)).position(5);
return 5;
@@ -62,7 +72,6 @@ public class FileRandomAccessOutputStreamTest extends AbstractTempDirTest {
stream.write("hello".getBytes(StandardCharsets.UTF_8));
stream.write("world\n".getBytes(StandardCharsets.UTF_8));
verify(channel, times(2)).write((ByteBuffer) any());
-
assertEquals(11, stream.position());
}
(commons-compress) 01/03: Use try-with-resources
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit cff82b4249bed4d9e3d6cf7da557216388df9bd5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri May 17 10:24:56 2024 -0400
Use try-with-resources
---
.../compress/utils/ZipSplitReadOnlySeekableByteChannelTest.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/test/java/org/apache/commons/compress/utils/ZipSplitReadOnlySeekableByteChannelTest.java b/src/test/java/org/apache/commons/compress/utils/ZipSplitReadOnlySeekableByteChannelTest.java
index fddc1f26f..d1d6f79e6 100644
--- a/src/test/java/org/apache/commons/compress/utils/ZipSplitReadOnlySeekableByteChannelTest.java
+++ b/src/test/java/org/apache/commons/compress/utils/ZipSplitReadOnlySeekableByteChannelTest.java
@@ -62,9 +62,10 @@ public class ZipSplitReadOnlySeekableByteChannelTest {
@Test
public void testChannelsPositionIsZeroAfterConstructor() throws IOException {
final List<SeekableByteChannel> channels = getSplitZipChannels();
- new ZipSplitReadOnlySeekableByteChannel(channels);
- for (final SeekableByteChannel channel : channels) {
- assertEquals(0, channel.position());
+ try (ZipSplitReadOnlySeekableByteChannel c = new ZipSplitReadOnlySeekableByteChannel(channels)) {
+ for (final SeekableByteChannel channel : channels) {
+ assertEquals(0, channel.position());
+ }
}
}