diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionEnvService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionEnvService.java index 832b7e97e6..11c6b1b30b 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionEnvService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionEnvService.java @@ -6,6 +6,7 @@ import io.metersphere.base.domain.ApiTestEnvironmentExample; import io.metersphere.base.mapper.ApiDefinitionEnvMapper; import io.metersphere.base.mapper.ApiTestEnvironmentMapper; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -42,10 +43,12 @@ public class ApiDefinitionEnvService { if (CollectionUtils.isNotEmpty(list)) { ApiTestEnvironmentExample environmentExample = new ApiTestEnvironmentExample(); - environmentExample.createCriteria().andProjectIdEqualTo(projectId).andIdEqualTo(list.get(0).getEnvId()); - long count = apiTestEnvironmentMapper.countByExample(environmentExample); - if (count > 0) { - return list.get(0); + if (StringUtils.isNotEmpty(list.get(0).getEnvId())) { + environmentExample.createCriteria().andProjectIdEqualTo(projectId).andIdEqualTo(list.get(0).getEnvId()); + long count = apiTestEnvironmentMapper.countByExample(environmentExample); + if (count > 0) { + return list.get(0); + } } } return null;