mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-11-01 03:25:35 +08:00 
			
		
		
		
	🎨 代码优化,防止出现空指针异常报错
Co-authored-by: sunhui <10151317@qq.com>
This commit is contained in:
		| @ -377,7 +377,12 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH | |||||||
|   @Override |   @Override | ||||||
|   @JsonDeserialize |   @JsonDeserialize | ||||||
|   public void setMultiConfigs(Map<String, WxMaConfig> configs, String defaultMiniappId) { |   public void setMultiConfigs(Map<String, WxMaConfig> configs, String defaultMiniappId) { | ||||||
|  |     // 防止覆盖配置 | ||||||
|  |     if(this.configMap != null) { | ||||||
|  |       this.configMap.putAll(configs); | ||||||
|  |     } else { | ||||||
|       this.configMap = Maps.newHashMap(configs); |       this.configMap = Maps.newHashMap(configs); | ||||||
|  |     } | ||||||
|     WxMaConfigHolder.set(defaultMiniappId); |     WxMaConfigHolder.set(defaultMiniappId); | ||||||
|     this.initHttp(); |     this.initHttp(); | ||||||
|   } |   } | ||||||
| @ -385,7 +390,11 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH | |||||||
|   @Override |   @Override | ||||||
|   public void addConfig(String miniappId, WxMaConfig configStorages) { |   public void addConfig(String miniappId, WxMaConfig configStorages) { | ||||||
|     synchronized (this) { |     synchronized (this) { | ||||||
|       if (this.configMap == null) { |       /* | ||||||
|  |        * 因为commit f74b00cf 默认初始化了configMap,导致使用此方法无法进入if从而触发initHttp(), | ||||||
|  |        * 就会出现HttpClient报NullPointException | ||||||
|  |        */ | ||||||
|  |       if (this.configMap == null || this.configMap.isEmpty()) { | ||||||
|         this.setWxMaConfig(configStorages); |         this.setWxMaConfig(configStorages); | ||||||
|       } else { |       } else { | ||||||
|         WxMaConfigHolder.set(miniappId); |         WxMaConfigHolder.set(miniappId); | ||||||
|  | |||||||
| @ -542,7 +542,12 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public void setMultiConfigStorages(Map<String, WxMpConfigStorage> configStorages, String defaultMpId) { |   public void setMultiConfigStorages(Map<String, WxMpConfigStorage> configStorages, String defaultMpId) { | ||||||
|  |     // 防止覆盖配置 | ||||||
|  |     if(this.configStorageMap != null) { | ||||||
|  |       this.configStorageMap.putAll(configStorages); | ||||||
|  |     } else { | ||||||
|       this.configStorageMap = Maps.newHashMap(configStorages); |       this.configStorageMap = Maps.newHashMap(configStorages); | ||||||
|  |     } | ||||||
|     WxMpConfigStorageHolder.set(defaultMpId); |     WxMpConfigStorageHolder.set(defaultMpId); | ||||||
|     this.initHttp(); |     this.initHttp(); | ||||||
|   } |   } | ||||||
| @ -550,7 +555,11 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | |||||||
|   @Override |   @Override | ||||||
|   public void addConfigStorage(String mpId, WxMpConfigStorage configStorages) { |   public void addConfigStorage(String mpId, WxMpConfigStorage configStorages) { | ||||||
|     synchronized (this) { |     synchronized (this) { | ||||||
|       if (this.configStorageMap == null) { |       /* | ||||||
|  |        * 因为commit 2aa27cf12d 默认初始化了configStorageMap,导致使用此方法无法进入if从而触发initHttp(), | ||||||
|  |        * 就会出现HttpClient报NullPointException | ||||||
|  |        */ | ||||||
|  |       if (this.configStorageMap == null || this.configStorageMap.isEmpty()) { | ||||||
|         this.setWxMpConfigStorage(configStorages); |         this.setWxMpConfigStorage(configStorages); | ||||||
|       } else { |       } else { | ||||||
|         WxMpConfigStorageHolder.set(mpId); |         WxMpConfigStorageHolder.set(mpId); | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 playersun
					playersun