forked from I2P_Developers/i2p.i2p
lint: don't catch Exception, catch RuntimeException or checked exception.
omits SAM, BOB, reflection, commented-out code, and a few other places
This commit is contained in:
@@ -862,7 +862,7 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
|
||||
if ((duration > 100) && _log.shouldLog(Log.INFO))
|
||||
_log.info("Message availability notification for " + msgId.intValue() + " took "
|
||||
+ duration + " to " + _sessionListener);
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
_log.log(Log.CRIT, "Error notifying app of message availability", e);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -399,7 +399,7 @@ class I2PSessionMuxedImpl extends I2PSessionImpl2 {
|
||||
try {
|
||||
_demultiplexer.messageAvailable(I2PSessionMuxedImpl.this,
|
||||
msg.id, msg.size, msg.proto, msg.fromPort, msg.toPort);
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
_log.error("Error notifying app of message availability", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class SingleFileNamingService extends NamingService {
|
||||
key = getKey(hostname.substring(4));
|
||||
if (key != null)
|
||||
return lookupBase64(key);
|
||||
} catch (Exception ioe) {
|
||||
} catch (IOException ioe) {
|
||||
if (_file.exists())
|
||||
_log.error("Error loading hosts file " + _file, ioe);
|
||||
else if (_log.shouldLog(Log.WARN))
|
||||
@@ -123,7 +123,7 @@ public class SingleFileNamingService extends NamingService {
|
||||
return line.substring(0, split);
|
||||
}
|
||||
return null;
|
||||
} catch (Exception ioe) {
|
||||
} catch (IOException ioe) {
|
||||
if (_file.exists())
|
||||
_log.error("Error loading hosts file " + _file, ioe);
|
||||
else if (_log.shouldLog(Log.WARN))
|
||||
|
||||
@@ -257,7 +257,7 @@ public class DSAEngine {
|
||||
_log.warn("Took too long to verify the signature (" + diff + "ms)");
|
||||
}
|
||||
return ok;
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
_log.log(Log.CRIT, "Error verifying the signature", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.i2p.crypto;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.math.BigInteger;
|
||||
import java.security.AlgorithmParameters;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.Provider;
|
||||
import java.security.Security;
|
||||
import java.security.spec.ECField;
|
||||
@@ -278,7 +279,7 @@ class ECConstants {
|
||||
AlgorithmParameters ap;
|
||||
try {
|
||||
ap = AlgorithmParameters.getInstance("EC");
|
||||
} catch (Exception e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
if (BC_AVAILABLE) {
|
||||
log("Named curve " + name + " is not available, trying BC", e);
|
||||
ap = AlgorithmParameters.getInstance("EC", "BC");
|
||||
@@ -292,7 +293,7 @@ class ECConstants {
|
||||
ECParameterSpec rv = ap.getParameterSpec(ECParameterSpec.class);
|
||||
log("Named curve " + name + " loaded");
|
||||
return rv;
|
||||
} catch (Exception e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
log("Named curve " + name + " is not available", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -327,12 +327,12 @@ public class ElGamalAESEngine {
|
||||
//ByteArrayInputStream bais = new ByteArrayInputStream(decrypted);
|
||||
int cur = 0;
|
||||
long numTags = DataHelper.fromLong(decrypted, cur, 2);
|
||||
if ((numTags < 0) || (numTags > MAX_TAGS_RECEIVED)) throw new Exception("Invalid number of session tags");
|
||||
if ((numTags < 0) || (numTags > MAX_TAGS_RECEIVED)) throw new IllegalArgumentException("Invalid number of session tags");
|
||||
if (numTags > 0) tags = new ArrayList<SessionTag>((int)numTags);
|
||||
cur += 2;
|
||||
//_log.debug("# tags: " + numTags);
|
||||
if (numTags * SessionTag.BYTE_LENGTH > decrypted.length - 2) {
|
||||
throw new Exception("# tags: " + numTags + " is too many for " + (decrypted.length - 2));
|
||||
throw new IllegalArgumentException("# tags: " + numTags + " is too many for " + (decrypted.length - 2));
|
||||
}
|
||||
for (int i = 0; i < numTags; i++) {
|
||||
byte tag[] = new byte[SessionTag.BYTE_LENGTH];
|
||||
@@ -344,7 +344,7 @@ public class ElGamalAESEngine {
|
||||
cur += 4;
|
||||
//_log.debug("len: " + len);
|
||||
if ((len < 0) || (len > decrypted.length - cur - Hash.HASH_LENGTH - 1))
|
||||
throw new Exception("Invalid size of payload (" + len + ", remaining " + (decrypted.length-cur) +")");
|
||||
throw new IllegalArgumentException("Invalid size of payload (" + len + ", remaining " + (decrypted.length-cur) +")");
|
||||
//byte hashval[] = new byte[Hash.HASH_LENGTH];
|
||||
//System.arraycopy(decrypted, cur, hashval, 0, Hash.HASH_LENGTH);
|
||||
//readHash = new Hash();
|
||||
@@ -379,8 +379,8 @@ public class ElGamalAESEngine {
|
||||
return unencrData;
|
||||
}
|
||||
|
||||
throw new Exception("Hash does not match");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Hash does not match");
|
||||
} catch (RuntimeException e) {
|
||||
if (_log.shouldLog(Log.WARN)) _log.warn("Unable to decrypt AES block", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public enum EncType {
|
||||
return true;
|
||||
try {
|
||||
getParams();
|
||||
} catch (Exception e) {
|
||||
} catch (InvalidParameterSpecException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -343,7 +343,7 @@ public class KeyGenerator {
|
||||
public static void main(String args[]) {
|
||||
try {
|
||||
main2(args);
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -381,7 +381,7 @@ public class KeyGenerator {
|
||||
try {
|
||||
System.out.println("Testing " + type);
|
||||
testSig(type, runs);
|
||||
} catch (Exception e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
System.out.println("error testing " + type);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -98,7 +98,8 @@ public class KeyStoreUtil {
|
||||
try {
|
||||
ks.load(null, DEFAULT_KEYSTORE_PASSWORD.toCharArray());
|
||||
success = addCerts(new File(System.getProperty("java.home"), "etc/security/cacerts"), ks) > 0;
|
||||
} catch (Exception e) {}
|
||||
} catch (IOException e) {
|
||||
} catch (GeneralSecurityException e) {}
|
||||
} else {
|
||||
success = loadCerts(new File(System.getProperty("java.home"), "etc/security/cacerts.bks"), ks);
|
||||
}
|
||||
@@ -113,7 +114,8 @@ public class KeyStoreUtil {
|
||||
try {
|
||||
// must be initted
|
||||
ks.load(null, DEFAULT_KEYSTORE_PASSWORD.toCharArray());
|
||||
} catch (Exception e) {}
|
||||
} catch (IOException e) {
|
||||
} catch (GeneralSecurityException e) {}
|
||||
error("All key store loads failed, will only load local certificates", null);
|
||||
}
|
||||
return ks;
|
||||
@@ -140,13 +142,15 @@ public class KeyStoreUtil {
|
||||
try {
|
||||
// not clear if null is allowed for password
|
||||
ks.load(null, DEFAULT_KEYSTORE_PASSWORD.toCharArray());
|
||||
} catch (Exception foo) {}
|
||||
} catch (IOException foo) {
|
||||
} catch (GeneralSecurityException e) {}
|
||||
return false;
|
||||
} catch (IOException ioe) {
|
||||
error("KeyStore load error, no default keys: " + file.getAbsolutePath(), ioe);
|
||||
try {
|
||||
ks.load(null, DEFAULT_KEYSTORE_PASSWORD.toCharArray());
|
||||
} catch (Exception foo) {}
|
||||
} catch (IOException foo) {
|
||||
} catch (GeneralSecurityException e) {}
|
||||
return false;
|
||||
} finally {
|
||||
try { if (fis != null) fis.close(); } catch (IOException foo) {}
|
||||
@@ -171,7 +175,7 @@ public class KeyStoreUtil {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
} catch (Exception foo) {}
|
||||
} catch (GeneralSecurityException e) {}
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -316,7 +320,10 @@ public class KeyStoreUtil {
|
||||
error("Not overwriting key " + alias + ", already exists in " + ks, null);
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
error("Not overwriting key \"" + alias + "\", already exists in " + ks, e);
|
||||
return false;
|
||||
} catch (GeneralSecurityException e) {
|
||||
error("Not overwriting key \"" + alias + "\", already exists in " + ks, e);
|
||||
return false;
|
||||
}
|
||||
@@ -354,7 +361,10 @@ public class KeyStoreUtil {
|
||||
success = getPrivateKey(ks, ksPW, alias, keyPW) != null;
|
||||
if (!success)
|
||||
error("Key gen failed to get private key", null);
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
error("Key gen failed to get private key", e);
|
||||
success = false;
|
||||
} catch (GeneralSecurityException e) {
|
||||
error("Key gen failed to get private key", e);
|
||||
success = false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.i2p.crypto;
|
||||
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.Signature;
|
||||
@@ -215,7 +216,9 @@ public enum SigType {
|
||||
}
|
||||
getDigestInstance();
|
||||
getHashInstance();
|
||||
} catch (Exception e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
return false;
|
||||
} catch (RuntimeException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -344,7 +344,11 @@ riCe6OlAEiNpcc6mMyIYYWFICbrDFTrDR3wXqwc/Jkcx6L5VVWoagpSzbo3yGhc=
|
||||
System.out.println("\r\nPrivate key written to: " + privateKeyFile);
|
||||
System.out.println("Public key written to: " + publicKeyFile);
|
||||
System.out.println("\r\nPublic key: " + signingPublicKey.toBase64() + "\r\n");
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error writing keys:");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} catch (DataFormatException e) {
|
||||
System.err.println("Error writing keys:");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
@@ -758,7 +762,7 @@ riCe6OlAEiNpcc6mMyIYYWFICbrDFTrDR3wXqwc/Jkcx6L5VVWoagpSzbo3yGhc=
|
||||
bytesToSignInputStream = new SequenceInputStream(versionHeaderInputStream, fileInputStream);
|
||||
signature = _context.dsa().sign(bytesToSignInputStream, signingPrivateKey);
|
||||
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error("Error signing", e);
|
||||
|
||||
|
||||
@@ -722,7 +722,7 @@ public class GroupElement implements Serializable {
|
||||
if (!this.repr.equals(ge.repr)) {
|
||||
try {
|
||||
ge = ge.toRep(this.repr);
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
@@ -174,7 +175,10 @@ public class PrivateKeyFile {
|
||||
pkf.write();
|
||||
verifySignature(pkf.getDestination());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (I2PException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
@@ -358,7 +362,7 @@ public class PrivateKeyFile {
|
||||
HashCash hc;
|
||||
try {
|
||||
hc = HashCash.mintCash(resource, effort);
|
||||
} catch (Exception e) {
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
return null;
|
||||
}
|
||||
System.out.println("Generation took: " + DataHelper.formatDuration(System.currentTimeMillis() - begin));
|
||||
@@ -391,7 +395,9 @@ public class PrivateKeyFile {
|
||||
Destination d2;
|
||||
try {
|
||||
d2 = pkf2.getDestination();
|
||||
} catch (Exception e) {
|
||||
} catch (I2PException e) {
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
if (d2 == null)
|
||||
@@ -500,7 +506,7 @@ public class PrivateKeyFile {
|
||||
long low = Long.MAX_VALUE;
|
||||
try {
|
||||
low = HashCash.estimateTime(hashEffort);
|
||||
} catch (Exception e) {}
|
||||
} catch (NoSuchAlgorithmException e) {}
|
||||
// takes a lot longer than the estimate usually...
|
||||
// maybe because the resource string is much longer than used in the estimate?
|
||||
return "It is estimated that generating a HashCash Certificate with value " + hashEffort +
|
||||
|
||||
@@ -160,7 +160,7 @@ public class I2CPMessageReader {
|
||||
public void run() {
|
||||
try {
|
||||
run2();
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
_log.log(Log.CRIT, "Uncaught I2CP error", e);
|
||||
_listener.readError(I2CPMessageReader.this, e);
|
||||
cancelRunner();
|
||||
@@ -193,7 +193,7 @@ public class I2CPMessageReader {
|
||||
} catch (OutOfMemoryError oom) {
|
||||
// ooms seen here... maybe log and keep going?
|
||||
throw oom;
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
_log.log(Log.CRIT, "Unhandled error reading I2CP stream", e);
|
||||
_listener.disconnected(I2CPMessageReader.this);
|
||||
cancelRunner();
|
||||
|
||||
@@ -145,7 +145,7 @@ public class BufferedStatLog implements StatLog {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("writing " + writeStart +"->"+ writeEnd);
|
||||
writeEvents(writeStart, writeEnd);
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
_log.error("error writing " + writeStart +"->"+ writeEnd, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ public class EepGet {
|
||||
break;
|
||||
} // switch
|
||||
} // while
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
error = true;
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public class EepHead extends EepGet {
|
||||
break;
|
||||
} // switch
|
||||
} // while
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
error = true;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ package net.i2p.util;
|
||||
|
||||
import gnu.crypto.prng.AsyncFortunaStandalone;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
@@ -266,7 +267,7 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste
|
||||
synchronized(_fortuna) {
|
||||
_fortuna.addRandomBytes(data, offset, len);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
// AIOOBE seen, root cause unknown, ticket #1576
|
||||
Log log = _context.logManager().getLog(FortunaRandomSource.class);
|
||||
log.warn("feedEntropy()", e);
|
||||
@@ -290,6 +291,6 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste
|
||||
rand.nextBytes(buf);
|
||||
System.out.write(buf);
|
||||
}
|
||||
} catch (Exception e) { e.printStackTrace(); }
|
||||
} catch (IOException e) { e.printStackTrace(); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ abstract class LogWriterBase implements Runnable {
|
||||
if (_write && shouldReadConfig)
|
||||
rereadConfig();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
System.err.println("Error writing the log: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ public class PartialEepGet extends EepGet {
|
||||
break;
|
||||
} // switch
|
||||
} // while
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
error = true;
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class ResettableGZIPInputStream extends InflaterInputStream {
|
||||
public long getTotalRead() {
|
||||
try {
|
||||
return inf.getBytesRead();
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -136,7 +136,7 @@ public class ResettableGZIPInputStream extends InflaterInputStream {
|
||||
public long getTotalExpanded() {
|
||||
try {
|
||||
return inf.getBytesWritten();
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
// possible NPE in some implementations
|
||||
return 0;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ public class ResettableGZIPInputStream extends InflaterInputStream {
|
||||
public long getRemaining() {
|
||||
try {
|
||||
return inf.getRemaining();
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
// possible NPE in some implementations
|
||||
return 0;
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public class ResettableGZIPInputStream extends InflaterInputStream {
|
||||
public boolean getFinished() {
|
||||
try {
|
||||
return inf.finished();
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
// possible NPE in some implementations
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public class SSLEepGet extends EepGet {
|
||||
break;
|
||||
} // switch
|
||||
} // while
|
||||
} catch (Exception e) {
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
error = true;
|
||||
}
|
||||
@@ -370,7 +370,7 @@ public class SSLEepGet extends EepGet {
|
||||
System.out.println(" Valid To: " + cert.getNotAfter());
|
||||
try {
|
||||
cert.checkValidity();
|
||||
} catch (Exception e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
System.out.println(" WARNING: Certificate is not currently valid, it cannot be used");
|
||||
}
|
||||
CertUtil.saveCert(cert, new File(name));
|
||||
|
||||
@@ -439,7 +439,7 @@ public class ShellCommand {
|
||||
System.out.println("ShellCommand waiting for \"" + name + '\"');
|
||||
try {
|
||||
process.waitFor();
|
||||
} catch (Exception e) {
|
||||
} catch (InterruptedException e) {
|
||||
if (DEBUG) {
|
||||
System.out.println("ShellCommand exception waiting for \"" + name + '\"');
|
||||
e.printStackTrace();
|
||||
@@ -457,7 +457,7 @@ public class ShellCommand {
|
||||
if (process.exitValue() > 0)
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
// probably IOException, file not found from exec()
|
||||
if (DEBUG) {
|
||||
System.out.println("ShellCommand execute exception for \"" + name + '\"');
|
||||
|
||||
@@ -147,7 +147,7 @@ public class BlockFile implements Closeable {
|
||||
bf.bfck(true);
|
||||
bf.close();
|
||||
raif.close();
|
||||
} catch (Exception e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user