Skip to content

Commit

Permalink
Fixes #1090 - Improve IllegalStateExceptions error message.
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Nov 16, 2021
1 parent 2b18b9e commit 543fdf3
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public boolean matches(ChannelId channelId) {
return true;
}
default: {
throw new IllegalStateException();
throw new IllegalStateException("Invalid wild value " + _wild + " for " + this);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,11 @@ public void handshake(MessageListener callback) {

@Override
public void handshake(Map<String, Object> fields, MessageListener callback) {
if (getState() == State.DISCONNECTED) {
State state = getState();
if (state == State.DISCONNECTED) {
sessionState.submit(() -> sessionState.handshaking(fields, callback));
} else {
throw new IllegalStateException();
throw new IllegalStateException("Invalid state " + state);
}
}

Expand Down Expand Up @@ -1172,7 +1173,7 @@ private boolean isUpdateableTo(State newState) {
case TERMINATING:
return newState == DISCONNECTED;
default:
throw new IllegalStateException();
throw new IllegalStateException("Could not update state from " + this + " to " + newState);
}
}
}
Expand Down Expand Up @@ -1763,7 +1764,7 @@ public void handle(ClientTransport.FailureInfo failureInfo) {
break;
}
default: {
throw new IllegalStateException();
throw new IllegalStateException("Could not handle transport failure in state " + newState);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private void registerMessage(Message.Mutable message, TransportListener listener
Object existing = _exchanges.put(message.getId(), exchange);
// Paranoid check
if (existing != null) {
throw new IllegalStateException();
throw new IllegalStateException("Could not register exchange " + exchange + ", existing exchange is " + existing + " for message " + message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void run() {
promise.fail(failure.get());
return;
default:
throw new IllegalStateException();
throw new IllegalStateException("Could not run loop in state " + current);
}
}
}
Expand All @@ -224,7 +224,7 @@ public void proceed(R r) {
}
break;
default:
throw new IllegalStateException();
throw new IllegalStateException("Could not proceed loop in state " + current);
}
}
}
Expand All @@ -247,7 +247,7 @@ public void leave(R r) {
}
break;
default:
throw new IllegalStateException();
throw new IllegalStateException("Could not leave loop in state " + current);
}
}
}
Expand All @@ -270,7 +270,7 @@ public void fail(Throwable x) {
}
break;
default:
throw new IllegalStateException();
throw new IllegalStateException("Could not fail loop in state " + current);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,8 +785,8 @@ D get() {
try {
latch.await();
return result;
} catch (InterruptedException e) {
throw new IllegalStateException();
} catch (InterruptedException x) {
throw new IllegalStateException("Interrupted while waiting for deferred result", x);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public ServerSession getServerSession() {
@Override
public void handshake(Map<String, Object> template, ClientSession.MessageListener callback) {
if (_session != null) {
throw new IllegalStateException();
throw new IllegalStateException("Method handshake() invoke multiple times for local session " + this);
}

ServerSessionImpl session = new ServerSessionImpl(_bayeux, this, _idHint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean offer(T t) {
int capacity = elements.length;
int newCapacity = 2 * capacity;
if (newCapacity < 0) {
throw new IllegalStateException();
throw new IllegalStateException("Could not double up capacity " + capacity);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ public void onWritePossible() throws IOException {
}

while (true) {
switch (state) {
State current = state;
switch (current) {
case BEGIN: {
state = State.HANDSHAKE;
if (!writeBegin(output)) {
Expand Down Expand Up @@ -362,7 +363,7 @@ public void onWritePossible() throws IOException {
return;
}
default: {
throw new IllegalStateException();
throw new IllegalStateException("Could not write in state " + current);
}
}
}
Expand Down

0 comments on commit 543fdf3

Please sign in to comment.