The warning in IntelliJ about psaSuDb
being "always null" is a result of static analysis, which can't predict the dynamic behavior of mongoTemplate.findOne()
. The method can return either a valid Psa
object or null
depending on the MongoDB query result, and IntelliJ doesn't account for this runtime behavior. You can either ignore the warning, suppress it with @SuppressWarnings("ConstantConditions")
, or refactor the code to make the dynamic nature clearer to IntelliJ. The code is functioning as expected, and the warning is a false positive.