Skip to content

Commit

Permalink
Throw IllegalArgumentError early if queue name length exceeds 255 chars
Browse files Browse the repository at this point in the history
Fixes #72.
  • Loading branch information
michaelklishin committed Jun 28, 2015
1 parent 87bb1af commit 57f1ead
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/com/rabbitmq/client/impl/ChannelN.java
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ public Queue.DeclareOk queueDeclare(String queue, boolean durable, boolean exclu
boolean autoDelete, Map<String, Object> arguments)
throws IOException
{
validateQueueNameLength(queue);
return (Queue.DeclareOk)
exnWrappingRpc(new Queue.Declare.Builder()
.queue(queue)
Expand All @@ -864,6 +865,7 @@ public void queueDeclareNoWait(String queue,
boolean exclusive,
boolean autoDelete,
Map<String, Object> arguments) throws IOException {
validateQueueNameLength(queue);
transmit(new AMQCommand(new Queue.Declare.Builder()
.queue(queue)
.durable(durable)
Expand All @@ -879,6 +881,7 @@ public void queueDeclareNoWait(String queue,
public Queue.DeclareOk queueDeclarePassive(String queue)
throws IOException
{
validateQueueNameLength(queue);
return (Queue.DeclareOk)
exnWrappingRpc(new Queue.Declare.Builder()
.queue(queue)
Expand All @@ -893,6 +896,7 @@ public Queue.DeclareOk queueDeclarePassive(String queue)
public Queue.DeleteOk queueDelete(String queue, boolean ifUnused, boolean ifEmpty)
throws IOException
{
validateQueueNameLength(queue);
return (Queue.DeleteOk)
exnWrappingRpc(new Queue.Delete.Builder()
.queue(queue)
Expand All @@ -904,6 +908,7 @@ public Queue.DeleteOk queueDelete(String queue, boolean ifUnused, boolean ifEmpt

@Override
public void queueDeleteNoWait(String queue, boolean ifUnused, boolean ifEmpty) throws IOException {
validateQueueNameLength(queue);
transmit(new AMQCommand(new Queue.Delete.Builder()
.queue(queue)
.ifUnused(ifUnused)
Expand All @@ -924,6 +929,7 @@ public Queue.BindOk queueBind(String queue, String exchange,
String routingKey, Map<String, Object> arguments)
throws IOException
{
validateQueueNameLength(queue);
return (Queue.BindOk)
exnWrappingRpc(new Queue.Bind.Builder()
.queue(queue)
Expand All @@ -938,7 +944,6 @@ public Queue.BindOk queueBind(String queue, String exchange,
public Queue.BindOk queueBind(String queue, String exchange, String routingKey)
throws IOException
{

return queueBind(queue, exchange, routingKey, null);
}

Expand All @@ -947,6 +952,7 @@ public void queueBindNoWait(String queue,
String exchange,
String routingKey,
Map<String, Object> arguments) throws IOException {
validateQueueNameLength(queue);
transmit(new AMQCommand(new Queue.Bind.Builder()
.queue(queue)
.exchange(exchange)
Expand All @@ -960,6 +966,7 @@ public Queue.UnbindOk queueUnbind(String queue, String exchange, String routingK
Map<String, Object> arguments)
throws IOException
{
validateQueueNameLength(queue);
return (Queue.UnbindOk)
exnWrappingRpc(new Queue.Unbind.Builder()
.queue(queue)
Expand All @@ -974,6 +981,7 @@ public Queue.UnbindOk queueUnbind(String queue, String exchange, String routingK
public Queue.PurgeOk queuePurge(String queue)
throws IOException
{
validateQueueNameLength(queue);
return (Queue.PurgeOk)
exnWrappingRpc(new Queue.Purge.Builder()
.queue(queue)
Expand All @@ -992,6 +1000,7 @@ public Queue.UnbindOk queueUnbind(String queue, String exchange, String routingK
public GetResponse basicGet(String queue, boolean autoAck)
throws IOException
{
validateQueueNameLength(queue);
AMQCommand replyCommand = exnWrappingRpc(new Basic.Get.Builder()
.queue(queue)
.noAck(autoAck)
Expand Down Expand Up @@ -1218,4 +1227,10 @@ private void handleAckNack(long seqNo, boolean multiple, boolean nack) {
unconfirmedSet.notifyAll();
}
}

private void validateQueueNameLength(String queue) {
if(queue.length() > 255) {
throw new IllegalArgumentException("queue name must be no more than 255 characters long");
}
}
}
10 changes: 10 additions & 0 deletions test/src/com/rabbitmq/client/test/functional/QueueLifecycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,14 @@ public void testArgumentArrays() throws IOException {
channel.queueDeclare(queueName, true, true, false, args);
verifyQueue(queueName, true, true, false, args);
}

public void testQueueNamesLongerThan255Characters() throws IOException {
String q = new String(new byte[300]).replace('\u0000', 'x');
try {
channel.queueDeclare(q, false, false, false, null);
fail("queueDeclare should have failed");
} catch (IllegalArgumentException ignored) {
// expected
}
}
}

0 comments on commit 57f1ead

Please sign in to comment.