I have a record which has a List property, like this:
public record MyRecord(List<SomeOtherRecord> otherRecords) {
public MyRecord(List<OtherRecord> otherRecords) {
this.otherRecords = nullSafeCopyOf(otherRecords);
}
private static <T> List<T> nullSafeCopyOf(List<T> source) {
if (source != null) {
return List.copyOf(source);
} else {
return List.of();
}
}
}
Because List.copyOf throws an NPE when a null is passed and because I have multiple of such records, I created a small helper method to get rid of all the null-checks. But now the AvoidExposingMutableRecordState rule doesn't recognize it anymore.
Hi @jankeesvanandel thanks for reporting! Current priority is migrate to pmd7 to make the rules work in IntelliJ 2024.2+ again. After that, this issue will be in the picture again.
I have a record which has a List property, like this:
Because List.copyOf throws an NPE when a null is passed and because I have multiple of such records, I created a small helper method to get rid of all the null-checks. But now the AvoidExposingMutableRecordState rule doesn't recognize it anymore.