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 | ||||
|   @JsonDeserialize | ||||
|   public void setMultiConfigs(Map<String, WxMaConfig> configs, String defaultMiniappId) { | ||||
|     // 防止覆盖配置 | ||||
|     if(this.configMap != null) { | ||||
|       this.configMap.putAll(configs); | ||||
|     } else { | ||||
|       this.configMap = Maps.newHashMap(configs); | ||||
|     } | ||||
|     WxMaConfigHolder.set(defaultMiniappId); | ||||
|     this.initHttp(); | ||||
|   } | ||||
| @ -385,7 +390,11 @@ public abstract class BaseWxMaServiceImpl<H, P> implements WxMaService, RequestH | ||||
|   @Override | ||||
|   public void addConfig(String miniappId, WxMaConfig configStorages) { | ||||
|     synchronized (this) { | ||||
|       if (this.configMap == null) { | ||||
|       /* | ||||
|        * 因为commit f74b00cf 默认初始化了configMap,导致使用此方法无法进入if从而触发initHttp(), | ||||
|        * 就会出现HttpClient报NullPointException | ||||
|        */ | ||||
|       if (this.configMap == null || this.configMap.isEmpty()) { | ||||
|         this.setWxMaConfig(configStorages); | ||||
|       } else { | ||||
|         WxMaConfigHolder.set(miniappId); | ||||
|  | ||||
| @ -542,7 +542,12 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | ||||
|  | ||||
|   @Override | ||||
|   public void setMultiConfigStorages(Map<String, WxMpConfigStorage> configStorages, String defaultMpId) { | ||||
|     // 防止覆盖配置 | ||||
|     if(this.configStorageMap != null) { | ||||
|       this.configStorageMap.putAll(configStorages); | ||||
|     } else { | ||||
|       this.configStorageMap = Maps.newHashMap(configStorages); | ||||
|     } | ||||
|     WxMpConfigStorageHolder.set(defaultMpId); | ||||
|     this.initHttp(); | ||||
|   } | ||||
| @ -550,7 +555,11 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH | ||||
|   @Override | ||||
|   public void addConfigStorage(String mpId, WxMpConfigStorage configStorages) { | ||||
|     synchronized (this) { | ||||
|       if (this.configStorageMap == null) { | ||||
|       /* | ||||
|        * 因为commit 2aa27cf12d 默认初始化了configStorageMap,导致使用此方法无法进入if从而触发initHttp(), | ||||
|        * 就会出现HttpClient报NullPointException | ||||
|        */ | ||||
|       if (this.configStorageMap == null || this.configStorageMap.isEmpty()) { | ||||
|         this.setWxMpConfigStorage(configStorages); | ||||
|       } else { | ||||
|         WxMpConfigStorageHolder.set(mpId); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 playersun
					playersun