mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-181080 Result of expression is ignored for Optional.orElseThrow
This commit is contained in:
@@ -36,7 +36,7 @@ public abstract class ContractValue {
|
||||
/**
|
||||
* @return true if this contract value represents a bounds-checking condition
|
||||
*/
|
||||
boolean isBoundCheckingCondition() {
|
||||
public boolean isBoundCheckingCondition() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ public abstract class ContractValue {
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isBoundCheckingCondition() {
|
||||
public boolean isBoundCheckingCondition() {
|
||||
switch (myRelationType) {
|
||||
case LE:
|
||||
case LT:
|
||||
|
||||
+3
-3
@@ -71,7 +71,7 @@ public abstract class MethodContract {
|
||||
|
||||
abstract String getArgumentsPresentation();
|
||||
|
||||
abstract List<ContractValue> getConditions();
|
||||
public abstract List<ContractValue> getConditions();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -91,7 +91,7 @@ public abstract class MethodContract {
|
||||
}
|
||||
|
||||
@Override
|
||||
List<ContractValue> getConditions() {
|
||||
public List<ContractValue> getConditions() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
};
|
||||
@@ -114,7 +114,7 @@ public abstract class MethodContract {
|
||||
}
|
||||
|
||||
@Override
|
||||
List<ContractValue> getConditions() {
|
||||
public List<ContractValue> getConditions() {
|
||||
return Collections.singletonList(condition);
|
||||
}
|
||||
};
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ public final class StandardMethodContract extends MethodContract {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ContractValue> getConditions() {
|
||||
public List<ContractValue> getConditions() {
|
||||
return IntStreamEx.ofIndices(arguments).mapToObj(idx -> arguments[idx].getCondition(idx)).without(ContractValue.booleanValue(true))
|
||||
.toList();
|
||||
}
|
||||
|
||||
+3
-2
@@ -209,8 +209,9 @@ public class SideEffectChecker {
|
||||
if (method.getName().startsWith("assert") || method.getName().startsWith("check")) {
|
||||
return true;
|
||||
}
|
||||
return ControlFlowAnalyzer.getMethodContracts(method).stream()
|
||||
.anyMatch(mc -> mc.returnValue == MethodContract.ValueConstraint.THROW_EXCEPTION);
|
||||
return ControlFlowAnalyzer.getMethodCallContracts(method, null).stream()
|
||||
.filter(mc -> mc.getConditions().stream().noneMatch(cv -> cv.isBoundCheckingCondition()))
|
||||
.anyMatch(mc -> mc.getReturnValue() == MethodContract.ValueConstraint.THROW_EXCEPTION);
|
||||
}
|
||||
|
||||
private static boolean isSideEffectFreeConstructor(@NotNull PsiNewExpression newExpression) {
|
||||
|
||||
+12
@@ -281,4 +281,16 @@ class Test {
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
void testOptionalOrElseThrow() {
|
||||
doTest """
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||
class Test {
|
||||
void test(Optional<String> opt) {
|
||||
opt.orElseThrow(RuntimeException::new);
|
||||
}
|
||||
}"""
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user