jborgers / PMD-jPinpoint-rules

PMD rule set for responsible Java and Kotlin coding: performance, sustainability, multi-threading, data mixup and more.
Apache License 2.0
43 stars 10 forks source link

Fix request: False positive in AvoidExposingMutableRecordState #356

Open jankeesvanandel opened 1 month ago

jankeesvanandel commented 1 month ago

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.

jborgers commented 3 weeks ago

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.