Author: pmouawad Date: Sun Feb 18 20:59:14 2018 New Revision: 1824708 URL: http://svn.apache.org/viewvc?rev=1824708&view=rev Log: Fix sonar warnings: - Variable correct naming - Clarify why we return null instead of empty array
Modified: jmeter/trunk/src/core/org/apache/jmeter/util/keystore/JmeterKeyStore.java Modified: jmeter/trunk/src/core/org/apache/jmeter/util/keystore/JmeterKeyStore.java URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/keystore/JmeterKeyStore.java?rev=1824708&r1=1824707&r2=1824708&view=diff ============================================================================== --- jmeter/trunk/src/core/org/apache/jmeter/util/keystore/JmeterKeyStore.java (original) +++ jmeter/trunk/src/core/org/apache/jmeter/util/keystore/JmeterKeyStore.java Sun Feb 18 20:59:14 2018 @@ -63,7 +63,7 @@ public final class JmeterKeyStore { private Map<String, PrivateKey> privateKeyByAlias = new HashMap<>(); private Map<String, X509Certificate[]> certsByAlias = new HashMap<>(); - private int last_user; + private int lastAliasIndex; /** * @param type @@ -114,54 +114,52 @@ public final class JmeterKeyStore { char[] pw = pword==null ? null : pword.toCharArray(); store.load(is, pw); - List<String> v_names = new ArrayList<>(); + List<String> aliasesList = new ArrayList<>(); this.privateKeyByAlias = new HashMap<>(); this.certsByAlias = new HashMap<>(); if (null != is){ // No point checking an empty keystore - PrivateKey _key = null; + PrivateKey privateKey = null; int index = 0; Enumeration<String> aliases = store.aliases(); while (aliases.hasMoreElements()) { String alias = aliases.nextElement(); if (store.isKeyEntry(alias)) { if (index >= startIndex && index <= endIndex) { - _key = (PrivateKey) store.getKey(alias, pw); - if (null == _key) { + privateKey = (PrivateKey) store.getKey(alias, pw); + if (null == privateKey) { throw new IOException("No key found for alias: " + alias); // Should not happen } Certificate[] chain = store.getCertificateChain(alias); if (null == chain) { throw new IOException("No certificate chain found for alias: " + alias); } - v_names.add(alias); + aliasesList.add(alias); X509Certificate[] x509certs = new X509Certificate[chain.length]; for (int i = 0; i < x509certs.length; i++) { x509certs[i] = (X509Certificate)chain[i]; } - privateKeyByAlias.put(alias, _key); + privateKeyByAlias.put(alias, privateKey); certsByAlias.put(alias, x509certs); } index++; } } - if (null == _key) { + if (null == privateKey) { throw new IOException("No key(s) found"); } - if (index <= endIndex-startIndex) { - if (log.isWarnEnabled()) { - log.warn("Did not find all requested aliases. Start={}, end={}, found={}", - startIndex, endIndex, certsByAlias.size()); - } + if (index <= endIndex-startIndex && log.isWarnEnabled()) { + log.warn("Did not find all requested aliases. Start={}, end={}, found={}", + startIndex, endIndex, certsByAlias.size()); } } /* * Note: if is == null, the arrays will be empty */ - this.names = v_names.toArray(new String[v_names.size()]); + this.names = aliasesList.toArray(new String[aliasesList.size()]); } @@ -283,9 +281,9 @@ public final class JmeterKeyStore { */ private int getIndexAndIncrement(int length) { synchronized(this) { - int result = last_user++; - if (last_user >= length) { - last_user = 0; + int result = lastAliasIndex++; + if (lastAliasIndex >= length) { + lastAliasIndex = 0; } return result; } @@ -304,16 +302,13 @@ public final class JmeterKeyStore { int count = getAliasCount(); String[] aliases = new String[count]; for(int i = 0; i < aliases.length; i++) { -// if (keys[i].getAlgorithm().equals(keyType)){ -// -// } aliases[i] = this.names[i]; } if(aliases.length>0) { return aliases; } else { // API expects null not empty array, see http://docs.oracle.com/javase/7/docs/api/javax/net/ssl/X509KeyManager.html - return null; + return null; // NOSONAR } }