diff --git a/activemq-client/pom.xml b/activemq-client/pom.xml
index b71f9632d9..2dd9df097f 100644
--- a/activemq-client/pom.xml
+++ b/activemq-client/pom.xml
@@ -268,6 +268,17 @@
+
+
+ maven-jar-plugin
+
+
+
+ test-jar
+
+
+
+
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireUtil.java b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireUtil.java
new file mode 100644
index 0000000000..f52e6c3e08
--- /dev/null
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/OpenWireUtil.java
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire;
+
+public class OpenWireUtil {
+
+ /**
+ * Verify that the provided class extends {@link Throwable} and throw an
+ * {@link IllegalArgumentException} if it does not.
+ *
+ * @param clazz
+ */
+ public static void validateIsThrowable(Class> clazz) {
+ if (!Throwable.class.isAssignableFrom(clazz)) {
+ throw new IllegalArgumentException("Class " + clazz + " is not assignable to Throwable");
+ }
+ }
+}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java
index 9e00ae3eb9..cd22f66634 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v1/BaseDataStreamMarshaller.java
@@ -25,6 +25,7 @@ import org.apache.activemq.command.DataStructure;
import org.apache.activemq.openwire.BooleanStream;
import org.apache.activemq.openwire.DataStreamMarshaller;
import org.apache.activemq.openwire.OpenWireFormat;
+import org.apache.activemq.openwire.OpenWireUtil;
import org.apache.activemq.util.ByteSequence;
public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
@@ -229,8 +230,11 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
private Throwable createThrowable(String className, String message) {
try {
Class clazz = Class.forName(className, false, BaseDataStreamMarshaller.class.getClassLoader());
+ OpenWireUtil.validateIsThrowable(clazz);
Constructor constructor = clazz.getConstructor(new Class[] {String.class});
return (Throwable)constructor.newInstance(new Object[] {message});
+ } catch (IllegalArgumentException e) {
+ return e;
} catch (Throwable e) {
return new Throwable(className + ": " + message);
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshaller.java
index 7e871f7ea9..7bdfbb8164 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v10/BaseDataStreamMarshaller.java
@@ -24,6 +24,7 @@ import org.apache.activemq.command.DataStructure;
import org.apache.activemq.openwire.BooleanStream;
import org.apache.activemq.openwire.DataStreamMarshaller;
import org.apache.activemq.openwire.OpenWireFormat;
+import org.apache.activemq.openwire.OpenWireUtil;
import org.apache.activemq.util.ByteSequence;
public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
@@ -228,8 +229,11 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
private Throwable createThrowable(String className, String message) {
try {
Class clazz = Class.forName(className, false, BaseDataStreamMarshaller.class.getClassLoader());
+ OpenWireUtil.validateIsThrowable(clazz);
Constructor constructor = clazz.getConstructor(new Class[] {String.class});
return (Throwable)constructor.newInstance(new Object[] {message});
+ } catch (IllegalArgumentException e) {
+ return e;
} catch (Throwable e) {
return new Throwable(className + ": " + message);
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/BaseDataStreamMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/BaseDataStreamMarshaller.java
index 99eb810673..67ef744f1a 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v11/BaseDataStreamMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v11/BaseDataStreamMarshaller.java
@@ -24,6 +24,7 @@ import org.apache.activemq.command.DataStructure;
import org.apache.activemq.openwire.BooleanStream;
import org.apache.activemq.openwire.DataStreamMarshaller;
import org.apache.activemq.openwire.OpenWireFormat;
+import org.apache.activemq.openwire.OpenWireUtil;
import org.apache.activemq.util.ByteSequence;
public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
@@ -227,8 +228,11 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
private Throwable createThrowable(String className, String message) {
try {
Class clazz = Class.forName(className, false, BaseDataStreamMarshaller.class.getClassLoader());
+ OpenWireUtil.validateIsThrowable(clazz);
Constructor constructor = clazz.getConstructor(new Class[] {String.class});
return (Throwable)constructor.newInstance(new Object[] {message});
+ } catch (IllegalArgumentException e) {
+ return e;
} catch (Throwable e) {
return new Throwable(className + ": " + message);
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/BaseDataStreamMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/BaseDataStreamMarshaller.java
index 50dab35f4e..fe43d3cbdf 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v12/BaseDataStreamMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v12/BaseDataStreamMarshaller.java
@@ -24,6 +24,7 @@ import org.apache.activemq.command.DataStructure;
import org.apache.activemq.openwire.BooleanStream;
import org.apache.activemq.openwire.DataStreamMarshaller;
import org.apache.activemq.openwire.OpenWireFormat;
+import org.apache.activemq.openwire.OpenWireUtil;
import org.apache.activemq.util.ByteSequence;
public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
@@ -227,8 +228,11 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
private Throwable createThrowable(String className, String message) {
try {
Class clazz = Class.forName(className, false, BaseDataStreamMarshaller.class.getClassLoader());
+ OpenWireUtil.validateIsThrowable(clazz);
Constructor constructor = clazz.getConstructor(new Class[] {String.class});
return (Throwable)constructor.newInstance(new Object[] {message});
+ } catch (IllegalArgumentException e) {
+ return e;
} catch (Throwable e) {
return new Throwable(className + ": " + message);
}
diff --git a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/BaseDataStreamMarshaller.java b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/BaseDataStreamMarshaller.java
index 07058a586f..13dfae871b 100644
--- a/activemq-client/src/main/java/org/apache/activemq/openwire/v9/BaseDataStreamMarshaller.java
+++ b/activemq-client/src/main/java/org/apache/activemq/openwire/v9/BaseDataStreamMarshaller.java
@@ -24,6 +24,7 @@ import org.apache.activemq.command.DataStructure;
import org.apache.activemq.openwire.BooleanStream;
import org.apache.activemq.openwire.DataStreamMarshaller;
import org.apache.activemq.openwire.OpenWireFormat;
+import org.apache.activemq.openwire.OpenWireUtil;
import org.apache.activemq.util.ByteSequence;
public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
@@ -227,8 +228,11 @@ public abstract class BaseDataStreamMarshaller implements DataStreamMarshaller {
private Throwable createThrowable(String className, String message) {
try {
Class clazz = Class.forName(className, false, BaseDataStreamMarshaller.class.getClassLoader());
+ OpenWireUtil.validateIsThrowable(clazz);
Constructor constructor = clazz.getConstructor(new Class[] {String.class});
return (Throwable)constructor.newInstance(new Object[] {message});
+ } catch (IllegalArgumentException e) {
+ return e;
} catch (Throwable e) {
return new Throwable(className + ": " + message);
}
diff --git a/activemq-client/src/test/java/org/apache/activemq/openwire/OpenWireValidationTest.java b/activemq-client/src/test/java/org/apache/activemq/openwire/OpenWireValidationTest.java
new file mode 100644
index 0000000000..a7a6a4f7ce
--- /dev/null
+++ b/activemq-client/src/test/java/org/apache/activemq/openwire/OpenWireValidationTest.java
@@ -0,0 +1,166 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.openwire;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.apache.activemq.command.CommandTypes;
+import org.apache.activemq.command.ExceptionResponse;
+import org.apache.activemq.util.ByteSequence;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Test that Openwire marshalling will validate Throwable types during
+ * unmarshalling commands that contain a Throwable
+ */
+@RunWith(Parameterized.class)
+public class OpenWireValidationTest {
+
+ protected final int version;
+
+ @Parameters(name = "version={0}")
+ public static Collection