forked from I2P_Developers/i2p.i2p
findbugs core,client,crypto,data,stat,i2np
This commit is contained in:
@ -63,7 +63,7 @@ import net.i2p.util.SecureDirectory;
|
||||
*/
|
||||
public class I2PAppContext {
|
||||
/** the context that components without explicit root are bound */
|
||||
protected static I2PAppContext _globalAppContext;
|
||||
protected static volatile I2PAppContext _globalAppContext;
|
||||
|
||||
private Properties _overrideProps;
|
||||
|
||||
@ -117,7 +117,8 @@ public class I2PAppContext {
|
||||
*
|
||||
*/
|
||||
public static I2PAppContext getGlobalContext() {
|
||||
// skip the global lock
|
||||
// skip the global lock - _gAC must be volatile
|
||||
// http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
|
||||
I2PAppContext rv = _globalAppContext;
|
||||
if (rv != null)
|
||||
return rv;
|
||||
@ -474,6 +475,9 @@ public class I2PAppContext {
|
||||
* provided during the context construction, as well as the ones included in
|
||||
* System.getProperties.
|
||||
*
|
||||
* WARNING - not overridden in RouterContext, doesn't contain router config settings,
|
||||
* use getProperties() instead.
|
||||
*
|
||||
* @return set of Strings containing the names of defined system properties
|
||||
*/
|
||||
public Set getPropertyNames() {
|
||||
|
@ -421,7 +421,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
*
|
||||
*/
|
||||
public byte[] receiveMessage(int msgId) throws I2PSessionException {
|
||||
MessagePayloadMessage msg = _availableMessages.remove(new Long(msgId));
|
||||
MessagePayloadMessage msg = _availableMessages.remove(Long.valueOf(msgId));
|
||||
if (msg == null) {
|
||||
_log.error("Receive message " + msgId + " had no matches");
|
||||
return null;
|
||||
@ -468,7 +468,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
* Recieve a payload message and let the app know its available
|
||||
*/
|
||||
public void addNewMessage(MessagePayloadMessage msg) {
|
||||
Long mid = new Long(msg.getMessageId());
|
||||
Long mid = Long.valueOf(msg.getMessageId());
|
||||
_availableMessages.put(mid, msg);
|
||||
long id = msg.getMessageId();
|
||||
byte data[] = msg.getPayload().getUnencryptedData();
|
||||
@ -518,7 +518,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
|
||||
public void available(long msgId, int size) {
|
||||
synchronized (AvailabilityNotifier.this) {
|
||||
_pendingIds.add(new Long(msgId));
|
||||
_pendingIds.add(Long.valueOf(msgId));
|
||||
_pendingSizes.add(Integer.valueOf(size));
|
||||
AvailabilityNotifier.this.notifyAll();
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ class I2PSessionMuxedImpl extends I2PSessionImpl2 implements I2PSession {
|
||||
*/
|
||||
@Override
|
||||
public void addNewMessage(MessagePayloadMessage msg) {
|
||||
Long mid = new Long(msg.getMessageId());
|
||||
Long mid = Long.valueOf(msg.getMessageId());
|
||||
_availableMessages.put(mid, msg);
|
||||
long id = msg.getMessageId();
|
||||
byte data[] = msg.getPayload().getUnencryptedData();
|
||||
|
@ -108,7 +108,7 @@ class I2PSimpleSession extends I2PSessionImpl2 {
|
||||
/**
|
||||
* Only map message handlers that we will use
|
||||
*/
|
||||
class SimpleMessageHandlerMap extends I2PClientMessageHandlerMap {
|
||||
private static class SimpleMessageHandlerMap extends I2PClientMessageHandlerMap {
|
||||
public SimpleMessageHandlerMap(I2PAppContext context) {
|
||||
int highest = Math.max(DestReplyMessage.MESSAGE_TYPE, BandwidthLimitsMessage.MESSAGE_TYPE);
|
||||
_handlers = new I2CPMessageHandler[highest+1];
|
||||
|
@ -149,7 +149,7 @@ public class CryptixAESEngine extends AESEngine {
|
||||
@Override
|
||||
public final void decryptBlock(byte payload[], int inIndex, SessionKey sessionKey, byte rv[], int outIndex) {
|
||||
if ( (payload == null) || (rv == null) )
|
||||
throw new IllegalArgumentException("null block args [payload=" + payload + " rv="+rv);
|
||||
throw new IllegalArgumentException("null block args");
|
||||
if (payload.length - inIndex > rv.length - outIndex)
|
||||
throw new IllegalArgumentException("bad block args [payload.len=" + payload.length
|
||||
+ " inIndex=" + inIndex + " rv.len=" + rv.length
|
||||
|
@ -72,13 +72,13 @@ public class Base32 {
|
||||
}
|
||||
|
||||
private static void runApp(String args[]) {
|
||||
if ("encodestring".equalsIgnoreCase(args[0])) {
|
||||
System.out.println(encode(args[1].getBytes()));
|
||||
return;
|
||||
}
|
||||
InputStream in = System.in;
|
||||
OutputStream out = System.out;
|
||||
try {
|
||||
if ("encodestring".equalsIgnoreCase(args[0])) {
|
||||
System.out.println(encode(args[1].getBytes()));
|
||||
return;
|
||||
}
|
||||
InputStream in = System.in;
|
||||
OutputStream out = System.out;
|
||||
if (args.length >= 3) {
|
||||
out = new FileOutputStream(args[2]);
|
||||
}
|
||||
@ -95,6 +95,9 @@ public class Base32 {
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace(System.err);
|
||||
} finally {
|
||||
try { in.close(); } catch (IOException e) {}
|
||||
try { out.close(); } catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,13 +178,13 @@ public class Base64 {
|
||||
}
|
||||
|
||||
private static void runApp(String args[]) {
|
||||
if ("encodestring".equalsIgnoreCase(args[0])) {
|
||||
System.out.println(encode(args[1].getBytes()));
|
||||
return;
|
||||
}
|
||||
InputStream in = System.in;
|
||||
OutputStream out = System.out;
|
||||
try {
|
||||
if ("encodestring".equalsIgnoreCase(args[0])) {
|
||||
System.out.println(encode(args[1].getBytes()));
|
||||
return;
|
||||
}
|
||||
InputStream in = System.in;
|
||||
OutputStream out = System.out;
|
||||
if (args.length >= 3) {
|
||||
out = new FileOutputStream(args[2]);
|
||||
}
|
||||
@ -201,6 +201,9 @@ public class Base64 {
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace(System.err);
|
||||
} finally {
|
||||
try { in.close(); } catch (IOException e) {}
|
||||
try { out.close(); } catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -844,7 +844,7 @@ public class DataHelper {
|
||||
*/
|
||||
public final static void xor(byte lhs[], int startLeft, byte rhs[], int startRight, byte out[], int startOut, int len) {
|
||||
if ( (lhs == null) || (rhs == null) || (out == null) )
|
||||
throw new NullPointerException("Invalid params to xor (" + lhs + ", " + rhs + ", " + out + ")");
|
||||
throw new NullPointerException("Null params to xor");
|
||||
if (lhs.length < startLeft + len)
|
||||
throw new IllegalArgumentException("Left hand side is too short");
|
||||
if (rhs.length < startRight + len)
|
||||
|
@ -133,9 +133,15 @@ public class PrivateKeyFile {
|
||||
*/
|
||||
public Destination createIfAbsent() throws I2PException, IOException, DataFormatException {
|
||||
if(!this.file.exists()) {
|
||||
FileOutputStream out = new FileOutputStream(this.file);
|
||||
this.client.createDestination(out);
|
||||
out.close();
|
||||
FileOutputStream out = null;
|
||||
try {
|
||||
out = new FileOutputStream(this.file);
|
||||
this.client.createDestination(out);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try { out.close(); } catch (IOException ioe) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
return getDestination();
|
||||
}
|
||||
@ -243,29 +249,36 @@ public class PrivateKeyFile {
|
||||
public I2PSession open() throws I2PSessionException, IOException {
|
||||
return this.open(new Properties());
|
||||
}
|
||||
|
||||
public I2PSession open(Properties opts) throws I2PSessionException, IOException {
|
||||
// open input file
|
||||
FileInputStream in = new FileInputStream(this.file);
|
||||
|
||||
// create sesssion
|
||||
I2PSession s = this.client.createSession(in, opts);
|
||||
|
||||
// close file
|
||||
in.close();
|
||||
|
||||
return s;
|
||||
FileInputStream in = null;
|
||||
try {
|
||||
in = new FileInputStream(this.file);
|
||||
I2PSession s = this.client.createSession(in, opts);
|
||||
return s;
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try { in.close(); } catch (IOException ioe) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copied from I2PClientImpl.createDestination()
|
||||
*/
|
||||
public void write() throws IOException, DataFormatException {
|
||||
FileOutputStream out = new FileOutputStream(this.file);
|
||||
this.dest.writeBytes(out);
|
||||
this.privKey.writeBytes(out);
|
||||
this.signingPrivKey.writeBytes(out);
|
||||
out.flush();
|
||||
out.close();
|
||||
FileOutputStream out = null;
|
||||
try {
|
||||
out = new FileOutputStream(this.file);
|
||||
this.dest.writeBytes(out);
|
||||
this.privKey.writeBytes(out);
|
||||
this.signingPrivKey.writeBytes(out);
|
||||
out.flush();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try { out.close(); } catch (IOException ioe) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -377,7 +390,8 @@ public class PrivateKeyFile {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ioe) {
|
||||
} catch (DataFormatException dfe) {
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
// not found, continue to the next file
|
||||
}
|
||||
|
@ -76,10 +76,11 @@ public class DestReplyMessage extends I2CPMessageImpl {
|
||||
}
|
||||
|
||||
protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
|
||||
if (_dest == null && _hash == null)
|
||||
return new byte[0]; // null response allowed
|
||||
if (_dest == null && _hash != null)
|
||||
if (_dest == null) {
|
||||
if (_hash == null)
|
||||
return new byte[0]; // null response allowed
|
||||
return _hash.getData();
|
||||
}
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream(_dest.size());
|
||||
try {
|
||||
_dest.writeBytes(os);
|
||||
|
@ -89,7 +89,7 @@ public class FrequencyStat {
|
||||
/** @since 0.8.2 */
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if ((obj == null) || (obj.getClass() != FrequencyStat.class)) return false;
|
||||
if ((obj == null) || !(obj instanceof FrequencyStat)) return false;
|
||||
return _statName.equals(((FrequencyStat)obj)._statName);
|
||||
}
|
||||
|
||||
|
@ -473,7 +473,7 @@ public class Rate {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if ((obj == null) || (obj.getClass() != Rate.class)) return false;
|
||||
if ((obj == null) || !(obj instanceof Rate)) return false;
|
||||
if (obj == this) return true;
|
||||
Rate r = (Rate) obj;
|
||||
return _period == r.getPeriod() && _creationDate == r.getCreationDate() &&
|
||||
|
@ -108,7 +108,7 @@ public class RateStat {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if ((obj == null) || (obj.getClass() != RateStat.class)) return false;
|
||||
if ((obj == null) || !(obj instanceof RateStat)) return false;
|
||||
RateStat rs = (RateStat) obj;
|
||||
if (DataHelper.eq(getGroupName(), rs.getGroupName()) && DataHelper.eq(getDescription(), rs.getDescription())
|
||||
&& DataHelper.eq(getName(), rs.getName())) {
|
||||
|
@ -116,7 +116,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
|
||||
if (!eq)
|
||||
throw new I2NPMessageException("Hash does not match for " + getClass().getName());
|
||||
|
||||
long start = _context.clock().now();
|
||||
//long start = _context.clock().now();
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Reading bytes: type = " + type + " / uniqueId : " + _uniqueId + " / expiration : " + _expiration);
|
||||
readMessage(buffer, 0, size, type);
|
||||
@ -159,7 +159,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
|
||||
if (!eq)
|
||||
throw new I2NPMessageException("Hash does not match for " + getClass().getName());
|
||||
|
||||
long start = _context.clock().now();
|
||||
//long start = _context.clock().now();
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Reading bytes: type = " + type + " / uniqueId : " + _uniqueId + " / expiration : " + _expiration);
|
||||
readMessage(data, cur, size, type);
|
||||
@ -215,7 +215,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
|
||||
}
|
||||
|
||||
public int toByteArray(byte buffer[]) {
|
||||
long start = _context.clock().now();
|
||||
//long start = _context.clock().now();
|
||||
|
||||
int prefixLen = 1 // type
|
||||
+ 4 // uniqueId
|
||||
|
@ -160,7 +160,7 @@ public class TunnelDataMessage extends I2NPMessageImpl {
|
||||
/** write the message body to the output array, starting at the given index */
|
||||
protected int writeMessageBody(byte out[], int curIndex) throws I2NPMessageException {
|
||||
if ( (_tunnelId <= 0) || (_data == null) )
|
||||
throw new I2NPMessageException("Not enough data to write out (id=" + _tunnelId + " data=" + _data + ")");
|
||||
throw new I2NPMessageException("Not enough data to write out (id=" + _tunnelId + ")");
|
||||
if (_data.length <= 0)
|
||||
throw new I2NPMessageException("Not enough data to write out (data.length=" + _data.length + ")");
|
||||
|
||||
|
Reference in New Issue
Block a user