diff options
Diffstat (limited to 'java/common/src')
3 files changed, 15 insertions, 2 deletions
diff --git a/java/common/src/main/java/org/apache/qpid/AMQPInvalidClassException.java b/java/common/src/main/java/org/apache/qpid/AMQPInvalidClassException.java index a0574efa72..ab5141be9d 100644 --- a/java/common/src/main/java/org/apache/qpid/AMQPInvalidClassException.java +++ b/java/common/src/main/java/org/apache/qpid/AMQPInvalidClassException.java @@ -32,6 +32,9 @@ package org.apache.qpid; */ public class AMQPInvalidClassException extends RuntimeException { + /** Error message text when trying to store an unsupported class or null object */ + public static final String INVALID_OBJECT_MSG = "Only Primitive objects allowed. Object is: "; + public AMQPInvalidClassException(String s) { super(s); diff --git a/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java b/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java index b268d03c3c..22205d49f8 100644 --- a/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java +++ b/java/common/src/main/java/org/apache/qpid/framing/FieldTable.java @@ -673,7 +673,7 @@ public class FieldTable return setBytes(string, (byte[]) object); } - throw new AMQPInvalidClassException("Only Primitives objects allowed Object is:" + (object == null ? "null" : object.getClass())); + throw new AMQPInvalidClassException(AMQPInvalidClassException.INVALID_OBJECT_MSG + (object == null ? "null" : object.getClass())); } public boolean isNullStringValue(String name) diff --git a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java index 179d371b1b..d4691ba097 100644 --- a/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java +++ b/java/common/src/test/java/org/apache/qpid/framing/PropertyFieldTableTest.java @@ -529,9 +529,19 @@ public class PropertyFieldTableTest extends TestCase catch (AMQPInvalidClassException aice) { assertEquals("Null values are not allowed to be set", - "Only Primitives objects allowed Object is:null", aice.getMessage()); + AMQPInvalidClassException.INVALID_OBJECT_MSG + "null", aice.getMessage()); } + try + { + table.setObject("Unsupported-object", new Exception()); + fail("Non primitive values are not allowed"); + } + catch (AMQPInvalidClassException aice) + { + assertEquals("Non primitive values are not allowed to be set", + AMQPInvalidClassException.INVALID_OBJECT_MSG + Exception.class, aice.getMessage()); + } Assert.assertEquals((Boolean) true, table.getBoolean("bool")); Assert.assertEquals((Byte) Byte.MAX_VALUE, table.getByte("byte")); |
