Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9154047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:22:07+00:00 2026-06-17T12:22:07+00:00

I have ‘builder’ class and Sonar gives the following warning: Missing Static Method In

  • 0

I have ‘builder’ class and Sonar gives the following warning:

Missing Static Method In Non Instantiatable Class
pmd : MissingStaticMethodInNonInstantiatableClass
A class that has private constructors and does not have any static methods or fields cannot be used

How would I refactor this class to satisfy the above check?
I’m scratching my head because I do use that class.

Sample use:

ViewBuilder vb = new ViewBuilder.Builder()
    .modelPart(CONTENT_PAGE, contentPageDao.get(id))
    .modelPart("navigation_sections", navigationSectionDao.list() )
    .modelPart("available_tags", tagDao.list() )
    .modelPart("available_albums", albumDao.list() )
    .section(CONTENT_PAGE)
    .page("index")
    .element("form")
    .action("/admin/content_page/save/" + id + ".html")
    .build();

Class itself:

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


 public final class ViewBuilder {

    private static final String ADMIN_LAYOUT = "admin/layout";
    private String layout = ADMIN_LAYOUT;
    private String section = "";

  private static Map<String, Object> viewParts = new HashMap<String, Object>();

  /**
   * @return the layout
   */ public String getLayout() {
    return layout;
  }

  /**
   * @param layout the layout to set
   */ public void setLayout(String layout) {
    this.layout = layout;
  }

  /**
   * @return the section
   */ public String getSection() {
    return section;
  }

  /**
   * @param section the section to set
   */ public void setSection(String section) {
    this.section = section;
  }

  public static class Builder{

    // required params
    private String layout;
    private String section;

    // optional params
    private Map<String, Object > viewParts = new HashMap<String, Object >();

    public Builder(){

        this.layout = ADMIN_LAYOUT;
        viewParts.put("layout", ADMIN_LAYOUT);

    }
    public Builder( String layout ){

      if( layout != null ){
        this.layout = layout;
        viewParts.put("layout", layout );
      } else {
        this.layout = ADMIN_LAYOUT;
        viewParts.put("layout", ADMIN_LAYOUT);
      }

    }// constructor
    public Builder modelPart( String val, Object o ){
      this.viewParts.put(val, o );
      return this;
    }

    public Builder action( String val ){
      this.viewParts.put("action", val);
      return this;
    }
    public Builder element( String val ){
      this.viewParts.put("element", val);
      return this;
    }
    public Builder section( String val ){
      this.section = val;
      this.viewParts.put("section", val);
      return this;
    }
    public Builder page( String val ){
      this.viewParts.put("page", val);
      return this;
    }
    public Builder layout( String val ){
      this.layout = val;
      return this;
    }

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


  }// Builder

    private ViewBuilder(Builder builder){
      this.section = builder.section;
      this.layout = builder.layout;

      viewParts = builder.viewParts;
    }

  /**
   * Get the value of viewParts
   *
   * @return the value of viewParts
   */
  public Map<String, Object> getViewParts() { return viewParts; }

  /**
   * Set the value of viewParts
   *
   * @param viewParts new value of viewParts
   */
  public void setViewParts(Map<String, Object> viewParts) { this.viewParts = viewParts; }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:22:08+00:00Added an answer on June 17, 2026 at 12:22 pm

    Given that your nested Builder class is public and static, I really see little benefit in it being nested at all. I would recommend breaking it out into its own top level class. Of course, thats not why PMD is complaining. Your outer class, ViewBuilder, has no public constructors, and no static methods. As it exists right now, its a fairly useless ‘namespace wrapper’ around your Builder class. Either add a constructor to it, or get rid of it altogether.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have the following code: String s= v.request(engine/?key=, P4z72NmBa91&method=load); JSONParser parser = new JSONParser(); Object
Have a test program public class Path { public static void main(String[] args) {
have written this little class, which generates a UUID every time an object of
Have such user_session model: class UserSession < Authlogic::Session::Base logout_on_timeout true # default if false
Have got a method which returns IEnumerable<User> which I have been using Linq /
Have written all the code in a silverlight class library (dll) and linked this
Have the following cronjob set up in root's crontab: (centos 5.x) 2 * *
Have: [DllImport(OpenAL32.dll)] static extern void alcOpenDevice(char*[] devicename); Wanna send the name to this function
have a class structure like so Permit -> Financial ->ICollection instrumentList Instrument -> Agency
Have the following code: $(#blogs).mouseover( function () { $(this).addClass(hover); $(#home).removeClass(hover); $(#homepages).removeClass(hover); $(#apps).removeClass(hover); $(#facebook).removeClass(hover); $(#kontakt).removeClass(hover);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.