#298 RequireThis requires adding "this." to static members

SVN_Head
closed
Other (70)
5
2012-10-10
2005-03-03
kit_
No

When is add "RequireThis" checkers to the configuration
file then it requires adding "this." event to static
members.

Discussion

  • Logged In: YES
    user_id=746148

    the check works as desined, we already have RFE about this
    (1070794)
    I close this bug as duplicate.

     
  • Logged In: YES
    user_id=628011

    Works as designed?

    Checkstyle even complains about missing "this." for static
    fields in static methods where you don't have an instance of
    the class. Means: adding the this to make checkstyle happy
    would result in a compile error.

    This is clearly a bug and not a RFE.

     
  • Logged In: YES
    user_id=746148

    compiler does allow to reference static members using "this"
    So, compiler will not complain.

     
  • Logged In: YES
    user_id=628011

    You are right that compiler doesn't complain about
    referencing static fields by "this" in instance methods. But
    I was talking about static methods. Try this one:

    public class RequireThisTest {
    static int NUMBER = 1;

    static {
    System.out.println(NUMBER);
    }
    }

    RequireThis will complain about the missing "this" but with
    the "this" the compiler complains because we don't have a
    "this" instance in a static context.

    So I stand by my accessment that this is a bug and not a RFE.

    (Note: to make compiler and RequireThis happy, I could write
    System.out.println(RequireThisTest.NUMBER);
    But if you see it this way, I would say that in this case
    the RequireThis module is wrongly named (and documented) and
    should be renamed to RequireExplicitAccess or something like
    this)

     
  • Logged In: YES
    user_id=746148

    Sorry, I missed static methods :(
    I will transform 1070794 to bug.

     
  • Logged In: YES
    user_id=746148

    I've re-read 1070794 and it looks like it is better to reopen
    this bug.

     
  • Logged In: YES
    user_id=746148

    1490844 (Check RequireThis doesn't filter out static
    variables) was closed as duplicate of this bug

     
  • Lars Kühne
    Lars Kühne
    2006-12-08

    Logged In: YES
    user_id=401384
    Originator: NO

    RFE #1610970 (Allow "Require This" to ignore static fields and methods) has been closed as a duplicate of this bug.

     
  • Logged In: YES
    user_id=746148
    Originator: NO

    1631665 ("Require This" checker bugs with static fields) was closed as duplicate of this bug

     
  • Logged In: YES
    user_id=505193
    Originator: NO

    The reported error message is confusing. I found out that you have to prefix the class name: Instead of PROPERTY_EVENTNAME use ClassName.PROPERTY_EVENTNAME even if this code is within Classname. I don't consider this to be in the scope of "require this" but in general this seems to be good coding style as you can recognize the location of the constant which is cool if you inherit them.

    kind regards,

    Achim (non-checkstyle member)

     
  • Logged In: YES
    user_id=505193
    Originator: NO

    The reported error message is confusing. I found out that you have to prefix the class name: Instead of PROPERTY_EVENTNAME use ClassName.PROPERTY_EVENTNAME even if this code is within Classname. I don't consider this to be in the scope of "require this" but in general this seems to be good coding style as you can recognize the location of the constant which is cool if you inherit them.

    kind regards,

    Achim (non-checkstyle member)

     
  • the check works as desined
    Are you serious?
    This is inacceptable. Look at all the duplicates.
    Users really dont think that this is correct behaviour!
    Besides it is common java style to access static members inside the defining class (or if inherited) directly without qualifying your own class.

    Wha is RFE? Radio Free Europe?

     
  • Ah, got it
    RFE = request for enhancement

    Anyways it is a bug!
    this.MY_CONSTANT is NOT good coding style and simply wrong in static methods!!!
    Checkstyle tells me to add "this." even if the method is static.
    But adding "this." will cause a compile error!
    Aint this a bug?

    Please ignore static members in this check and add a new check for static members.

     
  • bug #3022727 closed as duplicate of this ticket

     
  • 2809659 closed as duplicate of this ticket

     
  • I've implemented a simple fix: the check now ignores static fields and members.
    Though I have a feeling that this is not the last problem we have with the check :( Next time we may need to rewrite the test completely.