Skip to content

Commit 389e804

Browse files
committed
asserts
1 parent 62f9ee9 commit 389e804

25 files changed

+2
-59
lines changed

AndroidAsync/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.koushikdutta.async"
3-
android:versionCode="308"
4-
android:versionName="3.0.9">
3+
android:versionCode="310"
4+
android:versionName="3.1.0">
55

66
<uses-permission android:name="android.permission.INTERNET"/>
77

AndroidAsync/src/com/koushikdutta/async/AsyncNetworkSocket.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ ChannelWrapper getChannel() {
4949
}
5050

5151
public void onDataWritable() {
52-
// assert mWriteableHandler != null;
5352
if (!mChannel.isChunked()) {
5453
// turn write off
5554
mKey.interestOps(~SelectionKey.OP_WRITE & mKey.interestOps());
@@ -79,7 +78,6 @@ public void run() {
7978
return;
8079
}
8180
if (!mChannel.isConnected()) {
82-
assert !mChannel.isChunked();
8381
return;
8482
}
8583

@@ -103,7 +101,6 @@ private void handleRemaining(int remaining) throws IOException {
103101
throw new IOException(new CancelledKeyException());
104102
if (remaining > 0) {
105103
// chunked channels should not fail
106-
assert !mChannel.isChunked();
107104
// register for a write notification if a write fails
108105
// turn write on
109106
mKey.interestOps(SelectionKey.OP_WRITE | mKey.interestOps());

AndroidAsync/src/com/koushikdutta/async/AsyncSSLSocketWrapper.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ public void write(ByteBufferList bb) {
471471
bb.addAll(arr);
472472
writeBuf.flip();
473473
writeList.add(writeBuf);
474-
assert !writeList.hasRemaining();
475474
if (writeList.remaining() > 0)
476475
mSink.write(writeList);
477476
int previousCapacity = writeBuf.capacity();

AndroidAsync/src/com/koushikdutta/async/AsyncServer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ public Cancellable connectResolvedInetSocketAddress(final InetSocketAddress addr
396396

397397
public ConnectFuture connectResolvedInetSocketAddress(final InetSocketAddress address, final ConnectCallback callback, final SocketCreateCallback createCallback) {
398398
final ConnectFuture cancel = new ConnectFuture();
399-
assert !address.isUnresolved();
400399

401400
post(new Runnable() {
402401
@Override

AndroidAsync/src/com/koushikdutta/async/BufferedDataSink.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ public int getMaxBuffer() {
104104
}
105105

106106
public void setMaxBuffer(int maxBuffer) {
107-
assert maxBuffer >= 0;
108107
mMaxBuffer = maxBuffer;
109108
}
110109

AndroidAsync/src/com/koushikdutta/async/ByteBufferList.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ public void get(byte[] bytes, int offset, int length) {
166166
offset += read;
167167
if (b.remaining() == 0) {
168168
ByteBuffer removed = mBuffers.remove();
169-
assert b == removed;
170169
reclaim(b);
171170
}
172171
}
@@ -196,8 +195,6 @@ public void get(ByteBufferList into, int length) {
196195
b.get(subset.array(), 0, need);
197196
into.add(subset);
198197
mBuffers.addFirst(b);
199-
assert subset.capacity() >= need;
200-
assert subset.position() == 0;
201198
break;
202199
}
203200
else {
@@ -338,7 +335,6 @@ public void recycle() {
338335
while (mBuffers.size() > 0) {
339336
reclaim(mBuffers.remove());
340337
}
341-
assert mBuffers.size() == 0;
342338
remaining = 0;
343339
}
344340

@@ -465,14 +461,11 @@ public static void reclaim(ByteBuffer b) {
465461
return;
466462
}
467463

468-
assert !reclaimedContains(b);
469-
470464
b.position(0);
471465
b.limit(b.capacity());
472466
currentSize += b.capacity();
473467

474468
r.add(b);
475-
assert r.size() != 0 ^ currentSize == 0;
476469

477470
maxItem = Math.max(maxItem, b.capacity());
478471
}
@@ -490,7 +483,6 @@ public static ByteBuffer obtain(int size) {
490483
if (r.size() == 0)
491484
maxItem = 0;
492485
currentSize -= ret.capacity();
493-
assert r.size() != 0 ^ currentSize == 0;
494486
if (ret.capacity() >= size) {
495487
// System.out.println("using " + ret.capacity());
496488
return ret;
@@ -516,7 +508,6 @@ public static void obtainArray(ByteBuffer[] arr, int size) {
516508
while (r.size() > 0 && total < size && index < arr.length - 1) {
517509
ByteBuffer b = r.remove();
518510
currentSize -= b.capacity();
519-
assert r.size() != 0 ^ currentSize == 0;
520511
int needed = Math.min(size - total, b.capacity());
521512
total += needed;
522513
arr[index++] = b;

AndroidAsync/src/com/koushikdutta/async/DataEmitterReader.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ public class DataEmitterReader implements com.koushikdutta.async.callback.DataCa
88
ByteBufferList mPendingData = new ByteBufferList();
99

1010
public void read(int count, DataCallback callback) {
11-
assert mPendingRead == null;
1211
mPendingReadLength = count;
1312
mPendingRead = callback;
14-
assert !mPendingData.hasRemaining();
1513
mPendingData.recycle();
1614
}
1715

@@ -22,7 +20,6 @@ private boolean handlePendingData(DataEmitter emitter) {
2220
DataCallback pendingRead = mPendingRead;
2321
mPendingRead = null;
2422
pendingRead.onDataAvailable(emitter, mPendingData);
25-
assert !mPendingData.hasRemaining();
2623

2724
return true;
2825
}
@@ -32,7 +29,6 @@ public DataEmitterReader() {
3229
@Override
3330
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
3431
// if we're registered for data, we must be waiting for a read
35-
assert mPendingRead != null;
3632
do {
3733
int need = Math.min(bb.remaining(), mPendingReadLength - mPendingData.remaining());
3834
bb.get(mPendingData, need);

AndroidAsync/src/com/koushikdutta/async/LineEmitter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
3737
while (bb.remaining() > 0) {
3838
byte b = bb.get();
3939
if (b == '\n') {
40-
assert mLineCallback != null;
4140
buffer.flip();
4241
data.add(buffer);
4342
mLineCallback.onStringAvailable(data.readString(charset));

AndroidAsync/src/com/koushikdutta/async/ServerSocketChannelWrapper.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,17 @@ public int getLocalPort() {
3737
@Override
3838
public int read(ByteBuffer buffer) throws IOException {
3939
final String msg = "Can't read ServerSocketChannel";
40-
assert false;
4140
throw new IOException(msg);
4241
}
4342

4443
@Override
4544
public boolean isConnected() {
46-
assert false;
4745
return false;
4846
}
4947

5048
@Override
5149
public int write(ByteBuffer src) throws IOException {
5250
final String msg = "Can't write ServerSocketChannel";
53-
assert false;
5451
throw new IOException(msg);
5552
}
5653

@@ -62,21 +59,18 @@ public SelectionKey register(Selector sel) throws ClosedChannelException {
6259
@Override
6360
public int write(ByteBuffer[] src) throws IOException {
6461
final String msg = "Can't write ServerSocketChannel";
65-
assert false;
6662
throw new IOException(msg);
6763
}
6864

6965
@Override
7066
public long read(ByteBuffer[] byteBuffers) throws IOException {
7167
final String msg = "Can't read ServerSocketChannel";
72-
assert false;
7368
throw new IOException(msg);
7469
}
7570

7671
@Override
7772
public long read(ByteBuffer[] byteBuffers, int i, int i2) throws IOException {
7873
final String msg = "Can't read ServerSocketChannel";
79-
assert false;
8074
throw new IOException(msg);
8175
}
8276

AndroidAsync/src/com/koushikdutta/async/Util.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public static void emitAllData(DataEmitter emitter, ByteBufferList list) {
3636
list.recycle();
3737
if (SUPRESS_DEBUG_EXCEPTIONS)
3838
return;
39-
assert false;
4039
throw new RuntimeException("mDataHandler failed to consume data, yet remains the mDataHandler.");
4140
}
4241
}
@@ -50,7 +49,6 @@ public static void emitAllData(DataEmitter emitter, ByteBufferList list) {
5049
list.recycle();
5150
if (SUPRESS_DEBUG_EXCEPTIONS)
5251
return;
53-
// assert false;
5452
// throw new AssertionError("Not all data was consumed by Util.emitAllData");
5553
}
5654
}

AndroidAsync/src/com/koushikdutta/async/future/Continuation.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public void onCompleted(Exception ex) {
5656
if (mThisCompleted)
5757
return;
5858
mThisCompleted = true;
59-
assert waiting;
6059
waiting = false;
6160
if (ex == null) {
6261
next();

AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpClient.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ public boolean cancel() {
153153
}
154154

155155
private void reportConnectedCompleted(FutureAsyncHttpResponse cancel, Exception ex, AsyncHttpResponseImpl response, AsyncHttpRequest request, final HttpConnectCallback callback) {
156-
assert callback != null;
157156
cancel.scheduled.cancel();
158157
boolean complete;
159158
if (ex != null) {
@@ -166,7 +165,6 @@ private void reportConnectedCompleted(FutureAsyncHttpResponse cancel, Exception
166165
}
167166
if (complete) {
168167
callback.onConnectCompleted(ex, response);
169-
assert ex != null || response.socket() == null || response.getDataCallback() != null || response.isPaused();
170168
return;
171169
}
172170

@@ -204,7 +202,6 @@ private static void copyHeader(AsyncHttpRequest from, AsyncHttpRequest to, Strin
204202
}
205203

206204
private void executeAffinity(final AsyncHttpRequest request, final int redirectCount, final FutureAsyncHttpResponse cancel, final HttpConnectCallback callback) {
207-
assert mServer.isAffinityThread();
208205
if (redirectCount > 15) {
209206
reportConnectedCompleted(cancel, new RedirectLimitExceededException("too many redirects"), null, request, callback);
210207
return;
@@ -704,13 +701,11 @@ public Future<WebSocket> websocket(final AsyncHttpRequest req, String[] protocol
704701
}
705702

706703
public Future<WebSocket> websocket(String uri, String protocol, final WebSocketConnectCallback callback) {
707-
// assert callback != null;
708704
final AsyncHttpGet get = new AsyncHttpGet(uri.replace("ws://", "http://").replace("wss://", "https://"));
709705
return websocket(get, protocol, callback);
710706
}
711707

712708
public Future<WebSocket> websocket(String uri, String[] protocols, final WebSocketConnectCallback callback) {
713-
// assert callback != null;
714709
final AsyncHttpGet get = new AsyncHttpGet(uri.replace("ws://", "http://").replace("wss://", "https://"));
715710
return websocket(get, protocols, callback);
716711
}

AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpRequest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public static void setDefaultHeaders(Headers ret, Uri uri) {
9797
public static final String HEADER_ACCEPT_ALL = "*/*";
9898

9999
public AsyncHttpRequest(Uri uri, String method, Headers headers) {
100-
assert uri != null;
101100
mMethod = method;
102101
this.uri = uri;
103102
if (headers == null)

AndroidAsync/src/com/koushikdutta/async/http/AsyncHttpResponseImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ private void assertContent() {
175175
if (!mFirstWrite)
176176
return;
177177
mFirstWrite = false;
178-
assert null != mRequest.getHeaders().get("Content-Type");
179-
assert mRequest.getHeaders().get("Transfer-Encoding") != null || HttpUtil.contentLength(mRequest.getHeaders()) != -1;
180178
}
181179

182180
DataSink mSink;

AndroidAsync/src/com/koushikdutta/async/http/HybiParser.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
192192
DataCallback mStage4 = new DataCallback() {
193193
@Override
194194
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
195-
assert bb.remaining() == mLength;
196195
mPayload = new byte[mLength];
197196
bb.get(mPayload);
198197
try {

AndroidAsync/src/com/koushikdutta/async/http/body/MultipartFormDataBody.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ public void onContinue(Continuation continuation, CompletedCallback next) throws
178178
byte[] bytes = (getBoundaryEnd()).getBytes();
179179
com.koushikdutta.async.Util.writeAll(sink, bytes, next);
180180
written += bytes.length;
181-
182-
assert written == totalToWrite;
183181
}
184182
});
185183
c.start();

AndroidAsync/src/com/koushikdutta/async/http/body/Part.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,5 @@ public long length() {
6666
}
6767

6868
public void write(DataSink sink, CompletedCallback callback) {
69-
assert false;
7069
}
7170
}

AndroidAsync/src/com/koushikdutta/async/http/cache/ResponseCacheMiddleware.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ void sendCachedDataOnNetworkThread() {
439439
// fill pending
440440
try {
441441
ByteBuffer buffer = allocator.allocate();
442-
assert buffer.position() == 0;
443442
FileInputStream din = cacheResponse.getBody();
444443
int read = din.read(buffer.array(), buffer.arrayOffset(), buffer.capacity());
445444
if (read == -1) {

AndroidAsync/src/com/koushikdutta/async/http/filter/ChunkedInputFilter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ else if (c >= 'A' && c <= 'F')
112112
mChunkLength = 0;
113113
break;
114114
case COMPLETE:
115-
assert false;
116115
// Exception fail = new Exception("Continued receiving data after chunk complete");
117116
// report(fail);
118117
return;

AndroidAsync/src/com/koushikdutta/async/http/filter/ContentLengthFilter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ protected void report(Exception e) {
2121
ByteBufferList transformed = new ByteBufferList();
2222
@Override
2323
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
24-
assert totalRead < contentLength;
25-
2624
int remaining = bb.remaining();
2725
long toRead = Math.min(contentLength - totalRead, remaining);
2826

AndroidAsync/src/com/koushikdutta/async/http/filter/InflaterInputFilter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
3838
if (!output.hasRemaining()) {
3939
output.flip();
4040
transformed.add(output);
41-
assert totalRead != 0;
4241
int newSize = output.capacity() * 2;
4342
output = ByteBufferList.obtain(newSize);
4443
}

AndroidAsync/src/com/koushikdutta/async/http/server/AsyncHttpServerResponseImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public AsyncHttpServerRequest getRequest() {
6666
@Override
6767
public void write(ByteBufferList bb) {
6868
// order is important here...
69-
assert !mEnded;
7069
// do the header write... this will call onWritable, which may be reentrant
7170
if (!headWritten)
7271
initFirstWrite();

AndroidAsync/src/com/koushikdutta/async/http/server/AsyncHttpServerRouter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ public void directory(String regex, final File directory) {
281281
}
282282

283283
public void directory(String regex, final File directory, final boolean list) {
284-
assert directory.isDirectory();
285284
addAction(AsyncHttpGet.METHOD, regex, new HttpServerRequestCallback() {
286285
@Override
287286
public void onRequest(AsyncHttpServerRequest request, final AsyncHttpServerResponse response) {

AndroidAsync/src/com/koushikdutta/async/http/server/BoundaryEmitter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ public String getBoundary() {
1919
}
2020

2121
public String getBoundaryStart() {
22-
assert boundary != null;
2322
return new String(boundary, 2, boundary.length - 2);
2423
}
2524

2625
public String getBoundaryEnd() {
27-
assert boundary != null;
2826
return getBoundaryStart() + "--\r\n";
2927
}
3028

@@ -160,7 +158,6 @@ else if (state == -4) {
160158
}
161159
}
162160
else {
163-
assert false;
164161
report(new MimeEncodingException("Invalid multipart/form-data. Unknown state?"));
165162
}
166163
}

AndroidAsync/src/com/koushikdutta/async/util/ArrayDeque.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ private void allocateElements(int numElements) {
121121
* when head and tail have wrapped around to become equal.
122122
*/
123123
private void doubleCapacity() {
124-
assert head == tail;
125124
int p = head;
126125
int n = elements.length;
127126
int r = n - p; // number of elements to the right of p
@@ -490,11 +489,6 @@ public E pop() {
490489
}
491490

492491
private void checkInvariants() {
493-
assert elements[tail] == null;
494-
assert head == tail ? elements[head] == null :
495-
(elements[head] != null &&
496-
elements[(tail - 1) & (elements.length - 1)] != null);
497-
assert elements[(head - 1) & (elements.length - 1)] == null;
498492
}
499493

500494
/**

0 commit comments

Comments
 (0)