Java Sonal lint:更改此条件,使其不总是计算为真

Java Sonal lint:更改此条件,使其不总是计算为真,java,spring,jpa,sonarqube,sonarlint,Java,Spring,Jpa,Sonarqube,Sonarlint,我试图使用Java服务中的数据JPA存储库,如下所示: @Service public class APIKeyServiceImpl implements APIKeyService { private APIKeyRepo apiKeyRepo; @Autowired public APIKeyServiceImpl(APIKeyRepo apiKeyRepo) { this.apiKeyRepo = apiKeyRepo; }

我试图使用Java服务中的数据JPA存储库,如下所示:

@Service
public class APIKeyServiceImpl implements APIKeyService {

    private APIKeyRepo apiKeyRepo;

    @Autowired
    public APIKeyServiceImpl(APIKeyRepo apiKeyRepo) {
        this.apiKeyRepo = apiKeyRepo;
    }


    @Override
    public String save(String apiKeyInput) {

        APIKEY apikey = new APIKEY();
        apikey.setApikey(apiKeyInput);

        APIKEY savedKey = apiKeyRepo.save(apikey);

        return null != savedKey ? savedKey.getApikey() : null;
    }

}
现在,短期回购代码如下:

public interface APIKeyRepo extends JpaRepository<APIKEY, String> {

}
我不太明白这其中的哪一部分总是评估正确

保存实体时,保存方法将返回保存的实体,该实体永远不能为空

来源:方法文件。

保存实体时,保存方法将返回保存的实体,该实体永远不能为空


来源:方法文档。

我想存储库总是返回非空值:为什么(在什么条件下)认为
savedKey
为空?@AlexanderTerekhov-谢谢,注意到了。@ScaryWombat-我实际上认为JPA可能会给出空结果。我错了。当你保存一个实体时,你总是会得到保存的实体作为回报,这就是为什么它在任何时候都不能是空对象!我想存储库总是返回非空值:为什么(在什么条件下)认为
savedKey
是空的?@AlexanderTerekhov-谢谢,注意到了。@ScaryWombat-我实际上认为JPA可能会给出空的结果。我错了。当你保存一个实体时,你总是会得到保存的实体作为回报,这就是为什么它在任何时候都不能是空对象!
return null != savedKey ? savedKey.getApikey() : null;