diff --git a/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java b/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java index eae6f0aff8..99b978005f 100644 --- a/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java +++ b/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.console.filter; +import java.lang.reflect.Array; import java.lang.reflect.Method; import java.util.Enumeration; import java.util.HashMap; @@ -331,10 +332,32 @@ public class MapTransformFilter extends ResultTransformFilter { return props; } - protected String getDisplayString(Object obj) { - if (obj != null && obj.getClass().isArray()) { - obj = Arrays.asList((Object[]) obj); - } + @SuppressWarnings("unchecked") + protected String getDisplayString(Object obj) { + if (null == obj) + return "null"; + + if (obj != null && obj.getClass().isArray()) { + Class type = obj.getClass().getComponentType(); + if (!type.isPrimitive()) { + obj = Arrays.asList((Object[]) obj); + } else { + // for primitives, we can't use Arrays.toString(), so we have to roll something similar. + int len = Array.getLength(obj); + if (0 == len) + return "[]"; + StringBuilder bldr = new StringBuilder(); + bldr.append("["); + for (int i = 0; i <= len; i++) { + bldr.append(Array.get(obj, i)); + if (i + 1 >= len) + return bldr.append("]").toString(); + bldr.append(","); + } + } + + } + return obj.toString(); } } diff --git a/activemq-console/src/test/java/org/apache/activemq/console/filter/TestMapTransformFilter.java b/activemq-console/src/test/java/org/apache/activemq/console/filter/TestMapTransformFilter.java new file mode 100644 index 0000000000..6c6818c1dd --- /dev/null +++ b/activemq-console/src/test/java/org/apache/activemq/console/filter/TestMapTransformFilter.java @@ -0,0 +1,58 @@ +/** + * 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.console.filter; + +import junit.framework.TestCase; + +public class TestMapTransformFilter extends TestCase { + + private static final Object[][] testData = new Object[][] { + { new byte[] { 1, 2, 3, 4 } }, + { new int[] { 1, 2, 3, 4 } }, + { new long[] { 1, 2, 3, 4 } }, + { new double[] { 1, 2, 3, 4 } }, + { new float[] { 1, 2, 3, 4 } }, + { new char[] { '1', '2', '3', '4' } }, + + { new Integer[] { 1, 2, 3, 4 } }, + { new Byte[] { 1, 2, 3, 4 } }, + { new Long[] { 1L, 2L, 3L, 4L } }, + { new Double[] { 1d, 2d, 3d, 4d } }, + { new Float[] { 1f, 2f, 3f, 4f } }, + { new Character[] { '1', '2', '3', '4' } }, + + { new String[] { "abc", "def" } }, + { new int[] { 1, } }, + { new int[] {,} }, + { "abc"}, + {(byte)1}, + { (int)1 }, + { (long)1 }, + { (double)1d }, + { (float)1f }, + { (char)'1' }, + + }; + + public void testFetDisplayString() { + MapTransformFilter filter = new MapTransformFilter(null); + for (Object[] objectArray : testData) { + filter.getDisplayString(objectArray[0]); + } + } + +}