Findbugs: More findbugs fixes. Including but not limited to: null check fixes and some synchronization

This commit is contained in:
dg2-new
2013-11-10 22:20:13 +00:00
parent 35fb332c2c
commit 5c38d5a6c9
23 changed files with 15 additions and 37 deletions

View File

@ -517,7 +517,6 @@ public class MetaInfo
* @since 0.9.1 * @since 0.9.1
*/ */
boolean checkPiece(PartialPiece pp) { boolean checkPiece(PartialPiece pp) {
MessageDigest sha1 = SHA1.getInstance();
int piece = pp.getPiece(); int piece = pp.getPiece();
byte[] hash; byte[] hash;
try { try {

View File

@ -754,7 +754,7 @@ public class SnarkManager implements CompleteListener {
* @since 0.9.1 * @since 0.9.1
*/ */
public void saveOpenTrackers(List<String> ot) { public void saveOpenTrackers(List<String> ot) {
String val = setListConfig(PROP_OPENTRACKERS, ot); setListConfig(PROP_OPENTRACKERS, ot);
if (ot == null) if (ot == null)
ot = Collections.singletonList(I2PSnarkUtil.DEFAULT_OPENTRACKERS); ot = Collections.singletonList(I2PSnarkUtil.DEFAULT_OPENTRACKERS);
_util.setOpenTrackers(ot); _util.setOpenTrackers(ot);

View File

@ -2548,7 +2548,7 @@ public class I2PSnarkServlet extends BasicServlet {
if (showPriority) { if (showPriority) {
buf.append("<td class=\"priority\">"); buf.append("<td class=\"priority\">");
File f = item; File f = item;
if ((!complete) && (!item.isDirectory()) && f != null) { if ((!complete) && (!item.isDirectory())) {
int pri = snark.getStorage().getPriority(f.getCanonicalPath()); int pri = snark.getStorage().getPriority(f.getCanonicalPath());
buf.append("<input type=\"radio\" value=\"5\" name=\"pri.").append(f.getCanonicalPath()).append("\" "); buf.append("<input type=\"radio\" value=\"5\" name=\"pri.").append(f.getCanonicalPath()).append("\" ");
if (pri > 0) if (pri > 0)

View File

@ -273,8 +273,6 @@ public class IndexBean {
TunnelController cur = getController(_tunnel); TunnelController cur = getController(_tunnel);
Properties config = getConfig(); Properties config = getConfig();
if (config == null)
return "Invalid params";
if (cur == null) { if (cur == null) {
// creating new // creating new
@ -970,8 +968,6 @@ public class IndexBean {
TunnelController tun = getController(_tunnel); TunnelController tun = getController(_tunnel);
Properties config = getConfig(); Properties config = getConfig();
if (config == null)
return "Invalid params";
if (tun == null) { if (tun == null) {
// creating new // creating new
tun = new TunnelController(config, "", true); tun = new TunnelController(config, "", true);
@ -1038,8 +1034,6 @@ public class IndexBean {
private String generateNewEncryptionKey() { private String generateNewEncryptionKey() {
TunnelController tun = getController(_tunnel); TunnelController tun = getController(_tunnel);
Properties config = getConfig(); Properties config = getConfig();
if (config == null)
return "Invalid params";
if (tun == null) { if (tun == null) {
// creating new // creating new
tun = new TunnelController(config, "", true); tun = new TunnelController(config, "", true);

View File

@ -93,7 +93,8 @@ class ConnectionDataReceiver implements MessageOutputStream.DataReceiver {
if (doSend) { if (doSend) {
PacketLocal packet = send(buf, off, size); PacketLocal packet = send(buf, off, size);
if (packet == null) return _dummyStatus; // this shouldn't be null
//if (packet == null) return _dummyStatus;
//dont wait for non-acks //dont wait for non-acks
if ( (packet.getSequenceNum() > 0) || (packet.isFlagSet(Packet.FLAG_SYNCHRONIZE)) ) if ( (packet.getSequenceNum() > 0) || (packet.isFlagSet(Packet.FLAG_SYNCHRONIZE)) )

View File

@ -598,7 +598,6 @@ public class DSAEngine {
private Signature altSignRaw(SimpleDataStructure hash, SigningPrivateKey privateKey) throws GeneralSecurityException { private Signature altSignRaw(SimpleDataStructure hash, SigningPrivateKey privateKey) throws GeneralSecurityException {
SigType type = privateKey.getType(); SigType type = privateKey.getType();
String algo = getRawAlgo(type); String algo = getRawAlgo(type);
java.security.Signature jsig = java.security.Signature.getInstance(algo);
PrivateKey privKey = SigUtil.toJavaKey(privateKey); PrivateKey privKey = SigUtil.toJavaKey(privateKey);
return altSignRaw(algo, hash, privKey, type); return altSignRaw(algo, hash, privKey, type);
} }

View File

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

View File

@ -113,7 +113,7 @@ public class Clock implements Timestamper.UpdateListener {
/* /*
* @return the current delta from System.currentTimeMillis() in milliseconds * @return the current delta from System.currentTimeMillis() in milliseconds
*/ */
public long getOffset() { public synchronized long getOffset() {
return _offset; return _offset;
} }

View File

@ -149,7 +149,7 @@ public class SimpleTimer {
} }
// FIXME if you plan to use this class again // FIXME if you plan to use this class again
while (_events.containsKey(time)) while (_events.containsKey(time))
time = new Long(time.longValue() + 1); time = Long.valueOf(time.longValue() + 1);
_events.put(time, event); _events.put(time, event);
_eventTimes.put(event, time); _eventTimes.put(event, time);

View File

@ -374,7 +374,6 @@ public class MessageHistory {
buf.append(getPrefix()); buf.append(getPrefix());
buf.append("timed out waiting for a reply to [").append(sentMessage.getMessageType()); buf.append("timed out waiting for a reply to [").append(sentMessage.getMessageType());
buf.append("] [").append(sentMessage.getMessageId()).append("] expiring on ["); buf.append("] [").append(sentMessage.getMessageId()).append("] expiring on [");
if (sentMessage != null)
buf.append(getTime(sentMessage.getReplySelector().getExpiration())); buf.append(getTime(sentMessage.getReplySelector().getExpiration()));
buf.append("] ").append(sentMessage.getReplySelector().toString()); buf.append("] ").append(sentMessage.getReplySelector().toString());
addEntry(buf.toString()); addEntry(buf.toString());

View File

@ -86,7 +86,7 @@ public class StatisticsManager implements Service {
if (_context.getBooleanPropertyDefaultTrue(PROP_PUBLISH_RANKINGS) && if (_context.getBooleanPropertyDefaultTrue(PROP_PUBLISH_RANKINGS) &&
_context.random().nextInt(RANDOM_INCLUDE_STATS) == 0) { _context.random().nextInt(RANDOM_INCLUDE_STATS) == 0) {
long publishedUptime = _context.router().getUptime(); //long publishedUptime = _context.router().getUptime();
// Don't publish these for first hour // Don't publish these for first hour
// Disabled in 0.9 // Disabled in 0.9
//if (publishedUptime > 62*60*1000) //if (publishedUptime > 62*60*1000)

View File

@ -283,7 +283,6 @@ public class TunnelPoolSettings {
} }
private static final boolean getBoolean(String str, boolean defaultValue) { private static final boolean getBoolean(String str, boolean defaultValue) {
if (str == null) return defaultValue;
boolean v = Boolean.parseBoolean(str) || boolean v = Boolean.parseBoolean(str) ||
(str != null && "YES".equals(str.toUpperCase(Locale.US))); (str != null && "YES".equals(str.toUpperCase(Locale.US)));
return v; return v;

View File

@ -223,7 +223,6 @@ public class HandleDatabaseLookupMessageJob extends JobImpl {
private static boolean isUnreachable(RouterInfo info) { private static boolean isUnreachable(RouterInfo info) {
if (info == null) return true; if (info == null) return true;
String cap = info.getCapabilities(); String cap = info.getCapabilities();
if (cap == null) return false;
return cap.indexOf(Router.CAPABILITY_REACHABLE) >= 0; return cap.indexOf(Router.CAPABILITY_REACHABLE) >= 0;
} }

View File

@ -310,8 +310,6 @@ class FloodfillPeerSelector extends PeerSelector {
if (pinfo == null) if (pinfo == null)
return rv; return rv;
Collection<RouterAddress> paddr = pinfo.getAddresses(); Collection<RouterAddress> paddr = pinfo.getAddresses();
if (paddr == null)
return rv;
for (RouterAddress pa : paddr) { for (RouterAddress pa : paddr) {
byte[] pib = pa.getIP(); byte[] pib = pa.getIP();
if (pib == null) continue; if (pib == null) continue;

View File

@ -926,7 +926,7 @@ public class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacade {
*/ */
void dropAfterLookupFailed(Hash peer) { void dropAfterLookupFailed(Hash peer) {
_context.peerManager().removeCapabilities(peer); _context.peerManager().removeCapabilities(peer);
boolean removed = _kb.remove(peer); _kb.remove(peer);
//if (removed) { //if (removed) {
// if (_log.shouldLog(Log.INFO)) // if (_log.shouldLog(Log.INFO))
// _log.info("Removed kbucket entry for " + peer); // _log.info("Removed kbucket entry for " + peer);

View File

@ -1270,8 +1270,6 @@ public class ProfileOrganizer {
if (pinfo == null) if (pinfo == null)
return rv; return rv;
Collection<RouterAddress> paddr = pinfo.getAddresses(); Collection<RouterAddress> paddr = pinfo.getAddresses();
if (paddr == null)
return rv;
for (RouterAddress pa : paddr) { for (RouterAddress pa : paddr) {
byte[] pib = pa.getIP(); byte[] pib = pa.getIP();
if (pib == null) continue; if (pib == null) continue;

View File

@ -139,11 +139,9 @@ public class OutboundMessageRegistry {
if (o instanceof OutNetMessage) { if (o instanceof OutNetMessage) {
msg = (OutNetMessage)o; msg = (OutNetMessage)o;
if (msg != null)
rv.add(msg); rv.add(msg);
} else if (o instanceof List) { } else if (o instanceof List) {
msgs = (List<OutNetMessage>)o; msgs = (List<OutNetMessage>)o;
if (msgs != null)
rv.addAll(msgs); rv.addAll(msgs);
} }
} }

View File

@ -229,7 +229,7 @@ public class DHSessionKeyBuilder {
//_peerValue = new NativeBigInteger(val); //_peerValue = new NativeBigInteger(val);
} }
public BigInteger getPeerPublicValue() { public synchronized BigInteger getPeerPublicValue() {
return _peerValue; return _peerValue;
} }

View File

@ -952,8 +952,7 @@ public class NTCPTransport extends TransportImpl {
} }
} else if (enabled.equals("false") && } else if (enabled.equals("false") &&
name != null && name.length() > 0 && name != null && name.length() > 0 &&
!name.equals(ohost) && !name.equals(ohost)) {
nport != null) {
// Host name is configured, and we have a port (either auto or configured) // Host name is configured, and we have a port (either auto or configured)
// but we probably only get here if the port is auto, // but we probably only get here if the port is auto,
// otherwise createNTCPAddress() would have done it already // otherwise createNTCPAddress() would have done it already

View File

@ -1306,7 +1306,7 @@ class EstablishmentManager {
_outboundByHash.remove(outboundState.getRemoteIdentity().calculateHash(), outboundState); _outboundByHash.remove(outboundState.getRemoteIdentity().calculateHash(), outboundState);
// should have already been removed in handleOutbound() above // should have already been removed in handleOutbound() above
// remove only if value == state // remove only if value == state
boolean removed = _outboundStates.remove(outboundState.getRemoteHostId(), outboundState); _outboundStates.remove(outboundState.getRemoteHostId(), outboundState);
if (outboundState.getState() != OB_STATE_CONFIRMED_COMPLETELY) { if (outboundState.getState() != OB_STATE_CONFIRMED_COMPLETELY) {
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("Expired: " + outboundState + " Lifetime: " + outboundState.getLifetime()); _log.info("Expired: " + outboundState + " Lifetime: " + outboundState.getLifetime());

View File

@ -150,7 +150,6 @@ class OutboundMessageFragments {
* *
*/ */
public void add(OutNetMessage msg) { public void add(OutNetMessage msg) {
I2NPMessage msgBody = msg.getMessage();
RouterInfo target = msg.getTarget(); RouterInfo target = msg.getTarget();
if (target == null) if (target == null)
return; return;

View File

@ -58,7 +58,7 @@ class OutboundTunnelEndpoint {
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("outbound tunnel " + _config + " received a full message: " + msg _log.debug("outbound tunnel " + _config + " received a full message: " + msg
+ " to be forwarded on to " + " to be forwarded on to "
+ (toRouter != null ? toRouter.toBase64().substring(0,4) : "") + toRouter.toBase64().substring(0,4)
+ (toTunnel != null ? ":" + toTunnel.getTunnelId() : "")); + (toTunnel != null ? ":" + toTunnel.getTunnelId() : ""));
int size = msg.getMessageSize(); int size = msg.getMessageSize();
// don't drop it if we are the target // don't drop it if we are the target

View File

@ -348,9 +348,6 @@ public abstract class TunnelPeerSelector {
private static boolean shouldExclude(RouterContext ctx, Log log, RouterInfo peer, char excl[]) { private static boolean shouldExclude(RouterContext ctx, Log log, RouterInfo peer, char excl[]) {
String cap = peer.getCapabilities(); String cap = peer.getCapabilities();
if (cap == null) {
return true;
}
for (int j = 0; j < excl.length; j++) { for (int j = 0; j < excl.length; j++) {
if (cap.indexOf(excl[j]) >= 0) { if (cap.indexOf(excl[j]) >= 0) {
return true; return true;