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 2019/12/25 23:38:00 UTC
[commons-codec] branch master updated: Use Objects.requireNonNull()
instead of custom check. Minor formatting.
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-codec.git
The following commit(s) were added to refs/heads/master by this push:
new 85e6822 Use Objects.requireNonNull() instead of custom check. Minor formatting.
85e6822 is described below
commit 85e68226ed1a382e5a4e757ae944ef63b3e7b787
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Dec 25 18:37:56 2019 -0500
Use Objects.requireNonNull() instead of custom check. Minor formatting.
---
.../java/org/apache/commons/codec/binary/Base64.java | 11 +++++------
.../commons/codec/binary/BaseNCodecInputStream.java | 14 +++++++-------
.../commons/codec/binary/BaseNCodecOutputStream.java | 16 ++++++++--------
.../apache/commons/codec/language/bm/PhoneticEngine.java | 9 +++------
4 files changed, 23 insertions(+), 27 deletions(-)
diff --git a/src/main/java/org/apache/commons/codec/binary/Base64.java b/src/main/java/org/apache/commons/codec/binary/Base64.java
index 02bfa37..caf6621 100644
--- a/src/main/java/org/apache/commons/codec/binary/Base64.java
+++ b/src/main/java/org/apache/commons/codec/binary/Base64.java
@@ -18,6 +18,7 @@
package org.apache.commons.codec.binary;
import java.math.BigInteger;
+import java.util.Objects;
/**
* 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 class Base64 extends BaseNCodec {
/**
* Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature.
*
- * @param bigInt
+ * @param bigInteger
* a BigInteger
* @return A byte array containing base64 character data
* @throws NullPointerException
* if null is passed in
* @since 1.4
*/
- public static byte[] encodeInteger(final BigInteger bigInt) {
- if (bigInt == null) {
- throw new NullPointerException("encodeInteger called with null parameter");
- }
- return encodeBase64(toIntegerBytes(bigInt), false);
+ public static byte[] encodeInteger(final BigInteger bigInteger) {
+ Objects.requireNonNull(bigInteger, "bigInteger");
+ return encodeBase64(toIntegerBytes(bigInteger), false);
}
/**
diff --git a/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java b/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java
index 567563c..19d5a77 100644
--- a/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java
+++ b/src/main/java/org/apache/commons/codec/binary/BaseNCodecInputStream.java
@@ -22,6 +22,7 @@ import static org.apache.commons.codec.binary.BaseNCodec.EOF;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Objects;
import org.apache.commons.codec.binary.BaseNCodec.Context;
@@ -110,7 +111,7 @@ public class BaseNCodecInputStream extends FilterInputStream {
* Attempts to read {@code len} bytes into the specified {@code b} array starting at {@code offset}
* from this InputStream.
*
- * @param b
+ * @param array
* destination byte array
* @param offset
* where to start writing the bytes
@@ -126,12 +127,11 @@ public class BaseNCodecInputStream extends FilterInputStream {
* if offset, len or buffer size are invalid
*/
@Override
- public int read(final byte b[], final int offset, final int len) throws IOException {
- if (b == null) {
- throw new NullPointerException();
- } else if (offset < 0 || len < 0) {
+ public int read(final byte array[], final int offset, final int len) throws IOException {
+ Objects.requireNonNull(array, "array");
+ if (offset < 0 || len < 0) {
throw new IndexOutOfBoundsException();
- } else if (offset > b.length || offset + len > b.length) {
+ } else if (offset > array.length || offset + len > array.length) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
@@ -163,7 +163,7 @@ public class BaseNCodecInputStream extends FilterInputStream {
baseNCodec.decode(buf, 0, c, context);
}
}
- readLen = baseNCodec.readResults(b, offset, len, context);
+ readLen = baseNCodec.readResults(array, offset, len, context);
}
return readLen;
}
diff --git a/src/main/java/org/apache/commons/codec/binary/BaseNCodecOutputStream.java b/src/main/java/org/apache/commons/codec/binary/BaseNCodecOutputStream.java
index 3b365a6..bad975c 100644
--- a/src/main/java/org/apache/commons/codec/binary/BaseNCodecOutputStream.java
+++ b/src/main/java/org/apache/commons/codec/binary/BaseNCodecOutputStream.java
@@ -22,6 +22,7 @@ import static org.apache.commons.codec.binary.BaseNCodec.EOF;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Objects;
import org.apache.commons.codec.binary.BaseNCodec.Context;
@@ -71,7 +72,7 @@ public class BaseNCodecOutputStream extends FilterOutputStream {
* Writes {@code len} bytes from the specified {@code b} array starting at {@code offset} to this
* output stream.
*
- * @param b
+ * @param array
* source byte array
* @param offset
* where to start reading the bytes
@@ -86,18 +87,17 @@ public class BaseNCodecOutputStream extends FilterOutputStream {
* if offset, len or buffer size are invalid
*/
@Override
- public void write(final byte b[], final int offset, final int len) throws IOException {
- if (b == null) {
- throw new NullPointerException();
- } else if (offset < 0 || len < 0) {
+ public void write(final byte array[], final int offset, final int len) throws IOException {
+ Objects.requireNonNull(array, "array");
+ if (offset < 0 || len < 0) {
throw new IndexOutOfBoundsException();
- } else if (offset > b.length || offset + len > b.length) {
+ } else if (offset > array.length || offset + len > array.length) {
throw new IndexOutOfBoundsException();
} else if (len > 0) {
if (doEncode) {
- baseNCodec.encode(b, offset, len, context);
+ baseNCodec.encode(array, offset, len, context);
} else {
- baseNCodec.decode(b, offset, len, context);
+ baseNCodec.decode(array, offset, len, context);
}
flush(false);
}
diff --git a/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java b/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
index 1f2c78d..3f58b85 100644
--- a/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
+++ b/src/main/java/org/apache/commons/codec/language/bm/PhoneticEngine.java
@@ -27,6 +27,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
@@ -177,9 +178,7 @@ public class PhoneticEngine {
public RulesApplication(final Map<String, List<Rule>> finalRules, final CharSequence input,
final PhonemeBuilder phonemeBuilder, final int i, final int maxPhonemes) {
- if (finalRules == null) {
- throw new NullPointerException("The finalRules argument must not be null");
- }
+ Objects.requireNonNull(finalRules, "finalRules");
this.finalRules = finalRules;
this.phonemeBuilder = phonemeBuilder;
this.input = input;
@@ -327,9 +326,7 @@ public class PhoneticEngine {
*/
private PhonemeBuilder applyFinalRules(final PhonemeBuilder phonemeBuilder,
final Map<String, List<Rule>> finalRules) {
- if (finalRules == null) {
- throw new NullPointerException("finalRules can not be null");
- }
+ Objects.requireNonNull(finalRules, "finalRules");
if (finalRules.isEmpty()) {
return phonemeBuilder;
}