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-crypto.git
The following commit(s) were added to refs/heads/master by this push: new 4c2fa88 Minor bullet-proofing 4c2fa88 is described below commit 4c2fa88f16b96d150fef4553a4674d23c627e22a Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sun Dec 11 10:52:59 2022 -0500 Minor bullet-proofing --- .../commons/crypto/stream/CryptoInputStream.java | 42 +++++++++++----------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java index bf939b0..bc5a16e 100644 --- a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java +++ b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java @@ -210,8 +210,7 @@ public class CryptoInputStream extends InputStream implements } inBuffer = ByteBuffer.allocateDirect(this.bufferSize); - outBuffer = ByteBuffer.allocateDirect(this.bufferSize - + cipher.getBlockSize()); + outBuffer = ByteBuffer.allocateDirect(this.bufferSize + cipher.getBlockSize()); outBuffer.limit(0); initCipher(); @@ -587,26 +586,29 @@ public class CryptoInputStream extends InputStream implements * @param buffer the bytebuffer to be freed. */ static void freeDirectBuffer(final ByteBuffer buffer) { - try { - /* Using reflection to implement sun.nio.ch.DirectBuffer.cleaner() - .clean(); */ - final String SUN_CLASS = "sun.nio.ch.DirectBuffer"; - final Class<?>[] interfaces = buffer.getClass().getInterfaces(); - final Object[] EMPTY_OBJECT_ARRAY = {}; - - for (final Class<?> clazz : interfaces) { - if (clazz.getName().equals(SUN_CLASS)) { - /* DirectBuffer#cleaner() */ - final Method getCleaner = Class.forName(SUN_CLASS).getMethod("cleaner"); - final Object cleaner = getCleaner.invoke(buffer, EMPTY_OBJECT_ARRAY); - /* Cleaner#clean() */ - final Method cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean"); - cleanMethod.invoke(cleaner, EMPTY_OBJECT_ARRAY); - return; + if (buffer != null) { + try { + /* + * Using reflection to implement sun.nio.ch.DirectBuffer.cleaner() .clean(); + */ + final String SUN_CLASS = "sun.nio.ch.DirectBuffer"; + final Class<?>[] interfaces = buffer.getClass().getInterfaces(); + final Object[] EMPTY_OBJECT_ARRAY = {}; + + for (final Class<?> clazz : interfaces) { + if (clazz.getName().equals(SUN_CLASS)) { + /* DirectBuffer#cleaner() */ + final Method getCleaner = Class.forName(SUN_CLASS).getMethod("cleaner"); + final Object cleaner = getCleaner.invoke(buffer, EMPTY_OBJECT_ARRAY); + /* Cleaner#clean() */ + final Method cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean"); + cleanMethod.invoke(cleaner, EMPTY_OBJECT_ARRAY); + return; + } } + } catch (final ReflectiveOperationException e) { // NOPMD + // Ignore the Reflection exception. } - } catch (final ReflectiveOperationException e) { // NOPMD - // Ignore the Reflection exception. } }