diff --git a/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java b/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java index a523416446..609b780072 100755 --- a/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java +++ b/activemq-core/src/main/java/org/apache/activemq/openwire/OpenWireFormat.java @@ -59,8 +59,8 @@ public final class OpenWireFormat implements WireFormat { private short nextMarshallCacheIndex; private short nextMarshallCacheEvictionIndex; private Map marshallCacheMap = new HashMap(); - private DataStructure marshallCache[] = new DataStructure[MARSHAL_CACHE_SIZE]; - private DataStructure unmarshallCache[] = new DataStructure[MARSHAL_CACHE_SIZE]; + private DataStructure marshallCache[] = null; + private DataStructure unmarshallCache[] = null; private DataByteArrayOutputStream bytesOut = new DataByteArrayOutputStream(); private DataByteArrayInputStream bytesIn = new DataByteArrayInputStream(); private WireFormatInfo preferedWireFormatInfo; @@ -572,6 +572,10 @@ public final class OpenWireFormat implements WireFormat { } public void setCacheEnabled(boolean cacheEnabled) { + if(cacheEnabled){ + marshallCache = new DataStructure[MARSHAL_CACHE_SIZE]; + unmarshallCache = new DataStructure[MARSHAL_CACHE_SIZE]; + } this.cacheEnabled = cacheEnabled; }