Quantcast

"Missing Static Method In Non Instantiatable Class" in builder pattern

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

"Missing Static Method In Non Instantiatable Class" in builder pattern

Piotr Picheta
Hi

I'm courious why this code example of builder pattern is breaking
"Missing Static Method In Non Instantiatable Class" rule, it's not that
class cannot be instantiated:

public final class RecipientDTO {

     private final Long id;

     public static class Builder {

         // required parameters
         private Long id;

         public Builder(final long id) {
             this.id = id;
         }

         public Builder setId(final long id) {
             this.id = id;
             return this;
         }

         public final RecipientDTO build() {
             return new RecipientDTO(this);
         }
     }

     private RecipientDTO(final Builder builder) {
         this.id = builder.id;
     }

     public Long getId() {
         return this.id;
     }
}



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: "Missing Static Method In Non Instantiatable Class" in builder pattern

Freddy Mallet
Indeed Piotr, this is clearly a case which is not correctly handled by this PMD rule. Feel free to create a JIRA ticket

Thanks for your feedback
-----
Sonar for Continuous Inspection



On Wed, Oct 10, 2012 at 10:10 PM, Piotr Picheta <[hidden email]> wrote:
Hi

I'm courious why this code example of builder pattern is breaking "Missing Static Method In Non Instantiatable Class" rule, it's not that class cannot be instantiated:

public final class RecipientDTO {

    private final Long id;

    public static class Builder {

        // required parameters
        private Long id;

        public Builder(final long id) {
            this.id = id;
        }

        public Builder setId(final long id) {
            this.id = id;
            return this;
        }

        public final RecipientDTO build() {
            return new RecipientDTO(this);
        }
    }

    private RecipientDTO(final Builder builder) {
        this.id = builder.id;
    }

    public Long getId() {
        return this.id;
    }
}



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Loading...