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-io.git
commit 0ac2e28a2e9913eb32b197d77305c20ce5bd9499 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Fri Apr 28 16:47:34 2023 -0400 Spotbugs: Make a defensive copy of array Setting to null resets to default --- src/main/java/org/apache/commons/io/input/BOMInputStream.java | 10 ++++++---- .../java/org/apache/commons/io/input/BOMInputStreamTest.java | 7 ++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/commons/io/input/BOMInputStream.java b/src/main/java/org/apache/commons/io/input/BOMInputStream.java index 9d07afca..d9d9560a 100644 --- a/src/main/java/org/apache/commons/io/input/BOMInputStream.java +++ b/src/main/java/org/apache/commons/io/input/BOMInputStream.java @@ -107,8 +107,10 @@ public class BOMInputStream extends ProxyInputStream { */ public static class Builder extends AbstractStreamBuilder<BOMInputStream, Builder> { + static final ByteOrderMark[] DEFAULT = { ByteOrderMark.UTF_8 }; + private boolean include; - private ByteOrderMark[] byteOrderMarks = { ByteOrderMark.UTF_8 }; + private ByteOrderMark[] byteOrderMarks = DEFAULT; @SuppressWarnings("resource") @Override @@ -123,7 +125,7 @@ public class BOMInputStream extends ProxyInputStream { * @return this */ public Builder setByteOrderMarks(final ByteOrderMark[] byteOrderMarks) { - this.byteOrderMarks = byteOrderMarks; + this.byteOrderMarks = byteOrderMarks != null ? byteOrderMarks.clone() : DEFAULT; return this; } @@ -177,7 +179,7 @@ public class BOMInputStream extends ProxyInputStream { */ @Deprecated public BOMInputStream(final InputStream delegate) { - this(delegate, false, ByteOrderMark.UTF_8); + this(delegate, false, Builder.DEFAULT); } /** @@ -191,7 +193,7 @@ public class BOMInputStream extends ProxyInputStream { */ @Deprecated public BOMInputStream(final InputStream delegate, final boolean include) { - this(delegate, include, ByteOrderMark.UTF_8); + this(delegate, include, Builder.DEFAULT); } /** diff --git a/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java b/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java index decc6929..411b26f4 100644 --- a/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java +++ b/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java @@ -404,12 +404,13 @@ public class BOMInputStreamTest { assertThrows(IllegalArgumentException.class, () -> new BOMInputStream(createUtf8Input(data, true), false, (ByteOrderMark[]) null).close()); assertThrows(IllegalArgumentException.class, () -> new BOMInputStream(createUtf8Input(data, true), false, new ByteOrderMark[0]).close()); // - assertThrows(IllegalArgumentException.class, () -> BOMInputStream.builder() + try (final BOMInputStream bomInputStream = BOMInputStream.builder() .setInputStream(createUtf8Input(data, true)) .setInclude(true) .setByteOrderMarks((ByteOrderMark[]) null) - .get() - .close()); + .get()) { + assertEquals(BOMInputStream.Builder.DEFAULT[0], bomInputStream.getBOM()); + } assertThrows(IllegalArgumentException.class, () -> BOMInputStream.builder() .setInputStream(createUtf8Input(data, true)) .setInclude(true)