mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: check for immutable types in records (IDEA-372966)
in "Assignment or return of field with mutable type" inspection GitOrigin-RevId: 96e782484fde1ad2229b19b30cf928847b04d4ba
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c0b6890c72
commit
d461d596f7
+1
@@ -161,6 +161,7 @@ public final class AssignmentOrReturnOfFieldWithMutableTypeInspection extends Ba
|
||||
boolean reportAssignment = !ContainerUtil.or(recordClass.getConstructors(), c -> JavaPsiRecordUtil.isExplicitCanonicalConstructor(c));
|
||||
for (PsiRecordComponent component : recordHeader.getRecordComponents()) {
|
||||
final PsiType type = component.getType();
|
||||
if (ClassUtils.isImmutable(type)) continue;
|
||||
final boolean mutable = type instanceof PsiArrayType ||
|
||||
ContainerUtil.exists(MUTABLE_TYPES, typeName -> InheritanceUtil.isInheritor(type, typeName));
|
||||
if (!mutable) continue;
|
||||
|
||||
+2
@@ -226,4 +226,6 @@ record Data4(Collection<String> strings) {
|
||||
public Collection<String> strings() {
|
||||
return <warning descr="Return of Collection<String> field 'strings'">strings</warning>;
|
||||
}
|
||||
}
|
||||
record Fooz(ImmutableList<Integer> ints) {
|
||||
}
|
||||
Reference in New Issue
Block a user