fix lint "Implied default locale in case conversion"

find app/src/full/java/kellinwood/ -name \*.java |xargs sed -i 's,\.toLowerCase(),.toLowerCase(Locale.ROOT),g'
This commit is contained in:
Hans-Christoph Steiner 2018-06-01 17:17:21 +02:00
parent 6f7fdec4eb
commit d5d3abe2a3
9 changed files with 39 additions and 29 deletions

View File

@ -6,7 +6,9 @@
<!-- to make CI fail on errors until this is fixed
https://github.com/rtyley/spongycastle/issues/7 -->
<issue id="InvalidPackage" severity="warning"/>
<issue id="ImpliedQuantity" severity="error"/>
<issue id="DefaultLocale" severity="error"/>
<!-- These are important to us, so promote from warning to error -->
<issue id="UnusedResources" severity="error">

View File

@ -1,6 +1,8 @@
package kellinwood.security.zipsigner;
import java.util.Locale;
/**
* Default resource adapter.
*/
@ -25,7 +27,7 @@ public class DefaultResourceAdapter implements ResourceAdapter {
case GENERATING_SIGNATURE_BLOCK:
return "Generating signature block file";
case COPYING_ZIP_ENTRY:
return String.format("Copying zip entry %d of %d", args[0], args[1]);
return String.format(Locale.ENGLISH, "Copying zip entry %d of %d", args[0], args[1]);
default:
throw new IllegalArgumentException("Unknown item " + item);
}

View File

@ -7,6 +7,7 @@ import kellinwood.security.zipsigner.Base64;
import org.bouncycastle.util.encoders.HexTranslator;
import java.security.MessageDigest;
import java.util.Locale;
/**
* User: ken
@ -41,7 +42,7 @@ public class Fingerprint {
builder.append((char) hex[i + 1]);
if (i != (hex.length - 2)) builder.append(':');
}
return builder.toString().toUpperCase();
return builder.toString().toUpperCase(Locale.ENGLISH);
} catch (Exception x) {
logger.error(x.getMessage(), x);
}

View File

@ -23,7 +23,6 @@ power to enforce restrictions on reverse-engineering of their software,
and it is irresponsible for them to claim they can. */
package kellinwood.security.zipsigner.optional;
import javax.crypto.EncryptedPrivateKeyInfo;
@ -53,6 +52,7 @@ import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Vector;
/**
@ -183,7 +183,7 @@ public class JKS extends KeyStoreSpi {
public Key engineGetKey(String alias, char[] password)
throws NoSuchAlgorithmException, UnrecoverableKeyException {
alias = alias.toLowerCase();
alias = alias.toLowerCase(Locale.ENGLISH);
if (!privateKeys.containsKey(alias))
return null;
@ -204,12 +204,12 @@ public class JKS extends KeyStoreSpi {
}
public Certificate[] engineGetCertificateChain(String alias) {
alias = alias.toLowerCase();
alias = alias.toLowerCase(Locale.ENGLISH);
return (Certificate[]) certChains.get(alias);
}
public Certificate engineGetCertificate(String alias) {
alias = alias.toLowerCase();
alias = alias.toLowerCase(Locale.ENGLISH);
if (engineIsKeyEntry(alias)) {
Certificate[] certChain = (Certificate[]) certChains.get(alias);
if (certChain != null && certChain.length > 0) return certChain[0];
@ -218,7 +218,7 @@ public class JKS extends KeyStoreSpi {
}
public Date engineGetCreationDate(String alias) {
alias = alias.toLowerCase();
alias = alias.toLowerCase(Locale.ENGLISH);
return (Date) dates.get(alias);
}
@ -226,7 +226,7 @@ public class JKS extends KeyStoreSpi {
public void engineSetKeyEntry(String alias, Key key, char[] passwd, Certificate[] certChain)
throws KeyStoreException {
alias = alias.toLowerCase();
alias = alias.toLowerCase(Locale.ENGLISH);
if (trustedCerts.containsKey(alias))
throw new KeyStoreException("\"" + alias + " is a trusted certificate entry");
privateKeys.put(alias, encryptKey(key, charsToBytes(passwd)));
@ -242,7 +242,7 @@ public class JKS extends KeyStoreSpi {
public void engineSetKeyEntry(String alias, byte[] encodedKey, Certificate[] certChain)
throws KeyStoreException {
alias = alias.toLowerCase();
alias = alias.toLowerCase(Locale.ENGLISH);
if (trustedCerts.containsKey(alias))
throw new KeyStoreException("\"" + alias + "\" is a trusted certificate entry");
try {
@ -263,7 +263,7 @@ public class JKS extends KeyStoreSpi {
public void engineSetCertificateEntry(String alias, Certificate cert)
throws KeyStoreException {
alias = alias.toLowerCase();
alias = alias.toLowerCase(Locale.ENGLISH);
if (privateKeys.containsKey(alias))
throw new KeyStoreException("\"" + alias + "\" is a private key entry");
if (cert == null)
@ -276,7 +276,7 @@ public class JKS extends KeyStoreSpi {
}
public void engineDeleteEntry(String alias) throws KeyStoreException {
alias = alias.toLowerCase();
alias = alias.toLowerCase(Locale.ENGLISH);
aliases.remove(alias);
}
@ -285,7 +285,7 @@ public class JKS extends KeyStoreSpi {
}
public boolean engineContainsAlias(String alias) {
alias = alias.toLowerCase();
alias = alias.toLowerCase(Locale.ENGLISH);
return aliases.contains(alias);
}
@ -294,12 +294,12 @@ public class JKS extends KeyStoreSpi {
}
public boolean engineIsKeyEntry(String alias) {
alias = alias.toLowerCase();
alias = alias.toLowerCase(Locale.ENGLISH);
return privateKeys.containsKey(alias);
}
public boolean engineIsCertificateEntry(String alias) {
alias = alias.toLowerCase();
alias = alias.toLowerCase(Locale.ENGLISH);
return trustedCerts.containsKey(alias);
}

View File

@ -17,6 +17,7 @@ import java.security.KeyStore;
import java.security.Provider;
import java.security.Security;
import java.security.cert.Certificate;
import java.util.Locale;
/**
@ -60,7 +61,7 @@ public class KeyStoreFileManager {
public static KeyStore createKeyStore(String keystorePath, char[] password)
throws Exception {
KeyStore ks = null;
if (keystorePath.toLowerCase().endsWith(".bks")) {
if (keystorePath.toLowerCase(Locale.ENGLISH).endsWith(".bks")) {
ks = KeyStore.getInstance("bks", new BouncyCastleProvider());
} else ks = new JksKeyStore();
ks.load(null, password);
@ -206,7 +207,7 @@ public class KeyStoreFileManager {
try {
KeyStore ks = loadKeyStore(keystorePath, storePass);
if (ks instanceof JksKeyStore) newKeyName = newKeyName.toLowerCase();
if (ks instanceof JksKeyStore) newKeyName = newKeyName.toLowerCase(Locale.ENGLISH);
if (ks.containsAlias(newKeyName)) throw new KeyNameConflictException();

View File

@ -27,6 +27,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.SequenceInputStream;
import java.util.Date;
import java.util.Locale;
import java.util.zip.CRC32;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
@ -91,7 +92,7 @@ public class ZioEntry implements Cloneable {
this.compressedSize = this.size;
if (getLogger().isDebugEnabled())
getLogger().debug(String.format("Computing CRC for %s, size=%d", sourceDataFile, size));
getLogger().debug(String.format(Locale.ENGLISH, "Computing CRC for %s, size=%d", sourceDataFile, size));
// compute CRC
CRC32 crc = new CRC32();
@ -292,10 +293,10 @@ public class ZioEntry implements Cloneable {
output.writeBytes(alignBytes, 0, numAlignBytes);
}
if (debug) getLogger().debug(String.format("Data position 0x%08x", output.getFilePointer()));
if (debug) getLogger().debug(String.format(Locale.ENGLISH, "Data position 0x%08x", output.getFilePointer()));
if (data != null) {
output.writeBytes(data);
if (debug) getLogger().debug(String.format("Wrote %d bytes", data.length));
if (debug) getLogger().debug(String.format(Locale.ENGLISH, "Wrote %d bytes", data.length));
} else {
if (debug) getLogger().debug(String.format("Seeking to position 0x%08x", dataPosition));
@ -309,10 +310,10 @@ public class ZioEntry implements Cloneable {
int numRead = zipInput.in.read(buffer, 0, (int) Math.min(compressedSize - totalCount, bufferSize));
if (numRead > 0) {
output.writeBytes(buffer, 0, numRead);
if (debug) getLogger().debug(String.format("Wrote %d bytes", numRead));
if (debug) getLogger().debug(String.format(Locale.ENGLISH, "Wrote %d bytes", numRead));
totalCount += numRead;
} else
throw new IllegalStateException(String.format("EOF reached while copying %s with %d bytes left to go", filename, compressedSize - totalCount));
throw new IllegalStateException(String.format(Locale.ENGLISH, "EOF reached while copying %s with %d bytes left to go", filename, compressedSize - totalCount));
}
}
}
@ -434,7 +435,7 @@ public class ZioEntry implements Cloneable {
while (count != size) {
int numRead = din.read(tmpdata, count, size - count);
if (numRead < 0)
throw new IllegalStateException(String.format("Read failed, expecting %d bytes, got %d instead", size, count));
throw new IllegalStateException(String.format(Locale.ENGLISH, "Read failed, expecting %d bytes, got %d instead", size, count));
count += numRead;
}
return tmpdata;

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.util.Locale;
/**
@ -47,7 +48,7 @@ public class ZioEntryInputStream extends InputStream {
raf = entry.getZipInput().in;
long dpos = entry.getDataPosition();
if (dpos >= 0) {
if (debug) log.debug(String.format("Seeking to %d", entry.getDataPosition()));
if (debug) log.debug(String.format(Locale.ENGLISH, "Seeking to %d", entry.getDataPosition()));
raf.seek(entry.getDataPosition());
} else {
// seeks to, then reads, the local header, causing the
@ -78,7 +79,7 @@ public class ZioEntryInputStream extends InputStream {
@Override
public int available() throws IOException {
int available = size - offset;
if (debug) log.debug(String.format("Available = %d", available));
if (debug) log.debug(String.format(Locale.ENGLISH, "Available = %d", available));
if (available == 0 && returnDummyByte) return 1;
else return available;
}
@ -119,7 +120,7 @@ public class ZioEntryInputStream extends InputStream {
if (monitor != null) monitor.write(b, off, numRead);
offset += numRead;
}
if (debug) log.debug(String.format("Read %d bytes for read(b,%d,%d)", numRead, off, len));
if (debug) log.debug(String.format(Locale.ENGLISH, "Read %d bytes for read(b,%d,%d)", numRead, off, len));
return numRead;
}
@ -132,7 +133,7 @@ public class ZioEntryInputStream extends InputStream {
public long skip(long n) throws IOException {
long numToSkip = Math.min(n, available());
raf.seek(raf.getFilePointer() + numToSkip);
if (debug) log.debug(String.format("Skipped %d bytes", numToSkip));
if (debug) log.debug(String.format(Locale.ENGLISH, "Skipped %d bytes", numToSkip));
return numToSkip;
}
}

View File

@ -25,6 +25,7 @@ import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
@ -149,8 +150,8 @@ public class ZipInput implements Closeable {
boolean debug = getLogger().isDebugEnabled();
if (debug) {
getLogger().debug(String.format("EOCD found in %d iterations", scanIterations));
getLogger().debug(String.format("Directory entries=%d, size=%d, offset=%d/0x%08x", centralEnd.totalCentralEntries,
getLogger().debug(String.format(Locale.ENGLISH, "EOCD found in %d iterations", scanIterations));
getLogger().debug(String.format(Locale.ENGLISH, "Directory entries=%d, size=%d, offset=%d/0x%08x", centralEnd.totalCentralEntries,
centralEnd.centralDirectorySize, centralEnd.centralStartOffset, centralEnd.centralStartOffset));
ZipListingHelper.listHeader(getLogger());

View File

@ -21,6 +21,7 @@ import kellinwood.logging.LoggerInterface;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
*
@ -38,7 +39,7 @@ public class ZipListingHelper {
public static void listEntry(LoggerInterface log, ZioEntry entry) {
int ratio = 0;
if (entry.getSize() > 0) ratio = (100 * (entry.getSize() - entry.getCompressedSize())) / entry.getSize();
log.debug(String.format("%8d %6s %8d %4d%% %s %08x %s",
log.debug(String.format(Locale.ENGLISH, "%8d %6s %8d %4d%% %s %08x %s",
entry.getSize(),
entry.getCompression() == 0 ? "Stored" : "Defl:N",
entry.getCompressedSize(),