mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-221210 false positive isEmpty is always true after stream.collect with custom Collector
GitOrigin-RevId: 6b5616254c78f038380ab7f4bf017a5905ce7c9f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
760e8e2740
commit
6d76ec8820
@@ -452,6 +452,19 @@ public class CFGBuilder {
|
||||
return add(new FlushFieldsInstruction());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate instruction to flush given value if it's variable.
|
||||
*
|
||||
* @param value value to flush
|
||||
* @return this builder
|
||||
*/
|
||||
public CFGBuilder flush(DfaValue value) {
|
||||
if (value instanceof DfaVariableValue) {
|
||||
add(new FlushVariableInstruction((DfaVariableValue)value));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate instructions to assign top stack value to the second stack value
|
||||
* (usually pushed via {@link #pushForWrite(DfaVariableValue)}).
|
||||
|
||||
+1
-1
@@ -600,7 +600,7 @@ public class StreamChainInliner implements CallInliner {
|
||||
void iteration(CFGBuilder builder) {
|
||||
// do nothing currently: we can emulate calling collection.add,
|
||||
// but it's unnecessary for current analysis
|
||||
builder.pop();
|
||||
builder.flush(SpecialField.COLLECTION_SIZE.createValue(builder.getFactory(), myResult)).pop();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class Main2 {
|
||||
// IDEA-221210
|
||||
public static void main(String[] args) {
|
||||
List<Integer> originalList = new ArrayList<>();
|
||||
originalList.add(1);
|
||||
final List<Integer> newList = originalList.stream()
|
||||
.collect(Collectors.toCollection(() -> new ArrayList<>(1)));
|
||||
|
||||
boolean empty = newList.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -174,6 +174,7 @@ public class DataFlowInspection8Test extends DataFlowInspectionTestCase {
|
||||
public void testStreamInlining() { doTest(); }
|
||||
public void testStreamCollectorInlining() { doTest(); }
|
||||
public void testStreamToMapInlining() { doTest(); }
|
||||
public void testStreamToCollectionInlining() { doTest(); }
|
||||
public void testStreamComparatorInlining() { doTest(); }
|
||||
public void testStreamKnownSource() { doTest(); }
|
||||
public void testStreamTypeAnnoInlining() {
|
||||
|
||||
Reference in New Issue
Block a user