Skip to content

Commit d0ce403

Browse files
committed
Refine asserts
1 parent 991f429 commit d0ce403

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Android Asynchronous Http Client
3+
Copyright (c) 2011 James Smith <[email protected]>
4+
http://loopj.com
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package com.loopj.android.http;
20+
21+
/**
22+
* Internal class, used to make some asserts, throw AssertError if asserts fail.
23+
*/
24+
class AssertUtils {
25+
26+
private AssertUtils() {
27+
}
28+
29+
public static void asserts(final boolean expression, final String failedMessage) {
30+
if (!expression) {
31+
throw new AssertionError(failedMessage);
32+
}
33+
}
34+
}

library/src/main/java/com/loopj/android/http/AsyncHttpResponseHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ protected void sendMessage(Message msg) {
357357
if (getUseSynchronousMode() || handler == null) {
358358
handleMessage(msg);
359359
} else if (!Thread.currentThread().isInterrupted()) { // do not send messages if request has been cancelled
360-
assert handler != null;
360+
AssertUtils.asserts(handler != null, "handler should not be null!");
361361
handler.sendMessage(msg);
362362
}
363363
}
@@ -374,7 +374,7 @@ protected void postRunnable(Runnable runnable) {
374374
runnable.run();
375375
} else {
376376
// Otherwise, run on provided handler
377-
assert handler != null;
377+
AssertUtils.asserts(handler != null, "handler should not be null!");
378378
handler.post(runnable);
379379
}
380380
}

0 commit comments

Comments
 (0)