Skip to content

Commit

Permalink
fix npe
Browse files Browse the repository at this point in the history
  • Loading branch information
jackie-coming committed Nov 27, 2024
1 parent 5f1e105 commit d07862e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@
import com.google.common.net.UrlEscapers;
import com.google.common.util.concurrent.RateLimiter;
import com.google.gson.Gson;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import java.util.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -249,10 +247,12 @@ private ApolloConfig loadApolloConfig() {
}

ApolloConfig result = response.getBody();

ConfigSyncType configSyncType=ConfigSyncType.fromString(result.getConfigSyncType());
if(configSyncType!=null&&configSyncType.equals(ConfigSyncType.INCREMENTALSYNC)){
result.setConfigurations(mergeConfigurations(m_configCache.get().getConfigurations(),result.getConfigurationChanges()));
if(result!=null){
ConfigSyncType configSyncType=ConfigSyncType.fromString(result.getConfigSyncType());
if(configSyncType!=null&&configSyncType.equals(ConfigSyncType.INCREMENTALSYNC)){
ApolloConfig apolloConfig = m_configCache.get()==null?new ApolloConfig():m_configCache.get();
result.setConfigurations(mergeConfigurations(apolloConfig.getConfigurations(),result.getConfigurationChanges()));
}
}

logger.debug("Loaded config for {}: {}", m_namespace, result);
Expand Down Expand Up @@ -363,7 +363,13 @@ private List<ServiceDTO> getConfigServices() {
}

private Map<String, String> mergeConfigurations(Map<String, String> configurations,List<ConfigurationChange> configurationChanges) {
Map<String, String> newConfigurations = Maps.newHashMap(configurations);
Map<String, String> newConfigurations = new HashMap<>();
if (configurationChanges == null) {
return newConfigurations;
}
if(configurations!=null){
Maps.newHashMap(configurations);
}
for (ConfigurationChange change : configurationChanges) {
switch (change.getConfigurationChangeType()) {
case ADDED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.ctrip.framework.apollo.core.dto;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
*/
public class ConfigurationChange {
private final String key;
private String newValue;
private ConfigurationChangeType configurationChangeType;
private final String newValue;
private final ConfigurationChangeType configurationChangeType;

/**
* Constructor.
Expand All @@ -51,13 +51,6 @@ public ConfigurationChangeType getConfigurationChangeType() {
return configurationChangeType;
}

public void setNewValue(String newValue) {
this.newValue = newValue;
}

public void setConfigurationChangeType(ConfigurationChangeType configurationChangeType) {
this.configurationChangeType = configurationChangeType;
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ public static ConfigSyncType fromString(String value) {
if (StringUtils.isEmpty(value)) {
return FULLSYNC;
}
return Stream.of(ConfigSyncType.values()).filter(type -> type.value.equals(value))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(value + " can not map enum"));
for (ConfigSyncType type : values()) {
if (type.value.equals(value)) {
return type;
}
}
throw new IllegalArgumentException("Invalid ConfigSyncType: " + value);

}

/**
Expand Down

0 comments on commit d07862e

Please sign in to comment.