commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject commons-crypto git commit: CRYPTO-80: Fix the pmd error
Date Fri, 17 Jun 2016 07:47:27 GMT
Repository: commons-crypto
Updated Branches:
  refs/heads/master 11ba975cd -> 18ac95b5e


CRYPTO-80: Fix the pmd error


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

Branch: refs/heads/master
Commit: 18ac95b5e51e54221666262d64afe24b89cd0dc5
Parents: 11ba975
Author: JKSelf <ke.a.jia@intel.com>
Authored: Thu Jun 16 16:08:24 2016 +0800
Committer: Sun Dapeng <sdp@apache.org>
Committed: Fri Jun 17 15:42:19 2016 +0800

----------------------------------------------------------------------
 .../apache/commons/crypto/cipher/Openssl.java   |  2 +-
 .../crypto/random/CryptoRandomFactory.java      |  6 +-
 .../commons/crypto/random/OsCryptoRandom.java   |  2 +-
 .../crypto/stream/CryptoInputStream.java        |  1 +
 .../commons/crypto/utils/NativeCodeLoader.java  | 10 ++--
 .../org/apache/commons/crypto/utils/OSInfo.java |  4 +-
 .../org/apache/commons/crypto/utils/Utils.java  | 58 ++++++++------------
 7 files changed, 35 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/18ac95b5/src/main/java/org/apache/commons/crypto/cipher/Openssl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/cipher/Openssl.java b/src/main/java/org/apache/commons/crypto/cipher/Openssl.java
index 2837761..34989ed 100644
--- a/src/main/java/org/apache/commons/crypto/cipher/Openssl.java
+++ b/src/main/java/org/apache/commons/crypto/cipher/Openssl.java
@@ -142,7 +142,7 @@ final class Openssl {
      * @throws NoSuchPaddingException if <code>transformation</code> contains
a
      *         padding scheme that is not available.
      */
-    public static final Openssl getInstance(String transformation)
+    public static Openssl getInstance(String transformation)
             throws NoSuchAlgorithmException, NoSuchPaddingException {
         Transform transform = tokenizeTransformation(transformation);
         int algorithmMode = AlgorithmMode.get(transform.algorithm,

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/18ac95b5/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
index eb536ef..f1dc270 100644
--- a/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
+++ b/src/main/java/org/apache/commons/crypto/random/CryptoRandomFactory.java
@@ -35,9 +35,9 @@ public class CryptoRandomFactory {
     public final static Logger LOG = LoggerFactory
             .getLogger(CryptoRandomFactory.class);
 
-  /**
-   * The private constructor of {@Link CryptoRandomFactory}.
-   */
+    /**
+     * The private constructor of {@Link CryptoRandomFactory}.
+     */
     private CryptoRandomFactory() {
     }
 

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/18ac95b5/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java b/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
index 2e6fd00..d53f074 100644
--- a/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
+++ b/src/main/java/org/apache/commons/crypto/random/OsCryptoRandom.java
@@ -120,7 +120,7 @@ public class OsCryptoRandom extends Random implements CryptoRandom {
         fillReservoir(4);
         int n = 0;
         for (int i = 0; i < 4; i++) {
-            n = ((n << 8) | (reservoir[pos++] & 0xff));
+            n = (n << 8) | (reservoir[pos++] & 0xff);
         }
         return n & (0xffffffff >> (32 - nbits));
     }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/18ac95b5/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
----------------------------------------------------------------------
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 59a719b..db974ab 100644
--- a/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
+++ b/src/main/java/org/apache/commons/crypto/stream/CryptoInputStream.java
@@ -197,6 +197,7 @@ public class CryptoInputStream extends InputStream implements
         int n;
         while ((n = read(oneByteBuf, 0, 1)) == 0) {
             /* no op */
+            ;
         }
         return (n == -1) ? -1 : oneByteBuf[0] & 0xff;
     }

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/18ac95b5/src/main/java/org/apache/commons/crypto/utils/NativeCodeLoader.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/utils/NativeCodeLoader.java b/src/main/java/org/apache/commons/crypto/utils/NativeCodeLoader.java
index 2068828..59a102f 100644
--- a/src/main/java/org/apache/commons/crypto/utils/NativeCodeLoader.java
+++ b/src/main/java/org/apache/commons/crypto/utils/NativeCodeLoader.java
@@ -107,13 +107,11 @@ public final class NativeCodeLoader {
         boolean hasNativeLib = hasResource(nativeLibraryPath + "/"
                 + nativeLibraryName);
         if (!hasNativeLib) {
-            if (OSInfo.getOSName().equals("Mac")) {
+            String altName = "libcommons-crypto.jnilib";
+            if (OSInfo.getOSName().equals("Mac") && hasResource(nativeLibraryPath
+ "/" + altName)) {
                 // Fix for openjdk7 for Mac
-                String altName = "libcommons-crypto.jnilib";
-                if (hasResource(nativeLibraryPath + "/" + altName)) {
-                    nativeLibraryName = altName;
-                    hasNativeLib = true;
-                }
+                nativeLibraryName = altName;
+                hasNativeLib = true;
             }
         }
 

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/18ac95b5/src/main/java/org/apache/commons/crypto/utils/OSInfo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/crypto/utils/OSInfo.java b/src/main/java/org/apache/commons/crypto/utils/OSInfo.java
index f4c31fb..f809b99 100644
--- a/src/main/java/org/apache/commons/crypto/utils/OSInfo.java
+++ b/src/main/java/org/apache/commons/crypto/utils/OSInfo.java
@@ -168,9 +168,9 @@ public class OSInfo {
                 if (exitCode == 0) {
                     return "armhf";
                 }
-            } catch (IOException e) {
+            } catch (IOException e) { //NOPMD
                 // ignored: fall back to "arm" arch (soft-float ABI)
-            } catch (InterruptedException e) {
+            } catch (InterruptedException e) { //NOPMD
                 // ignored: fall back to "arm" arch (soft-float ABI)
             }
         } else {

http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/18ac95b5/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 5507de2..aac0995 100644
--- a/src/main/java/org/apache/commons/crypto/utils/Utils.java
+++ b/src/main/java/org/apache/commons/crypto/utils/Utils.java
@@ -31,17 +31,6 @@ import org.apache.commons.crypto.cipher.CipherTransformation;
 import org.apache.commons.crypto.cipher.CryptoCipher;
 import org.apache.commons.crypto.cipher.CryptoCipherFactory;
 import org.apache.commons.crypto.conf.ConfigurationKeys;
-import static org.apache.commons.crypto.conf.ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_DEFAULT;
-import static org.apache.commons.crypto.conf.ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_KEY;
-import static org.apache.commons.crypto.conf.ConfigurationKeys.COMMONS_CRYPTO_CIPHER_JCE_PROVIDER_KEY;
-import static org.apache.commons.crypto.conf.ConfigurationKeys.COMMONS_CRYPTO_LIB_NAME_KEY;
-import static org.apache.commons.crypto.conf.ConfigurationKeys.COMMONS_CRYPTO_LIB_PATH_KEY;
-import static org.apache.commons.crypto.conf.ConfigurationKeys.COMMONS_CRYPTO_LIB_TEMPDIR_KEY;
-import static org.apache.commons.crypto.conf.ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_DEVICE_FILE_PATH_DEFAULT;
-import static org.apache.commons.crypto.conf.ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_DEVICE_FILE_PATH_KEY;
-import static org.apache.commons.crypto.conf.ConfigurationKeys.COMMONS_CRYPTO_STREAM_BUFFER_SIZE_DEFAULT;
-import static org.apache.commons.crypto.conf.ConfigurationKeys.COMMONS_CRYPTO_STREAM_BUFFER_SIZE_KEY;
-import static org.apache.commons.crypto.conf.ConfigurationKeys.COMMONS_CRYPTO_SYSTEM_PROPERTIES_FILE;
 
 /**
  * General utility methods.
@@ -76,7 +65,7 @@ public final class Utils {
     private static void loadSystemProperties() {
         try {
             InputStream is = Thread.currentThread().getContextClassLoader()
-                    .getResourceAsStream(COMMONS_CRYPTO_SYSTEM_PROPERTIES_FILE);
+                    .getResourceAsStream(ConfigurationKeys.COMMONS_CRYPTO_SYSTEM_PROPERTIES_FILE);
 
             if (is == null) {
                 return; // no configuration file is found
@@ -88,15 +77,13 @@ public final class Utils {
             Enumeration<?> names = props.propertyNames();
             while (names.hasMoreElements()) {
                 String name = (String) names.nextElement();
-                if (name.startsWith(ConfigurationKeys.CONF_PREFIX)) {
-                    if (System.getProperty(name) == null) {
-                        System.setProperty(name, props.getProperty(name));
-                    }
+                if (name.startsWith(ConfigurationKeys.CONF_PREFIX) && System.getProperty(name)
== null) {
+                    System.setProperty(name, props.getProperty(name));
                 }
             }
         } catch (Throwable ex) {
             System.err.println("Could not load '"
-                    + COMMONS_CRYPTO_SYSTEM_PROPERTIES_FILE
+                    + ConfigurationKeys.COMMONS_CRYPTO_SYSTEM_PROPERTIES_FILE
                     + "' from classpath: " + ex.toString());
         }
     }
@@ -125,8 +112,9 @@ public final class Utils {
                     return;
                 }
             }
-        } catch (ReflectiveOperationException e) {
+        } catch (ReflectiveOperationException e) { // NOPMD
             // Ignore the Reflection exception.
+
         }
     }
 
@@ -139,13 +127,13 @@ public final class Utils {
      * */
     public static int getBufferSize(Properties props) {
         String bufferSizeStr = props
-                .getProperty(COMMONS_CRYPTO_STREAM_BUFFER_SIZE_KEY);
+                .getProperty(ConfigurationKeys.COMMONS_CRYPTO_STREAM_BUFFER_SIZE_KEY);
         if (bufferSizeStr == null || bufferSizeStr.isEmpty()) {
             bufferSizeStr = System
-                    .getProperty(COMMONS_CRYPTO_STREAM_BUFFER_SIZE_KEY);
+                    .getProperty(ConfigurationKeys.COMMONS_CRYPTO_STREAM_BUFFER_SIZE_KEY);
         }
         if (bufferSizeStr == null || bufferSizeStr.isEmpty()) {
-            return COMMONS_CRYPTO_STREAM_BUFFER_SIZE_DEFAULT;
+            return ConfigurationKeys.COMMONS_CRYPTO_STREAM_BUFFER_SIZE_DEFAULT;
         }
         return Integer.parseInt(bufferSizeStr);
     }
@@ -158,13 +146,13 @@ public final class Utils {
      * @return the cipher class based on the props.
      */
     public static String getCipherClassString(Properties props) {
-        final String configName = COMMONS_CRYPTO_CIPHER_CLASSES_KEY;
+        final String configName = ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_KEY;
         String cipherClassString = props.getProperty(configName) != null ? props
-                .getProperty(configName, COMMONS_CRYPTO_CIPHER_CLASSES_DEFAULT)
+                .getProperty(configName, ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_DEFAULT)
                 : System.getProperty(configName,
-                        COMMONS_CRYPTO_CIPHER_CLASSES_DEFAULT);
+                ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_DEFAULT);
         if (cipherClassString.isEmpty()) {
-            cipherClassString = COMMONS_CRYPTO_CIPHER_CLASSES_DEFAULT;
+            cipherClassString = ConfigurationKeys.COMMONS_CRYPTO_CIPHER_CLASSES_DEFAULT;
         }
         return cipherClassString;
     }
@@ -177,9 +165,9 @@ public final class Utils {
      * @return the jce provider based on the props.
      */
     public static String getJCEProvider(Properties props) {
-        return props.getProperty(COMMONS_CRYPTO_CIPHER_JCE_PROVIDER_KEY) != null ? props
-                .getProperty(COMMONS_CRYPTO_CIPHER_JCE_PROVIDER_KEY) : System
-                .getProperty(COMMONS_CRYPTO_CIPHER_JCE_PROVIDER_KEY);
+        return props.getProperty(ConfigurationKeys.COMMONS_CRYPTO_CIPHER_JCE_PROVIDER_KEY)
!=
+            null ? props.getProperty(ConfigurationKeys.COMMONS_CRYPTO_CIPHER_JCE_PROVIDER_KEY)
+            : System.getProperty(ConfigurationKeys.COMMONS_CRYPTO_CIPHER_JCE_PROVIDER_KEY);
     }
 
     /**
@@ -191,11 +179,11 @@ public final class Utils {
      */
     public static String getRandomDevPath(Properties props) {
         String devPath = props
-                .getProperty(COMMONS_CRYPTO_SECURE_RANDOM_DEVICE_FILE_PATH_KEY);
+                .getProperty(ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_DEVICE_FILE_PATH_KEY);
         if (devPath == null) {
             devPath = System.getProperty(
-                    COMMONS_CRYPTO_SECURE_RANDOM_DEVICE_FILE_PATH_KEY,
-                    COMMONS_CRYPTO_SECURE_RANDOM_DEVICE_FILE_PATH_DEFAULT);
+                    ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_DEVICE_FILE_PATH_KEY,
+                    ConfigurationKeys.COMMONS_CRYPTO_SECURE_RANDOM_DEVICE_FILE_PATH_DEFAULT);
         }
         return devPath;
     }
@@ -206,7 +194,7 @@ public final class Utils {
      * @return the path of native library.
      */
     public static String getLibPath() {
-        return System.getProperty(COMMONS_CRYPTO_LIB_PATH_KEY);
+        return System.getProperty(ConfigurationKeys.COMMONS_CRYPTO_LIB_PATH_KEY);
     }
 
     /**
@@ -215,7 +203,7 @@ public final class Utils {
      * @return the file name of native library.
      */
     public static String getLibName() {
-        return System.getProperty(COMMONS_CRYPTO_LIB_NAME_KEY);
+        return System.getProperty(ConfigurationKeys.COMMONS_CRYPTO_LIB_NAME_KEY);
     }
 
     /**
@@ -224,7 +212,7 @@ public final class Utils {
      * @return the temp directory.
      */
     public static String getTmpDir() {
-        return System.getProperty(COMMONS_CRYPTO_LIB_TEMPDIR_KEY,
+        return System.getProperty(ConfigurationKeys.COMMONS_CRYPTO_LIB_TEMPDIR_KEY,
                 System.getProperty("java.io.tmpdir"));
     }
 
@@ -287,7 +275,7 @@ public final class Utils {
         int sum = 0;
         while (i-- > 0) {
             // (sum >>> Byte.SIZE) is the carry for addition
-            sum = (initIV[i] & 0xff) + (sum >>> Byte.SIZE);
+            sum = initIV[i] & 0xff + sum >>> Byte.SIZE;
             if (j++ < 8) { // Big-endian, and long is 8 bytes length
                 sum += (byte) counter & 0xff;
                 counter >>>= 8;


Mime
View raw message