IDEA-208770 Inspection OptionalGetWithoutIsPresent doesn't recognize check in stream

This commit is contained in:
Tagir Valeev
2019-03-14 11:55:48 +07:00
parent 5222cb45b3
commit ba3791e5de
2 changed files with 17 additions and 0 deletions
@@ -754,8 +754,10 @@ public class StreamChainInliner implements CallInliner {
// exactly single element
PsiExpression arg = sourceCall.getArgumentList().getExpressions()[0];
builder
.pushForWrite(builder.createTempVariable(inType))
.pushExpression(arg)
.boxUnbox(arg, inType)
.assign()
.chain(firstStep::before)
.chain(firstStep::iteration);
return;
@@ -429,4 +429,19 @@ class FinallyTest
System.out.println(a.getAsInt());
}
}
class X {
private String value;
public Optional<String> getValue() {
return Optional.ofNullable(value);
}
}
void testStream() {
// IDEA-208770
Stream.of(new X(), new X()).filter(x -> x.getValue().isPresent()).map(x -> x.getValue().get());
Stream.of(new X()).filter(x -> x.getValue().isPresent()).map(x -> x.getValue().get());
X xx = new X();
Stream.of(xx).filter(x -> x.getValue().isPresent()).map(x -> x.getValue().get());
}
}