format AffectedConfigurationPropertiesRebinder with checkstyle

pull/699/head
dongyinuo 3 years ago
parent 88c7f47fb6
commit cd15ecf8b9

@ -29,6 +29,7 @@ import java.util.concurrent.ConcurrentHashMap;
import com.tencent.polaris.api.utils.MapUtils; import com.tencent.polaris.api.utils.MapUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.boot.context.properties.ConfigurationPropertiesBean; import org.springframework.boot.context.properties.ConfigurationPropertiesBean;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
@ -94,14 +95,14 @@ public class AffectedConfigurationPropertiesRebinder extends ConfigurationProper
}); });
} }
private void rebindDefaultValue(String beanName, String key){ private void rebindDefaultValue(String beanName, String key) {
String changeValue = applicationContext.getEnvironment().getProperty(key); String changeValue = applicationContext.getEnvironment().getProperty(key);
if (StringUtils.hasLength(changeValue)){ if (StringUtils.hasLength(changeValue)) {
return; return;
} }
Map<String, Object> defaultValues = propertiesBeanDefaultValues.get(beanName); Map<String, Object> defaultValues = propertiesBeanDefaultValues.get(beanName);
if (MapUtils.isEmpty(defaultValues)){ if (MapUtils.isEmpty(defaultValues)) {
return; return;
} }
try { try {
@ -112,17 +113,18 @@ public class AffectedConfigurationPropertiesRebinder extends ConfigurationProper
assert field != null; assert field != null;
field.setAccessible(true); field.setAccessible(true);
field.set(bean, defaultValues.get(fieldName)); field.set(bean, defaultValues.get(fieldName));
} catch (Exception e){ }
catch (Exception e) {
LOGGER.error("[SCT Config] rebind default value error, bean = {}, key = {}", beanName, key); LOGGER.error("[SCT Config] rebind default value error, bean = {}, key = {}", beanName, key);
} }
} }
private void initPropertiesBeanDefaultValues(Map<String, ConfigurationPropertiesBean> propertiesBeans){ private void initPropertiesBeanDefaultValues(Map<String, ConfigurationPropertiesBean> propertiesBeans) {
if (MapUtils.isEmpty(propertiesBeans)){ if (MapUtils.isEmpty(propertiesBeans)) {
return; return;
} }
for (ConfigurationPropertiesBean propertiesBean : propertiesBeans.values()){ for (ConfigurationPropertiesBean propertiesBean : propertiesBeans.values()) {
Map<String, Object> defaultValues = new HashMap<>(); Map<String, Object> defaultValues = new HashMap<>();
try { try {
Object instance = propertiesBean.getInstance().getClass().getDeclaredConstructor((Class<?>[]) null).newInstance(); Object instance = propertiesBean.getInstance().getClass().getDeclaredConstructor((Class<?>[]) null).newInstance();
@ -130,12 +132,16 @@ public class AffectedConfigurationPropertiesRebinder extends ConfigurationProper
try { try {
field.setAccessible(true); field.setAccessible(true);
defaultValues.put(field.getName(), field.get(instance)); defaultValues.put(field.getName(), field.get(instance));
} catch (Exception ignored){} }
catch (Exception ignored) {
}
}, field -> { }, field -> {
int modifiers = field.getModifiers(); int modifiers = field.getModifiers();
return !Modifier.isFinal(modifiers) && !Modifier.isStatic(modifiers); return !Modifier.isFinal(modifiers) && !Modifier.isStatic(modifiers);
}); });
}catch (Exception ignored){} }
catch (Exception ignored) {
}
propertiesBeanDefaultValues.put(propertiesBean.getName(), defaultValues); propertiesBeanDefaultValues.put(propertiesBean.getName(), defaultValues);
} }

Loading…
Cancel
Save