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:
zzz
2015-11-12 18:49:13 +00:00
parent 37a4fcb469
commit 51c5da3f72
78 changed files with 235 additions and 136 deletions

View File

@ -158,7 +158,7 @@ public class GarlicClove extends DataStructureImpl {
if (m.length <= 0)
throw new RuntimeException("foo, returned 0 length");
out.write(m);
} catch (Exception e) {
} catch (RuntimeException e) {
throw new DataFormatException("Unable to write the clove: " + _msg + " to " + out, e);
}
DataHelper.writeLong(out, 4, _cloveId);
@ -187,7 +187,7 @@ public class GarlicClove extends DataStructureImpl {
byte m[] = _msg.toByteArray();
System.arraycopy(m, 0, rv, offset, m.length);
offset += m.length;
} catch (Exception e) { throw new RuntimeException("Unable to write: " + _msg + ": " + e.getMessage()); }
} catch (RuntimeException e) { throw new RuntimeException("Unable to write: " + _msg + ": " + e.getMessage()); }
DataHelper.toLong(rv, offset, 4, _cloveId);
offset += 4;
DataHelper.toDate(rv, offset, _expiration.getTime());

View File

@ -59,7 +59,7 @@ public class I2NPMessageHandler {
_lastSize = msg.readBytes(in, type, _messageBuffer);
} catch (I2NPMessageException ime) {
throw ime;
} catch (Exception e) {
} catch (RuntimeException e) {
if (_log.shouldLog(Log.WARN))
_log.warn("Error reading the stream", e);
throw new I2NPMessageException("Unknown error reading the " + msg.getClass().getSimpleName(), e);
@ -131,7 +131,7 @@ public class I2NPMessageHandler {
cur += _lastSize;
} catch (I2NPMessageException ime) {
throw ime;
} catch (Exception e) {
} catch (RuntimeException e) {
if (_log.shouldLog(Log.WARN))
_log.warn("Error reading the stream", e);
throw new I2NPMessageException("Unknown error reading the " + msg.getClass().getSimpleName(), e);

View File

@ -163,7 +163,7 @@ public class I2NPMessageReader {
_log.warn("IO Error handling message", ioe);
_listener.disconnected(I2NPMessageReader.this);
cancelRunner();
} catch (Exception e) {
} catch (RuntimeException e) {
_log.log(Log.CRIT, "error reading msg!", e);
_listener.readError(I2NPMessageReader.this, e);
_listener.disconnected(I2NPMessageReader.this);

View File

@ -724,7 +724,10 @@ public class RouterInfo extends DatabaseEntry {
System.err.println("Router info " + args[i] + " is invalid");
fail = true;
}
} catch (Exception e) {
} catch (IOException e) {
System.err.println("Error reading " + args[i] + ": " + e);
fail = true;
} catch (DataFormatException e) {
System.err.println("Error reading " + args[i] + ": " + e);
fail = true;
} finally {

View File

@ -434,7 +434,7 @@ public class InNetMessagePool implements Service {
} catch (OutOfMemoryError oome) {
throw oome;
} catch (Exception e) {
} catch (RuntimeException e) {
if (_log.shouldLog(Log.CRIT))
_log.log(Log.CRIT, "Error in the tunnel gateway dispatcher", e);
}
@ -467,7 +467,7 @@ public class InNetMessagePool implements Service {
} catch (OutOfMemoryError oome) {
throw oome;
} catch (Exception e) {
} catch (RuntimeException e) {
if (_log.shouldLog(Log.CRIT))
_log.log(Log.CRIT, "Error in the tunnel data dispatcher", e);
}

View File

@ -9,6 +9,7 @@ package net.i2p.router;
*/
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -648,7 +649,7 @@ public class Router implements RouterClock.ClockShiftListener {
//else
// System.err.println("WARNING: Configuration file " + filename + " does not exist");
}
} catch (Exception ioe) {
} catch (IOException ioe) {
if (log != null)
log.error("Error loading the router configuration from " + filename, ioe);
else
@ -1351,7 +1352,7 @@ public class Router implements RouterClock.ClockShiftListener {
ordered.putAll(_config);
DataHelper.storeProps(ordered, new File(_configFilename));
}
} catch (Exception ioe) {
} catch (IOException ioe) {
// warning, _log will be null when called from constructor
if (_log != null)
_log.error("Error saving the config to " + _configFilename, ioe);

View File

@ -8,6 +8,7 @@ import java.util.Map;
import net.i2p.data.Hash;
import net.i2p.data.i2np.I2NPMessage;
import net.i2p.data.i2np.I2NPMessageException;
import net.i2p.data.i2np.I2NPMessageHandler;
import net.i2p.router.CommSystemFacade;
import net.i2p.router.JobImpl;
@ -121,7 +122,7 @@ public class VMCommSystem extends CommSystemFacade {
ReceiveJob.this.getContext().statManager().addRateData("transport.receiveMessageLarge", 1, 1);
_ctx.inNetMessagePool().add(msg, null, _from);
} catch (Exception e) {
} catch (I2NPMessageException e) {
_log.error("Error reading/formatting a VM message? Something is not right...", e);
}
}

View File

@ -543,7 +543,7 @@ public class PersistentDataStore extends TransientDataStore {
if (_log.shouldLog(Log.INFO))
_log.info("Unable to read the router reference in " + _routerFile.getName(), ioe);
corrupt = true;
} catch (Exception e) {
} catch (RuntimeException e) {
// key certificate problems, etc., don't let one bad RI kill the whole thing
if (_log.shouldLog(Log.INFO))
_log.info("Unable to read the router reference in " + _routerFile.getName(), e);
@ -666,7 +666,7 @@ public class PersistentDataStore extends TransientDataStore {
return null;
Hash h = Hash.create(b);
return h;
} catch (Exception e) {
} catch (RuntimeException e) {
// static
//_log.warn("Unable to fetch the key from [" + filename + "]", e);
return null;

View File

@ -626,7 +626,7 @@ public class Reseeder {
if (fetched % 60 == 0)
System.out.println();
}
} catch (Exception e) {
} catch (RuntimeException e) {
if (_log.shouldLog(Log.INFO))
_log.info("Failed fetch", e);
errors++;

View File

@ -301,7 +301,7 @@ class ProfilePersistenceHelper {
_log.debug("Loaded the profile for " + peer.toBase64() + " from " + file.getName());
return profile;
} catch (Exception e) {
} catch (IOException e) {
if (_log.shouldLog(Log.WARN))
_log.warn("Error loading properties from " + file.getAbsolutePath(), e);
file.delete();
@ -369,7 +369,7 @@ class ProfilePersistenceHelper {
return null;
Hash h = Hash.create(b);
return h;
} catch (Exception dfe) {
} catch (RuntimeException dfe) {
_log.warn("Invalid base64 [" + key + "]", dfe);
return null;
}

View File

@ -98,7 +98,13 @@ class RebuildRouterInfoJob extends JobImpl {
KeyData kd = LoadRouterInfoJob.readKeyData(keyFile, keyFile2);
info = new RouterInfo();
info.setIdentity(kd.routerIdentity);
} catch (Exception e) {
} catch (DataFormatException e) {
_log.log(Log.CRIT, "Error reading in the key data from " + keyFile.getAbsolutePath(), e);
keyFile.delete();
keyFile2.delete();
rebuildRouterInfo(alreadyRunning);
return;
} catch (IOException e) {
_log.log(Log.CRIT, "Error reading in the key data from " + keyFile.getAbsolutePath(), e);
keyFile.delete();
keyFile2.delete();

View File

@ -476,7 +476,7 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
ServiceStateTable table;
try {
table = serv.getServiceStateTable();
} catch (Exception e) {
} catch (RuntimeException e) {
// getSCPDNode() returns null,
// NPE at org.cybergarage.upnp.Service.getServiceStateTable(Service.java:526)
sb.append(" : no state");

View File

@ -88,7 +88,7 @@ class UPnPManager {
_isRunning = _upnp.runPlugin();
if (_log.shouldLog(Log.INFO))
_log.info("UPnP runPlugin took " + (_context.clock().now() - b));
} catch (Exception e) {
} catch (RuntimeException e) {
// NPE in UPnP (ticket #728), can't let it bring us down
if (!_errorLogged) {
_log.error("UPnP error, please report", e);

View File

@ -335,7 +335,7 @@ class EventPumper implements Runnable {
con.close();
key.cancel();
}
} catch (Exception ke) {
} catch (IOException ke) {
_log.error("Error closing key " + key + " on pumper shutdown", ke);
}
}
@ -344,7 +344,7 @@ class EventPumper implements Runnable {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Closing down the event pumper with no selection keys remaining");
}
} catch (Exception e) {
} catch (IOException e) {
_log.error("Error closing keys on pumper shutdown", e);
}
_wantsConRegister.clear();

View File

@ -463,7 +463,7 @@ class NTCPConnection implements Closeable {
_transport.afterSend(msg, successful, allowRequeue, msg.getLifetime());
if (_consecutiveBacklog > 10) { // waaay too backlogged
boolean wantsWrite = false;
try { wantsWrite = ( (_conKey.interestOps() & SelectionKey.OP_WRITE) != 0); } catch (Exception e) {}
try { wantsWrite = ( (_conKey.interestOps() & SelectionKey.OP_WRITE) != 0); } catch (RuntimeException e) {}
if (_log.shouldLog(Log.WARN)) {
int blocks = _writeBufs.size();
_log.warn("Too backlogged for too long (" + _consecutiveBacklog + " messages for " + DataHelper.formatDuration(queueTime()) + ", sched? " + wantsWrite + ", blocks: " + blocks + ") sending to " + _remotePeer.calculateHash());
@ -521,7 +521,7 @@ class NTCPConnection implements Closeable {
+ ", wantsWrite? " + (0 != (_conKey.interestOps()&SelectionKey.OP_WRITE))
+ ", currentOut set? " + currentOutboundSet
+ ", writeBufs: " + writeBufs + " on " + toString());
} catch (Exception e) {} // java.nio.channels.CancelledKeyException
} catch (RuntimeException e) {} // java.nio.channels.CancelledKeyException
}
//_context.statManager().addRateData("ntcp.sendBacklogTime", queueTime);
return true;

View File

@ -148,7 +148,7 @@ class ACKSender implements Runnable {
try {
// bulk operations may throw an exception
_peersToACK.addAll(notYet);
} catch (Exception e) {}
} catch (RuntimeException e) {}
if (_log.shouldLog(Log.DEBUG))
_log.debug("sleeping, pending size = " + notYet.size());
notYet.clear();

View File

@ -243,7 +243,7 @@ class MessageReceiver {
}
_context.messageHistory().droppedInboundMessage(state.getMessageId(), state.getFrom(), "error: " + ime.toString() + ": " + state.toString());
return null;
} catch (Exception e) {
} catch (RuntimeException e) {
// e.g. AIOOBE
if (_log.shouldLog(Log.WARN))
_log.warn("Error handling a message: " + state, e);

View File

@ -215,7 +215,7 @@ class PacketHandler {
_state = 5;
handlePacket(_reader, packet);
_state = 6;
} catch (Exception e) {
} catch (RuntimeException e) {
_state = 7;
if (_log.shouldLog(Log.ERROR))
_log.error("Crazy error handling a packet: " + packet, e);

View File

@ -43,7 +43,7 @@ class PacketPusher implements Runnable {
send(packets.get(i));
}
}
} catch (Exception e) {
} catch (RuntimeException e) {
_log.error("SSU Output Queue Error", e);
}
}

View File

@ -213,7 +213,7 @@ class BuildHandler implements Runnable {
while (_isRunning && !_manager.isShutdown()) {
try {
handleInboundRequest();
} catch (Exception e) {
} catch (RuntimeException e) {
_log.log(Log.CRIT, "B0rked in the tunnel handler", e);
}
}