Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Thread safety problem #233

Open
shouyuwang opened this issue Mar 14, 2022 · 1 comment
Open

bug: Thread safety problem #233

shouyuwang opened this issue Mar 14, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@shouyuwang
Copy link
Contributor

shouyuwang commented Mar 14, 2022

#225 This solution will lead to thread safety problem.

@Override
protected void doBind(Object bean, String beanName, String dataId, String groupId,
	String configType, NacosConfigurationProperties properties, String content,
	ConfigService configService) {
  synchronized (this) {
	  String name = "nacos-bootstrap-" + beanName;
	  NacosPropertySource propertySource = new NacosPropertySource(dataId, groupId, name, content, configType);
	  environment.getPropertySources().addLast(propertySource);
	  ObjectUtils.cleanMapOrCollectionField(bean);
	  Binder binder = Binder.get(environment);
	  ResolvableType type = getBeanType(bean, beanName);
	  Bindable<?> target = Bindable.of(type).withExistingValue(bean);
	  binder.bind(properties.prefix(), target);
	  publishBoundEvent(bean, beanName, dataId, groupId, properties, content, configService);
	  publishMetadataEvent(bean, beanName, dataId, groupId, properties);
	  environment.getPropertySources().remove(name);
  }
}

ObjectUtils.cleanMapOrCollectionField(bean);will make the type of Map or Collectiion field null,when bean uses the field will throw NPE
change-file
thread-safe

@hujun-w-2 hujun-w-2 added the bug Something isn't working label May 28, 2022
@chenhao26-nineteen
Copy link
Contributor

#225 This solution will lead to thread safety problem.

@Override
protected void doBind(Object bean, String beanName, String dataId, String groupId,
	String configType, NacosConfigurationProperties properties, String content,
	ConfigService configService) {
  synchronized (this) {
	  String name = "nacos-bootstrap-" + beanName;
	  NacosPropertySource propertySource = new NacosPropertySource(dataId, groupId, name, content, configType);
	  environment.getPropertySources().addLast(propertySource);
	  ObjectUtils.cleanMapOrCollectionField(bean);
	  Binder binder = Binder.get(environment);
	  ResolvableType type = getBeanType(bean, beanName);
	  Bindable<?> target = Bindable.of(type).withExistingValue(bean);
	  binder.bind(properties.prefix(), target);
	  publishBoundEvent(bean, beanName, dataId, groupId, properties, content, configService);
	  publishMetadataEvent(bean, beanName, dataId, groupId, properties);
	  environment.getPropertySources().remove(name);
  }
}

ObjectUtils.cleanMapOrCollectionField(bean);will make the type of Map or Collectiion field null,when bean uses the field will throw NPE change-file thread-safe

@ i will solved it@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants