You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2016/06/16 14:09:51 UTC

commons-crypto git commit: Don't try to instantiate class unless it is necessary

Repository: commons-crypto
Updated Branches:
  refs/heads/master c282329b3 -> 11ba975cd


Don't try to instantiate class unless it is necessary

Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/11ba975c
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/11ba975c
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/11ba975c

Branch: refs/heads/master
Commit: 11ba975cdcde5bc7ce0ccebf141ed0069202683f
Parents: c282329
Author: Sebb <se...@apache.org>
Authored: Thu Jun 16 15:09:47 2016 +0100
Committer: Sebb <se...@apache.org>
Committed: Thu Jun 16 15:09:47 2016 +0100

----------------------------------------------------------------------
 src/main/java/org/apache/commons/crypto/utils/Utils.java | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/11ba975c/src/main/java/org/apache/commons/crypto/utils/Utils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/utils/Utils.java b/src/main/java/org/apache/commons/crypto/utils/Utils.java
index b41045c..5507de2 100644
--- a/src/main/java/org/apache/commons/crypto/utils/Utils.java
+++ b/src/main/java/org/apache/commons/crypto/utils/Utils.java
@@ -110,19 +110,17 @@ public final class Utils {
         try {
             /* Using reflection to implement sun.nio.ch.DirectBuffer.cleaner()
             .clean(); */
-            Class<?> sunClass = Class.forName("sun.nio.ch.DirectBuffer");
-            Class<?> cleanerClass = Class.forName("sun.misc.Cleaner");
-
+            final String SUN_CLASS = "sun.nio.ch.DirectBuffer";
             Class<?>[] interfaces = buffer.getClass().getInterfaces();
 
             for (Class<?> clazz : interfaces) {
-                if (clazz.getName().equals(sunClass.getName())) {
+                if (clazz.getName().equals(SUN_CLASS)) {
                     final Object[] NO_PARAM = new Object[0];
                     /* DirectBuffer#cleaner() */
-                    Method getCleaner = sunClass.getMethod("cleaner");
+                    Method getCleaner = Class.forName(SUN_CLASS).getMethod("cleaner");
                     Object cleaner = getCleaner.invoke(buffer, NO_PARAM);
                     /* Cleaner#clean() */
-                    Method cleanMethod = cleanerClass.getMethod("clean");
+                    Method cleanMethod = Class.forName("sun.misc.Cleaner").getMethod("clean");
                     cleanMethod.invoke(cleaner, NO_PARAM);
                     return;
                 }