False positive S4248 with Lombok @UtilityClass

On SonarCloud, SonarJava raises false positives for regex Patterns when using Lombok @UtilityClass.
S4248 requires compiled patterns to be assigned to constants, but does not recognize the static keyword generated by @UtilityClass.


import java.util.regex.Pattern;

import lombok.experimental.UtilityClass;

public class Foo
    // S4248: Refactor this code to use a "static final" Pattern.
    private final Pattern PATTERN = Pattern.compile(".*");

Hello, welcome to the community!

Thanks for the feedback, indeed, this is a wrong behavior of the rule in the presence of Lombok.

I created a ticket (SONARJAVA-3379) to keep track of this issue.


Thanks for the quick reply and all the good work. :muscle:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.