mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-116947 Unqualified call NPE false positive with contracts
This commit is contained in:
+7
-3
@@ -1414,14 +1414,14 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
if (contracts.size() > 1) {
|
||||
addInstruction(new DupInstruction(args.length, contracts.size() - 1));
|
||||
}
|
||||
for (MethodContract contract : contracts) {
|
||||
handleContract(expression, contract);
|
||||
for (int i = 0; i < contracts.size(); i++) {
|
||||
handleContract(expression, contracts.get(i), contracts.size() - 1 - i);
|
||||
}
|
||||
pushUnknownReturnValue(expression); // goto here if all contracts are false
|
||||
return true;
|
||||
}
|
||||
|
||||
private void handleContract(PsiMethodCallExpression expression, MethodContract contract) {
|
||||
private void handleContract(PsiMethodCallExpression expression, MethodContract contract, int remainingContracts) {
|
||||
PsiExpression[] args = expression.getArgumentList().getExpressions();
|
||||
|
||||
final ControlFlow.ControlFlowOffset exitPoint = getEndOffset(expression);
|
||||
@@ -1448,6 +1448,10 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
continueCheckingContract.setOffset(myCurrentFlow.getInstructionCount());
|
||||
}
|
||||
|
||||
for (int j = 0; j < remainingContracts * args.length; j++) {
|
||||
addInstruction(new PopInstruction());
|
||||
}
|
||||
|
||||
// if contract is true
|
||||
switch (contract.returnValue) {
|
||||
case ANY_VALUE:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Foo {
|
||||
|
||||
@@ -6,8 +7,21 @@ public class Foo {
|
||||
return escapeStr(s, escaper);
|
||||
}
|
||||
|
||||
String foo2(Object escaper, @Nullable String s) {
|
||||
return <warning descr="Expression 'escapeStr(s, escaper)' might evaluate to null but is returned by the method which is not declared as @Nullable">escapeStr(s, escaper)</warning>;
|
||||
}
|
||||
|
||||
void foo3(@Nullable String s) {
|
||||
foo2(this, escapeStr(s));
|
||||
}
|
||||
|
||||
@Contract("null,_->null;!null,_->!null")
|
||||
String escapeStr(String s, Object o) {
|
||||
return s;
|
||||
}
|
||||
|
||||
@Contract("null->null;!null->!null")
|
||||
String escapeStr(String s) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user