Skip to content

Commit 85e6822

Browse files
committed
Use Objects.requireNonNull() instead of custom check. Minor formatting.
1 parent d58689c commit 85e6822

4 files changed

Lines changed: 23 additions & 27 deletions

File tree

src/main/java/org/apache/commons/codec/binary/Base64.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.commons.codec.binary;
1919

2020
import java.math.BigInteger;
21+
import java.util.Objects;
2122

2223
/**
2324
* Provides Base64 encoding and decoding as defined by <a href="http://www.ietf.org/rfc/rfc2045.txt">RFC 2045</a>.
@@ -730,18 +731,16 @@ public static BigInteger decodeInteger(final byte[] pArray) {
730731
/**
731732
* Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature.
732733
*
733-
* @param bigInt
734+
* @param bigInteger
734735
* a BigInteger
735736
* @return A byte array containing base64 character data
736737
* @throws NullPointerException
737738
* if null is passed in
738739
* @since 1.4
739740
*/
740-
public static byte[] encodeInteger(final BigInteger bigInt) {
741-
if (bigInt == null) {
742-
throw new NullPointerException("encodeInteger called with null parameter");
743-
}
744-
return encodeBase64(toIntegerBytes(bigInt), false);
741+
public static byte[] encodeInteger(final BigInteger bigInteger) {
742+
Objects.requireNonNull(bigInteger, "bigInteger");
743+
return encodeBase64(toIntegerBytes(bigInteger), false);
745744
}
746745

747746
/**

src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.FilterInputStream;
2323
import java.io.IOException;
2424
import java.io.InputStream;
25+
import java.util.Objects;
2526

2627
import org.apache.commons.codec.binary.BaseNCodec.Context;
2728

@@ -110,7 +111,7 @@ public int read() throws IOException {
110111
* Attempts to read {@code len} bytes into the specified {@code b} array starting at {@code offset}
111112
* from this InputStream.
112113
*
113-
* @param b
114+
* @param array
114115
* destination byte array
115116
* @param offset
116117
* where to start writing the bytes
@@ -126,12 +127,11 @@ public int read() throws IOException {
126127
* if offset, len or buffer size are invalid
127128
*/
128129
@Override
129-
public int read(final byte b[], final int offset, final int len) throws IOException {
130-
if (b == null) {
131-
throw new NullPointerException();
132-
} else if (offset < 0 || len < 0) {
130+
public int read(final byte array[], final int offset, final int len) throws IOException {
131+
Objects.requireNonNull(array, "array");
132+
if (offset < 0 || len < 0) {
133133
throw new IndexOutOfBoundsException();
134-
} else if (offset > b.length || offset + len > b.length) {
134+
} else if (offset > array.length || offset + len > array.length) {
135135
throw new IndexOutOfBoundsException();
136136
} else if (len == 0) {
137137
return 0;
@@ -163,7 +163,7 @@ public int read(final byte b[], final int offset, final int len) throws IOExcept
163163
baseNCodec.decode(buf, 0, c, context);
164164
}
165165
}
166-
readLen = baseNCodec.readResults(b, offset, len, context);
166+
readLen = baseNCodec.readResults(array, offset, len, context);
167167
}
168168
return readLen;
169169
}

src/main/java/org/apache/commons/codec/binary/BaseNCodecOutputStream.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.FilterOutputStream;
2323
import java.io.IOException;
2424
import java.io.OutputStream;
25+
import java.util.Objects;
2526

2627
import org.apache.commons.codec.binary.BaseNCodec.Context;
2728

@@ -71,7 +72,7 @@ public void write(final int i) throws IOException {
7172
* Writes {@code len} bytes from the specified {@code b} array starting at {@code offset} to this
7273
* output stream.
7374
*
74-
* @param b
75+
* @param array
7576
* source byte array
7677
* @param offset
7778
* where to start reading the bytes
@@ -86,18 +87,17 @@ public void write(final int i) throws IOException {
8687
* if offset, len or buffer size are invalid
8788
*/
8889
@Override
89-
public void write(final byte b[], final int offset, final int len) throws IOException {
90-
if (b == null) {
91-
throw new NullPointerException();
92-
} else if (offset < 0 || len < 0) {
90+
public void write(final byte array[], final int offset, final int len) throws IOException {
91+
Objects.requireNonNull(array, "array");
92+
if (offset < 0 || len < 0) {
9393
throw new IndexOutOfBoundsException();
94-
} else if (offset > b.length || offset + len > b.length) {
94+
} else if (offset > array.length || offset + len > array.length) {
9595
throw new IndexOutOfBoundsException();
9696
} else if (len > 0) {
9797
if (doEncode) {
98-
baseNCodec.encode(b, offset, len, context);
98+
baseNCodec.encode(array, offset, len, context);
9999
} else {
100-
baseNCodec.decode(b, offset, len, context);
100+
baseNCodec.decode(array, offset, len, context);
101101
}
102102
flush(false);
103103
}

src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.List;
2828
import java.util.Locale;
2929
import java.util.Map;
30+
import java.util.Objects;
3031
import java.util.Set;
3132
import java.util.TreeMap;
3233

@@ -177,9 +178,7 @@ private static final class RulesApplication {
177178

178179
public RulesApplication(final Map<String, List<Rule>> finalRules, final CharSequence input,
179180
final PhonemeBuilder phonemeBuilder, final int i, final int maxPhonemes) {
180-
if (finalRules == null) {
181-
throw new NullPointerException("The finalRules argument must not be null");
182-
}
181+
Objects.requireNonNull(finalRules, "finalRules");
183182
this.finalRules = finalRules;
184183
this.phonemeBuilder = phonemeBuilder;
185184
this.input = input;
@@ -327,9 +326,7 @@ public PhoneticEngine(final NameType nameType, final RuleType ruleType, final bo
327326
*/
328327
private PhonemeBuilder applyFinalRules(final PhonemeBuilder phonemeBuilder,
329328
final Map<String, List<Rule>> finalRules) {
330-
if (finalRules == null) {
331-
throw new NullPointerException("finalRules can not be null");
332-
}
329+
Objects.requireNonNull(finalRules, "finalRules");
333330
if (finalRules.isEmpty()) {
334331
return phonemeBuilder;
335332
}

0 commit comments

Comments
 (0)