mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
CollectMigration: do not wrap nullable values with toUnmodifiableList/Set (IDEA-207976)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInspection.streamMigration;
|
||||
|
||||
import com.intellij.codeInsight.Nullability;
|
||||
import com.intellij.codeInsight.intention.impl.StreamRefactoringUtil;
|
||||
import com.intellij.codeInspection.dataFlow.NullabilityUtil;
|
||||
import com.intellij.codeInspection.util.LambdaGenerationUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -959,6 +961,11 @@ class CollectMigration extends BaseStreamApiMigration {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (terminal instanceof AddingTerminal) {
|
||||
Nullability nullability = NullabilityUtil.getExpressionNullability(((AddingTerminal)terminal).getMapping(), true);
|
||||
// Null is not allowed in unmodifiable list/set
|
||||
if (nullability == Nullability.NULLABLE) return null;
|
||||
}
|
||||
return new UnmodifiableTerminal(terminal, candidate.myVar, wrapCall, collector);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,13 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class Test {
|
||||
|
||||
List<String> testNullable(List<Integer> input) {
|
||||
// suppress for nullable
|
||||
List<String> list = input.stream().map(integer -> integer == null ? null : integer.toString()).collect(Collectors.toList());
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
List<String> test(String[] list) {
|
||||
return Arrays.stream(list).filter(s -> !s.isEmpty()).collect(Collectors.toUnmodifiableList());
|
||||
}
|
||||
|
||||
@@ -2,6 +2,16 @@
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
|
||||
List<String> testNullable(List<Integer> input) {
|
||||
// suppress for nullable
|
||||
List<String> list = new ArrayList<>();
|
||||
for (var integer : input) {
|
||||
list.add(integer == null ? null : integer.toString());
|
||||
}
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
|
||||
List<String> test(String[] list) {
|
||||
List<String> result = new LinkedList<>();
|
||||
f<caret>or (int i = 0; i < list.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user