mebigfatguy / fb-contrib

a FindBugs/SpotBugs plugin for doing static code analysis for java code bases
http://fb-contrib.sf.net
GNU Lesser General Public License v2.1
157 stars 45 forks source link

FCBL_FIELD_COULD_BE_LOCAL False positive #428

Open victorherraiz-santander opened 2 years ago

victorherraiz-santander commented 2 years ago

Version 7.4.7 (latest) reports an issue on Builder nested class attribute data. It cannot be local because is used at the WithBuilderconstructor.

public final class WithBuilder {
    private final Integer data;

    private WithBuilder(Builder builder) {
        this.data = builder.data;
    }

    public Integer getData() {
        return data;
    }

    public static Builder builder() {
        return new Builder();
    }

    private final static class Builder {
        private Integer data = 0;

        public void setData(Integer data) {
            this.data = data;
        }

        public WithBuilder build() {
            return new WithBuilder(this);
        }
    }
}

The above code is only an example of a class much more complex that actually requires a builder pattern.