Skip to content

Commit cb23b73

Browse files
author
David R. MacIver
committed
Rather than return null when we request a channel that doesn't exist, throw an exception containing a vaguely informative message and the relevant channel number. This means that at least when this bug occurs you'll be able to get a better idea of where it's occurring.
Arguably this is an API change, which might be problematic for a 1.7.1 release, but it's an API change to code which is really internal, so I don't think it's an issue.
1 parent d2c4994 commit cb23b73

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

src/com/rabbitmq/client/impl/AMQConnection.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,9 +428,9 @@ private class MainLoop extends Thread {
428428
// for non-zero channels (and any inbound commands on
429429
// channel zero that aren't Connection.CloseOk) must
430430
// be discarded.
431-
ChannelN channel = _channelManager.getChannel(frame.channel);
432-
// FIXME: catch NullPointerException and throw more informative one?
433-
channel.handleFrame(frame);
431+
_channelManager
432+
.getChannel(frame.channel)
433+
.handleFrame(frame);
434434
}
435435
}
436436
}

src/com/rabbitmq/client/impl/ChannelManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ public synchronized void setChannelMax(int value) {
6262
* Public API - Looks up an existing channel associated with this connection.
6363
* @param channelNumber the number of the required channel
6464
* @return the relevant channel descriptor
65+
* @throws UnknownChannelException if there is no Channel associated with the
66+
* required channel number.
6567
*/
6668
public ChannelN getChannel(int channelNumber) {
67-
return _channelMap.get(channelNumber);
69+
ChannelN result = _channelMap.get(channelNumber);
70+
if(result == null) throw new UnknownChannelException(channelNumber);
71+
return result;
6872
}
6973

7074
public void handleSignal(ShutdownSignalException signal) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// The contents of this file are subject to the Mozilla Public License
2+
// Version 1.1 (the "License"); you may not use this file except in
3+
// compliance with the License. You may obtain a copy of the License at
4+
// http://www.mozilla.org/MPL/
5+
//
6+
// Software distributed under the License is distributed on an "AS IS"
7+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
8+
// License for the specific language governing rights and limitations
9+
// under the License.
10+
//
11+
// The Original Code is RabbitMQ.
12+
//
13+
// The Initial Developers of the Original Code are LShift Ltd,
14+
// Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
15+
//
16+
// Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
17+
// Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
18+
// are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
19+
// Technologies LLC, and Rabbit Technologies Ltd.
20+
//
21+
// Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
22+
// Ltd. Portions created by Cohesive Financial Technologies LLC are
23+
// Copyright (C) 2007-2009 Cohesive Financial Technologies
24+
// LLC. Portions created by Rabbit Technologies Ltd are Copyright
25+
// (C) 2007-2009 Rabbit Technologies Ltd.
26+
//
27+
// All Rights Reserved.
28+
//
29+
// Contributor(s): ______________________________________.
30+
//
31+
32+
package com.rabbitmq.client.impl;
33+
34+
class UnknownChannelException extends RuntimeException{
35+
private final int channelNumber;
36+
37+
public UnknownChannelException(int channelNumber){
38+
super("Unknown channel number " + channelNumber + " for this this connection");
39+
this.channelNumber = channelNumber;
40+
}
41+
42+
public int getChannelNumber(){
43+
return channelNumber;
44+
}
45+
}

0 commit comments

Comments
 (0)