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

  • SEARCH
  • Home
  • 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 439367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:46:08+00:00 2026-05-12T20:46:08+00:00

One of the built-in Checkstyle checks is RequireThis , which will go off whenever

  • 0

One of the built-in Checkstyle checks is RequireThis, which will go off whenever you don’t prepend this. to local field or method invocations. For example,

public final class ExampleClass {
    public String getMeSomething() { 
        return "Something"; 
    }

    public String getMeSomethingElse() {
        //will violate Checkstyle; should be this.getMeSomething()
        return getMeSomething() + " else"; 
    }
}

I’m struggling with whether this check is justified. In the above example, the ExampleClass is final, which should guarantee that the “right” version of getMeSomething should be invoked. Additionally, there seem to be instances where you might want subclasses to override default behavior, in which case requiring “this” is the wrong behavior.

Finally, it seems like overly defensive coding behavior that only clutters up the source and makes it more difficult to see what is actually going on.

So before I suggest to my architect that this is a bad check to enable, I’m wondering if anyone else has enabled this check? Have you caught a critical bug as a result of a missing this?

  • 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-05-12T20:46:09+00:00Added an answer on May 12, 2026 at 8:46 pm

    The RequireThis rule does have a valid use in that it can prevent a possible bug in methods and constructors when it applies to fields. The code below is almost certainly a bug:

    void setSomething(String something) {
        something = something;
    }
    

    Code like this will compile but will do nothing except reassign the value of the method parameter to itself. It is more likely that the author intended to do this:

    void setSomething(String something) {
        this.something = something;
    }
    

    This is a typo that could happen and is worth checking for as it may help to prevent hard to debug problems if the code fails because this.something is not set much later in the program.

    The checkstyle settings allow you to keep this useful check for fields while omitting the largely unnecessary check for methods by configuring the rule like this:

       <module name="RequireThis">
           <property name="checkMethods" value="false"/>
       </module>
    

    When it comes to methods this rule has no real effect because calling this.getMeSomething() or just getMeSomething() has no effect on Java’s method resolution. Calling this.getSomethingStatic() still works when the method is static this is not an error, it is only a warning in various IDEs and static analysis tools.

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

Sidebar

Related Questions

I've built one variable (horaires_lundi) in this file : app/code/community/Unirgy/StoreLocator/controllers/Adminhtml/Locationcontroller.php ->setTitle($this->getRequest()->getParam('title')) ->setNotes($this->getRequest()->getParam('notes')) ->setStreetAddress($this->getRequest()->getParam('street_address')) ->setHorairesLundi($this->getRequest()->getParam('horaires_lundi'))
I have this entity class, the first one I built to test Hibernate, it
From this tutorial . see i have one pre-built static library named as stackoverflow.a
Is it possible that there are more than one certificate chain built during the
I'm using an asp.net Menu (asp:Menu - the built-in one) and I want to
I built a basic search form that queries one column in one table of
I have built 2 apps: one for iPhone, one for iPad. They both build
I have built some highcharts charts and I am displaying them one at a
I've built a web site on ASP.NET MVC and one little section of it
I have built a site using php and want to try keep it one

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.