Fix NPE when cancelling PacketLocal's

This commit is contained in:
zab2
2013-07-25 20:07:12 +00:00
parent a02cc25844
commit dd181a90e1

View File

@@ -32,7 +32,7 @@ class PacketLocal extends Packet implements MessageOutputStream.WriteStatus {
private long _cancelledOn; private long _cancelledOn;
private final AtomicInteger _nackCount = new AtomicInteger(0); private final AtomicInteger _nackCount = new AtomicInteger(0);
private volatile boolean _retransmitted; private volatile boolean _retransmitted;
private SimpleTimer2.TimedEvent _resendEvent; private volatile SimpleTimer2.TimedEvent _resendEvent;
/** not bound to a connection */ /** not bound to a connection */
public PacketLocal(I2PAppContext ctx, Destination to) { public PacketLocal(I2PAppContext ctx, Destination to) {
@@ -112,6 +112,13 @@ class PacketLocal extends Packet implements MessageOutputStream.WriteStatus {
_numSends++; _numSends++;
_lastSend = _context.clock().now(); _lastSend = _context.clock().now();
} }
private void cancelResend() {
SimpleTimer2.TimedEvent ev = _resendEvent;
if (ev != null)
ev.cancel();
}
public void ackReceived() { public void ackReceived() {
final long now = _context.clock().now(); final long now = _context.clock().now();
synchronized (this) { synchronized (this) {
@@ -120,15 +127,16 @@ class PacketLocal extends Packet implements MessageOutputStream.WriteStatus {
releasePayload(); releasePayload();
notifyAll(); notifyAll();
} }
_resendEvent.cancel(); cancelResend();
} }
public void cancelled() { public void cancelled() {
synchronized (this) { synchronized (this) {
_cancelledOn = _context.clock().now(); _cancelledOn = _context.clock().now();
releasePayload(); releasePayload();
notifyAll(); notifyAll();
} }
_resendEvent.cancel(); cancelResend();
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Cancelled! " + toString(), new Exception("cancelled")); _log.debug("Cancelled! " + toString(), new Exception("cancelled"));
} }