Skip to content

Commit ea75642

Browse files
Merge pull request #245 from rabbitmq/rabbitmq-java-client-239
Replace AssertionErrors with RuntimeExceptions
2 parents c6f5279 + 1cbadde commit ea75642

File tree

5 files changed

+9
-22
lines changed

5 files changed

+9
-22
lines changed

src/main/java/com/rabbitmq/client/impl/AMQCommand.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ private static void checkEmptyFrameSize() {
173173
try {
174174
f.writeTo(new DataOutputStream(s));
175175
} catch (IOException ioe) {
176-
throw new AssertionError("IOException while checking EMPTY_FRAME_SIZE");
176+
throw new IllegalStateException("IOException while checking EMPTY_FRAME_SIZE");
177177
}
178178
int actualLength = s.toByteArray().length;
179179
if (EMPTY_FRAME_SIZE != actualLength) {
180-
throw new AssertionError("Internal error: expected EMPTY_FRAME_SIZE("
180+
throw new IllegalStateException("Internal error: expected EMPTY_FRAME_SIZE("
181181
+ EMPTY_FRAME_SIZE
182182
+ ") is not equal to computed value: " + actualLength);
183183
}

src/main/java/com/rabbitmq/client/impl/CommandAssembler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public synchronized boolean handleFrame(Frame f) throws IOException
159159
case EXPECTING_CONTENT_BODY: consumeBodyFrame(f); break;
160160

161161
default:
162-
throw new AssertionError("Bad Command State " + this.state);
162+
throw new IllegalStateException("Bad Command State " + this.state);
163163
}
164164
return isComplete();
165165
}

src/main/java/com/rabbitmq/client/impl/nio/NioLoop.java

+1-14
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ public void run() {
7878
state.getConnection().handleHeartbeatFailure();
7979
} catch (Exception e) {
8080
LOGGER.warn("Error after heartbeat failure of connection {}", state.getConnection());
81-
} catch (AssertionError e) {
82-
// see https://github.com/rabbitmq/rabbitmq-java-client/issues/237
83-
LOGGER.warn("Assertion error after heartbeat failure of connection {}", state.getConnection());
8481
} finally {
8582
selectionKey.cancel();
8683
}
@@ -276,17 +273,7 @@ protected void dispatchIoErrorToConnection(final SocketChannelFrameHandlerState
276273
// In case of recovery after the shutdown,
277274
// the new connection shouldn't be initialized in
278275
// the NIO thread, to avoid a deadlock.
279-
Runnable shutdown = new Runnable() {
280-
281-
@Override
282-
public void run() {
283-
try {
284-
state.getConnection().handleIoError(ex);
285-
} catch(AssertionError e) {
286-
LOGGER.warn("Assertion error during error dispatching to connection: " + e.getMessage());
287-
}
288-
}
289-
};
276+
Runnable shutdown = () -> state.getConnection().handleIoError(ex);
290277
if (executorService() == null) {
291278
String name = "rabbitmq-connection-shutdown-" + state.getConnection();
292279
Thread shutdownThread = Environment.newThread(threadFactory(), shutdown, name);

src/main/java/com/rabbitmq/utility/BlockingCell.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public synchronized T get(long timeout) throws InterruptedException, TimeoutExce
6464
if (timeout == INFINITY) return get();
6565

6666
if (timeout < 0) {
67-
throw new AssertionError("Timeout cannot be less than zero");
67+
throw new IllegalArgumentException("Timeout cannot be less than zero");
6868
}
6969

7070
long now = System.nanoTime() / NANOS_IN_MILLI;
@@ -133,12 +133,12 @@ public synchronized T uninterruptibleGet(int timeout) throws TimeoutException {
133133
}
134134

135135
/**
136-
* Store a value in this BlockingCell, throwing AssertionError if the cell already has a value.
136+
* Store a value in this BlockingCell, throwing {@link IllegalStateException} if the cell already has a value.
137137
* @param newValue the new value to store
138138
*/
139139
public synchronized void set(T newValue) {
140140
if (_filled) {
141-
throw new AssertionError("BlockingCell can only be set once");
141+
throw new IllegalStateException("BlockingCell can only be set once");
142142
}
143143
_value = newValue;
144144
_filled = true;

src/test/java/com/rabbitmq/client/test/BlockingCellTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public void doubleSet() throws InterruptedException
3535
assertEquals("one", cell.get());
3636
try {
3737
cell.set("two");
38-
} catch (AssertionError ae) {
38+
} catch (IllegalStateException ae) {
3939
return;
4040
}
41-
fail("Expected AssertionError");
41+
fail("Expected IllegalStateException");
4242
}
4343

4444
@Test public void multiGet()

0 commit comments

Comments
 (0)