Findbugs all over:

- Serializable
 - hashCode()
 - Make DataStructureImpl Serializable (removed from DataStructure in 2005)
This commit is contained in:
zzz
2014-06-15 16:14:13 +00:00
parent ff189e796c
commit 8845ce6e1c
49 changed files with 201 additions and 130 deletions

View File

@ -41,6 +41,7 @@ package gnu.crypto.prng;
// do so, delete this exception statement from your version.
// ----------------------------------------------------------------------------
import java.io.Serializable;
import java.util.Map;
/**
@ -49,7 +50,7 @@ import java.util.Map;
* Modified slightly by jrandom for I2P (removing unneeded exceptions)
* @version $Revision: 1.1 $
*/
public abstract class BasePRNGStandalone implements IRandomStandalone {
public abstract class BasePRNGStandalone implements IRandomStandalone, Serializable {
// Constants and variables
// -------------------------------------------------------------------------

View File

@ -1,5 +1,6 @@
package net.i2p.crypto;
import java.io.Serializable;
import java.util.concurrent.LinkedBlockingQueue;
/**
@ -52,21 +53,26 @@ public final class CryptixAESKeyCache {
public static final KeyCacheEntry createNew() {
KeyCacheEntry e = new KeyCacheEntry();
e.Ke = new int[ROUNDS + 1][BC]; // encryption round keys
e.Kd = new int[ROUNDS + 1][BC]; // decryption round keys
e.tk = new int[KC];
e.key = new Object[] { e.Ke, e.Kd };
return e;
}
/**
* all the data alloc'ed in a makeKey call
*/
public static final class KeyCacheEntry {
int[][] Ke;
int[][] Kd;
int[] tk;
Object[] key;
public static class KeyCacheEntry implements Serializable {
/** encryption round keys */
final int[][] Ke;
/** decryption round keys */
final int[][] Kd;
final int[] tk;
/** Ke, Kd */
final Object[] key;
public KeyCacheEntry() {
Ke = new int[ROUNDS + 1][BC];
Kd = new int[ROUNDS + 1][BC];
tk = new int[KC];
key = new Object[] { Ke, Kd };
}
}
}

View File

@ -10,6 +10,7 @@ package net.i2p.crypto;
*/
import java.io.IOException;
import java.io.Serializable;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Comparator;
@ -798,7 +799,7 @@ public class TransientSessionKeyManager extends SessionKeyManager {
* Just for the HTML method above so we can see what's going on easier
* Earliest first
*/
private static class TagSetComparator implements Comparator<TagSet> {
private static class TagSetComparator implements Comparator<TagSet>, Serializable {
public int compare(TagSet l, TagSet r) {
int rv = (int) (l.getDate() - r.getDate());
if (rv != 0)

View File

@ -24,6 +24,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
@ -1463,7 +1464,7 @@ public class DataHelper {
* See sortStructures() comments.
* @since 0.8.3
*/
private static class DataStructureComparator implements Comparator<DataStructure> {
private static class DataStructureComparator implements Comparator<DataStructure>, Serializable {
public int compare(DataStructure l, DataStructure r) {
return l.calculateHash().toBase64().compareTo(r.calculateHash().toBase64());
}

View File

@ -13,6 +13,7 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import net.i2p.I2PAppContext;
import net.i2p.crypto.SHA256Generator;
@ -23,7 +24,7 @@ import net.i2p.util.Log;
*
* @author jrandom
*/
public abstract class DataStructureImpl implements DataStructure {
public abstract class DataStructureImpl implements DataStructure, Serializable {
public String toBase64() {
byte data[] = toByteArray();

View File

@ -186,4 +186,10 @@ public class Destination extends KeysAndCert {
public boolean equals(Object o) {
return super.equals(o) && (o instanceof Destination);
}
@Override
public int hashCode() {
// findbugs
return super.hashCode();
}
}

View File

@ -12,6 +12,7 @@ package net.i2p.data.i2cp;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -28,9 +29,12 @@ import net.i2p.data.TunnelId;
* @author jrandom
*/
public class RequestLeaseSetMessage extends I2CPMessageImpl {
private static final long serialVersionUID = 1L;
public final static int MESSAGE_TYPE = 21;
private SessionId _sessionId;
private final List<TunnelEndpoint> _endpoints;
// ArrayList is Serializable, List is not
private final ArrayList<TunnelEndpoint> _endpoints;
private Date _end;
public RequestLeaseSetMessage() {
@ -139,7 +143,8 @@ public class RequestLeaseSetMessage extends I2CPMessageImpl {
return buf.toString();
}
private static class TunnelEndpoint {
private static class TunnelEndpoint implements Serializable {
private static final long serialVersionUID = 1L;
private final Hash _router;
private final TunnelId _tunnelId;

View File

@ -35,7 +35,6 @@ import net.i2p.util.OrderedProperties;
* @author jrandom
*/
public class SessionConfig extends DataStructureImpl {
private final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(SessionConfig.class);
private Destination _destination;
private Signature _signature;
private Date _creationDate;
@ -125,31 +124,32 @@ public class SessionConfig extends DataStructureImpl {
*/
public boolean verifySignature() {
if (getSignature() == null) {
if (_log.shouldLog(Log.WARN)) _log.warn("Signature is null!");
//if (_log.shouldLog(Log.WARN)) _log.warn("Signature is null!");
return false;
}
if (getDestination() == null) {
if (_log.shouldLog(Log.WARN)) _log.warn("Destination is null!");
//if (_log.shouldLog(Log.WARN)) _log.warn("Destination is null!");
return false;
}
if (getCreationDate() == null) {
if (_log.shouldLog(Log.WARN)) _log.warn("Date is null!");
//if (_log.shouldLog(Log.WARN)) _log.warn("Date is null!");
return false;
}
if (tooOld()) {
if (_log.shouldLog(Log.WARN)) _log.warn("Too old!");
//if (_log.shouldLog(Log.WARN)) _log.warn("Too old!");
return false;
}
byte data[] = getBytes();
if (data == null) {
if (_log.shouldLog(Log.WARN)) _log.warn("Bytes could not be found - wtf?");
//if (_log.shouldLog(Log.WARN)) _log.warn("Bytes could not be found - wtf?");
return false;
}
boolean ok = DSAEngine.getInstance().verifySignature(getSignature(), data,
getDestination().getSigningPublicKey());
if (!ok) {
if (_log.shouldLog(Log.WARN)) _log.warn("DSA signature failed!");
Log log = I2PAppContext.getGlobalContext().logManager().getLog(SessionConfig.class);
if (log.shouldLog(Log.WARN)) log.warn("DSA signature failed!");
}
return ok;
}
@ -177,10 +177,12 @@ public class SessionConfig extends DataStructureImpl {
DataHelper.writeProperties(out, _options, true); // UTF-8
DataHelper.writeDate(out, _creationDate);
} catch (IOException ioe) {
_log.error("IOError signing", ioe);
Log log = I2PAppContext.getGlobalContext().logManager().getLog(SessionConfig.class);
log.error("IOError signing", ioe);
return null;
} catch (DataFormatException dfe) {
_log.error("Error writing out the bytes for signing/verification", dfe);
Log log = I2PAppContext.getGlobalContext().logManager().getLog(SessionConfig.class);
log.error("Error writing out the bytes for signing/verification", dfe);
return null;
}
return out.toByteArray();

View File

@ -8,6 +8,7 @@ package net.i2p.kademlia;
*
*/
import java.io.Serializable;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
@ -750,7 +751,7 @@ public class KBucketSet<T extends SimpleDataStructure> {
* For Collections.binarySearch.
* Returns equal for any overlap.
*/
private static class BucketComparator<T extends SimpleDataStructure> implements Comparator<KBucket<T>> {
private static class BucketComparator<T extends SimpleDataStructure> implements Comparator<KBucket<T>>, Serializable {
public int compare(KBucket<T> l, KBucket<T> r) {
if (l.getRangeEnd() < r.getRangeBegin())
return -1;

View File

@ -1,5 +1,6 @@
package net.i2p.kademlia;
import java.io.Serializable;
import java.util.Comparator;
import net.i2p.data.SimpleDataStructure;
@ -9,7 +10,7 @@ import net.i2p.data.SimpleDataStructure;
*
* @since 0.9.2 in i2psnark, moved to core in 0.9.10
*/
public class XORComparator<T extends SimpleDataStructure> implements Comparator<T> {
public class XORComparator<T extends SimpleDataStructure> implements Comparator<T>, Serializable {
private final byte[] _base;
/**

View File

@ -1,5 +1,6 @@
package net.i2p.util;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.ConcurrentModificationException;
@ -38,7 +39,7 @@ public class CachedIteratorArrayList<E> extends ArrayList<E> {
return iterator;
}
private class CachedIterator implements Iterator<E> {
private class CachedIterator implements Iterator<E>, Serializable {
/**
* Index of element to be returned by subsequent call to next.
*/

View File

@ -811,4 +811,10 @@ public class NativeBigInteger extends BigInteger {
// for findbugs
return super.equals(o);
}
@Override
public int hashCode() {
// for findbugs
return super.hashCode();
}
}

View File

@ -9,6 +9,7 @@ package net.i2p.util;
*
*/
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
@ -46,7 +47,7 @@ public class OrderedProperties extends Properties {
return Collections.unmodifiableSortedSet(rv);
}
private static class EntryComparator implements Comparator<Map.Entry<Object, Object>> {
private static class EntryComparator implements Comparator<Map.Entry<Object, Object>>, Serializable {
public int compare(Map.Entry<Object, Object> l, Map.Entry<Object, Object> r) {
return ((String)l.getKey()).compareTo(((String)r.getKey()));
}

View File

@ -25,8 +25,10 @@ import net.i2p.crypto.EntropyHarvester;
* @author jrandom
*/
public class RandomSource extends SecureRandom implements EntropyHarvester {
private static final long serialVersionUID = 1L;
private final EntropyHarvester _entropyHarvester;
protected final I2PAppContext _context;
protected transient final I2PAppContext _context;
/**
* Deprecated - do not instantiate this directly, as you won't get the

View File

@ -1,5 +1,6 @@
package net.i2p.util;
import java.io.Serializable;
import java.util.Comparator;
/**
@ -9,7 +10,7 @@ import java.util.Comparator;
* Moved from TrustedUpdate.java
* @since 0.7.10
*/
public class VersionComparator implements Comparator<String> {
public class VersionComparator implements Comparator<String>, Serializable {
public int compare(String l, String r) {
return comp(l, r);

View File

@ -29,6 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package net.metanotion.io.block.index;
import java.io.IOException;
import java.io.Serializable;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;
@ -311,7 +312,7 @@ public class BSkipLevels extends SkipLevels {
* Sorts in REVERSE order.
* @since 0.8.8
*/
private static class LevelComparator implements Comparator<SkipLevels> {
private static class LevelComparator implements Comparator<SkipLevels>, Serializable {
public int compare(SkipLevels l, SkipLevels r) {
Comparable lk = l.key();
Comparable rk = r.key();