ARTEMIS-3627 - fix regression in CriticalCrashTest - statically configured converters were being lost on new custom bean utils

This commit is contained in:
gtully 2022-01-25 13:43:50 +00:00 committed by Gary Tully
parent 90535a2401
commit e164a5b3b8
2 changed files with 12 additions and 3 deletions

View File

@ -35,18 +35,27 @@ import org.apache.commons.beanutils.Converter;
public class BeanSupport {
private static final BeanUtilsBean beanUtils = new BeanUtilsBean();
private static final Map<Converter, Class> 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> P copyData(P source, P target) throws Exception {
synchronized (beanUtils) {
beanUtils.copyProperties(source, target);

View File

@ -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);
}