Findbugs all over

- volatile -> atomic
 - unused code and fields
 - closing streams
 - hashCode / equals
 - known non-null
 - Number.valueOf
 - new String
 Still avoiding SAM, BOB, SusiMail
This commit is contained in:
zzz
2013-11-16 13:22:05 +00:00
parent 96cf1d60c2
commit 1d4190734d
30 changed files with 107 additions and 64 deletions

View File

@@ -108,10 +108,6 @@ public class AESEngine {
byte decr[] = new byte[payload.length];
decrypt(payload, 0, decr, 0, sessionKey, iv, payload.length);
if (decr == null) {
_log.error("Error decrypting the data - payload " + payload.length + " decrypted to null");
return null;
}
byte h[] = SimpleByteCache.acquire(Hash.HASH_LENGTH);
_context.sha().calculateHash(iv, 0, 16, h, 0);

View File

@@ -89,9 +89,9 @@ public class CertUtil {
log(I2PAppContext.getGlobalContext(), Log.ERROR, msg, t);
}
private static void error(I2PAppContext ctx, String msg, Throwable t) {
log(ctx, Log.ERROR, msg, t);
}
//private static void error(I2PAppContext ctx, String msg, Throwable t) {
// log(ctx, Log.ERROR, msg, t);
//}
private static void log(I2PAppContext ctx, int level, String msg, Throwable t) {
Log l = ctx.logManager().getLog(CertUtil.class);

View File

@@ -4,6 +4,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.PrivateKey;
@@ -54,11 +55,23 @@ public class KeyStoreUtil {
char[] pwchars = password != null ? password.toCharArray() : null;
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
if (exists) {
InputStream fis = new FileInputStream(ksFile);
ks.load(fis, pwchars);
InputStream fis = null;
try {
fis = new FileInputStream(ksFile);
ks.load(fis, pwchars);
} finally {
if (fis != null) try { fis.close(); } catch (IOException ioe) {}
}
}
if (ksFile != null && !exists) {
OutputStream fos = null;
try {
fos = new SecureFileOutputStream(ksFile);
ks.store(fos, pwchars);
} finally {
if (fos != null) try { fos.close(); } catch (IOException ioe) {}
}
}
if (ksFile != null && !exists)
ks.store(new SecureFileOutputStream(ksFile), pwchars);
return ks;
}
@@ -452,13 +465,13 @@ public class KeyStoreUtil {
log(I2PAppContext.getGlobalContext(), Log.ERROR, msg, t);
}
private static void info(I2PAppContext ctx, String msg) {
log(ctx, Log.INFO, msg, null);
}
//private static void info(I2PAppContext ctx, String msg) {
// log(ctx, Log.INFO, msg, null);
//}
private static void error(I2PAppContext ctx, String msg, Throwable t) {
log(ctx, Log.ERROR, msg, t);
}
//private static void error(I2PAppContext ctx, String msg, Throwable t) {
// log(ctx, Log.ERROR, msg, t);
//}
private static void log(I2PAppContext ctx, int level, String msg, Throwable t) {
if (level >= Log.WARN && !ctx.isRouterContext()) {

View File

@@ -174,7 +174,6 @@ class SigUtil {
private static ECPrivateKey cvtToJavaECKey(SigningPrivateKey pk)
throws GeneralSecurityException {
SigType type = pk.getType();
int len = type.getPubkeyLen();
byte[] b = pk.getData();
BigInteger s = new NativeBigInteger(1, b);
// see ECConstants re: casting

View File

@@ -293,7 +293,7 @@ public class TransientSessionKeyManager extends SessionKeyManager {
}
if (sess == null) {
SessionKey key = _context.keyGenerator().generateSessionKey();
sess = createAndReturnSession(target, key);
createAndReturnSession(target, key);
return key;
}
return sess.getCurrentKey();

View File

@@ -477,9 +477,11 @@ public class Base64 {
* @param breakLines Break lines at 80 characters or less.
* @since 1.4
*/
/***** unused
private static String encodeBytes(byte[] source, boolean breakLines) {
return encodeBytes(source, 0, source.length, breakLines);
} // end encodeBytes
******/
/**
* Encodes a byte array into Base64 notation.
@@ -493,13 +495,13 @@ public class Base64 {
private static String encodeBytes(byte[] source, int off, int len) {
return encodeBytes(source, off, len, true);
} // end encodeBytes
******/
private static String encodeBytes(byte[] source, int off, int len, boolean breakLines) {
StringBuilder buf = new StringBuilder( (len*4)/3 );
encodeBytes(source, off, len, breakLines, buf, ALPHABET);
return buf.toString();
}
******/
/**
* Encodes a byte array into Base64 notation.

View File

@@ -1291,7 +1291,7 @@ public class EepGet {
} catch (IOException ioe) {
_decompressException = ioe;
if (_log.shouldLog(Log.WARN))
_log.warn("Error decompressing: " + written + ", " + (in != null ? in.getTotalRead() + "/" + in.getTotalExpanded() : ""), ioe);
_log.warn("Error decompressing: " + written + ", " + in.getTotalRead() + "/" + in.getTotalExpanded(), ioe);
} catch (OutOfMemoryError oom) {
_decompressException = new IOException("OOM in HTTP Decompressor");
_log.error("OOM in HTTP Decompressor", oom);

View File

@@ -522,9 +522,11 @@ public class NativeBigInteger extends BigInteger {
* @return true if it was loaded successfully, else false
*
*/
/****
private static final boolean loadGeneric(boolean optimized) {
return loadGeneric(getMiddleName(optimized));
}
****/
private static final boolean loadGeneric(String name) {
try {
@@ -563,10 +565,12 @@ public class NativeBigInteger extends BigInteger {
* @return true if it was loaded successfully, else false
*
*/
/****
private static final boolean loadFromResource(boolean optimized) {
String resourceName = getResourceName(optimized);
return loadFromResource(resourceName);
}
****/
private static final boolean loadFromResource(String resourceName) {
if (resourceName == null) return false;

View File

@@ -46,6 +46,6 @@ public class IntBytes implements Serializer {
((b[1] & 0xff) << 16) |
((b[2] & 0xff) << 8) |
(b[3] & 0xff));
return new Integer(v);
return Integer.valueOf(v);
}
}

View File

@@ -54,6 +54,6 @@ public class LongBytes implements Serializer {
((long)(b[5] & 0xff) << 16) |
((long)(b[6] & 0xff) << 8) |
(b[7] & 0xff));
return new Long(v);
return Long.valueOf(v);
}
}