From e164a5b3b8874b9db45c556147fd6f64b4a4e63e Mon Sep 17 00:00:00 2001 From: gtully Date: Tue, 25 Jan 2022 13:43:50 +0000 Subject: [PATCH] ARTEMIS-3627 - fix regression in CriticalCrashTest - statically configured converters were being lost on new custom bean utils --- .../activemq/artemis/utils/uri/BeanSupport.java | 11 ++++++++++- .../artemis/core/config/impl/ConfigurationImpl.java | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/BeanSupport.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/BeanSupport.java index cbacf01009..ef4b39acfa 100644 --- a/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/BeanSupport.java +++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/utils/uri/BeanSupport.java @@ -35,18 +35,27 @@ import org.apache.commons.beanutils.Converter; public class BeanSupport { private static final BeanUtilsBean beanUtils = new BeanUtilsBean(); + private static final Map customConverters = new HashMap<>(); static { - // This is to customize the BeanUtils to use Fluent Proeprties as well + // This is to customize the BeanUtils to use Fluent Properties as well beanUtils.getPropertyUtils().addBeanIntrospector(new FluentPropertyBeanIntrospectorWithIgnores()); } public static void registerConverter(Converter converter, Class type) { synchronized (beanUtils) { beanUtils.getConvertUtils().register(converter, type); + customConverters.put(converter, type); } } + public static void customise(BeanUtilsBean bean) { + synchronized (beanUtils) { + customConverters.forEach((key, value) -> bean.getConvertUtils().register(key, value)); + } + bean.getPropertyUtils().addBeanIntrospector(new FluentPropertyBeanIntrospectorWithIgnores()); + } + public static

P copyData(P source, P target) throws Exception { synchronized (beanUtils) { beanUtils.copyProperties(source, target); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java index 3c13f7014a..84144611b5 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java @@ -99,7 +99,7 @@ import org.apache.activemq.artemis.core.settings.impl.ResourceLimitSettings; import org.apache.activemq.artemis.utils.Env; import org.apache.activemq.artemis.utils.ObjectInputStreamWithClassLoader; import org.apache.activemq.artemis.utils.critical.CriticalAnalyzerPolicy; -import org.apache.activemq.artemis.utils.uri.FluentPropertyBeanIntrospectorWithIgnores; +import org.apache.activemq.artemis.utils.uri.BeanSupport; import org.apache.commons.beanutils.BeanUtilsBean; import org.apache.commons.beanutils.ConvertUtilsBean; import org.apache.commons.beanutils.Converter; @@ -504,7 +504,7 @@ public class ConfigurationImpl implements Configuration, Serializable { return (T) SimpleString.toSimpleString(value.toString()); } }, SimpleString.class); - beanUtils.getPropertyUtils().addBeanIntrospector(new FluentPropertyBeanIntrospectorWithIgnores()); + BeanSupport.customise(beanUtils); beanUtils.populate(this, beanProperties); }