Skip to content

Commit

Permalink
npe fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lepdou committed Apr 14, 2016
1 parent 8720978 commit fb6359a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Expand Up @@ -21,6 +21,7 @@
import org.springframework.web.client.HttpClientErrorException;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;


Expand Down Expand Up @@ -74,7 +75,7 @@ public static class ItemAPI extends API {

public List<ItemDTO> findItems(String appId, Apollo.Env env, String clusterName, String namespace) {
if (StringUtils.isContainEmpty(appId, clusterName, namespace)) {
return null;
return Collections.EMPTY_LIST;
}

return Arrays.asList(restTemplate.getForObject(getAdminServiceHost(env) + String
Expand Down Expand Up @@ -140,7 +141,8 @@ public ReleaseDTO release(String appId, Apollo.Env env, String clusterName, Stri
ResponseEntity<ReleaseDTO> response = restTemplate.postForEntity(getAdminServiceHost(env) + String.
format("apps/%s/clusters/%s/namespaces/%s/releases", appId, clusterName, namespace),
entity, ReleaseDTO.class);
if (response.getStatusCode() == HttpStatus.OK){

if (response != null && response.getStatusCode() == HttpStatus.OK){
return response.getBody();
}else {
logger.error("release fail.id:{}, env:{}, clusterName:{}, namespace:{},releaseBy{}",appId, env, clusterName, namespace, releaseBy);
Expand Down
Expand Up @@ -44,12 +44,15 @@ public ResponseEntity<SimpleMsg> modifyItems(@PathVariable String appId, @PathVa
@PathVariable String clusterName, @PathVariable String namespaceName,
@RequestBody NamespaceModifyModel model) {

if (model == null){
return ResponseEntity.badRequest().body(new SimpleMsg("form data exception."));
}
model.setAppId(appId);
model.setClusterName(clusterName);
model.setEnv(env);
model.setNamespaceName(namespaceName);

if (model == null || model.isInvalid()){
if (model.isInvalid()){
return ResponseEntity.badRequest().body(new SimpleMsg("form data exception."));
}

Expand All @@ -66,12 +69,15 @@ public ResponseEntity<SimpleMsg> modifyItems(@PathVariable String appId, @PathVa
public ResponseEntity<SimpleMsg> createRelease(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName,
@RequestBody NamespaceReleaseModel model){
if (model == null){
return ResponseEntity.badRequest().body(new SimpleMsg("form data exception."));
}
model.setAppId(appId);
model.setClusterName(clusterName);
model.setEnv(env);
model.setNamespaceName(namespaceName);

if (model == null || model.isInvalid()){
if (model.isInvalid()){
return ResponseEntity.badRequest().body(new SimpleMsg("form data exception."));
}

Expand Down
Expand Up @@ -90,8 +90,11 @@ private boolean isHasRepeatKey(String[] newItems){
int keyCount = 0;
for (String item: newItems){
if (!isCommentItem(item) && !isBlankItem(item)){
keyCount ++;
keys.add(parseKeyValueFromItem(item)[0]);
keyCount++;
String[] kv = parseKeyValueFromItem(item);
if (kv != null) {
keys.add(kv[0]);
}
}
}

Expand Down

0 comments on commit fb6359a

Please sign in to comment.