简体   繁体   English

如何告诉 IntelliJ IDEA 方法正在检查 null 值(ConstantConditions 警告)

[英]How to tell IntelliJ IDEA that a method is checking for null value (ConstantConditions warning)

We have a common method that we shared across our codebase to check if a response is empty, including null body.我们有一个在我们的代码库中共享的通用方法来检查响应是否为空,包括null正文。 This is the signature of the method这是方法的签名

public static <T> boolean checkResponseEmpty(ResponseEntity<T> responseEntity);

Is there a way (maybe by adding annotation) to tell the IDEA that we've checked for null value on some fields, and it does not have to tell us a warning for ConstantConditions for that object and the fields (see screenshot).有没有办法(也许通过添加注释)告诉 IDEA 我们已经检查了某些字段的null值,并且它不必告诉我们针对该 object 和字段的ConstantConditions警告(见屏幕截图)。

IntelliJ IDEA 警告


PS: I already know that I can suppress the warning with //noinspection ConstantConditions but I don't event want to do that. PS:我已经知道我可以使用//noinspection ConstantConditions来抑制警告,但我不想这样做。

IDEA can see the check for 'response', but there are no explicit checks for 'getBody' or 'getArrivals'. IDEA 可以看到对“response”的检查,但是没有对“getBody”或“getArrivals”的明确检查。 First, you can extract 'response.getBody()' to a variable and check if it's not null. Second, you can use JetBrains '@NotNull' annotation on a return of 'getBody' and 'getArrivals' if it's suites your code logic (see https://www.jetbrains.com/help/idea/nullable-and-notnull-annotations.html )首先,您可以将“response.getBody()”提取到变量并检查它是否不是 null。其次,您可以在返回“getBody”和“getArrivals”时使用 JetBrains“@NotNull”注释(如果它适合您的代码逻辑) (参见https://www.jetbrains.com/help/idea/nullable-and-notnull-annotations.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM