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: PMD7 AvoidUnguardedAssignmentToNonFinalFieldsInObjectsUsingSynchronized false positive #385

Closed stokpop closed 2 days ago

stokpop commented 3 days ago

matches local var, should be class field matches only

package com.jpinpoint.tryout;

import net.jcip.annotations.GuardedBy;

import java.util.HashMap;
import java.util.Map;

public class NoMatchOnNonFieldValues {
    @GuardedBy("this")
    private static Map staticMapField = new HashMap();

    public String getDetails() {

        String detailsResponse = null;
        try {
            detailsResponse = produceResponse(); // <-- false positive
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }

        return detailsResponse;
    }

    public static synchronized Map getStaticMapField() {
        return staticMapField;
    }
}