#259 Style check problem for methods parameter final modifier

release_3.4
closed
5
2012-10-10
2004-10-20
Amey
No

Hi
We are currently using checkstyle for code style
checking.We encountered one situation where
checkstyle is reporting problem

Code snippet is

public void foo(final String xmlString,VOCollectionBuilder
builder)
{
if ( null == builder )
{
builder = new VOCollectionBuilder();
}

}

Its generates parameter builder should be final.
But if u see inside if condition parameter is modified.
Am i missing something or is this a problem.
Thanks a lot
Amey

Discussion

  • Logged In: YES
    user_id=746148

    I this it's a FinalParameters check who generates this error.
    It just check that ALL parameters are final.
    If you do not need such check remove it from your configuration,
    if you do need such check, but not for this method you can
    try to
    filter it using Filter API (see SuppressionFilter)

    Please confirm that this works for you, so we can close this
    bug.
    Thanks in advance.

     
  • Amey
    Amey
    2004-10-22

    Logged In: YES
    user_id=1142993

    Hi
    We are currently disabling this final check.But from
    enhancement point of view,checkstyle do some more analysis
    into method code and not just checking of method
    parameters are final or not.
    Anyways thanks a lot for immediate answer
    Amey

     
  • Logged In: YES
    user_id=746148

    The check does exactly what it should do, and shouldn't be
    changed in the way you suggested. It doesn't check that
    a parameter could be made final, it suggestes make all
    parameters final.
    Here is quote from documetation for this check:
    Rationale: Changing the value of parameters during the
    execution of the method's algorithm can be confusing and
    should be avoided. A great way to let the Java compiler
    prevent this coding style is to declare parameters final.

    So, if you disagree with this rationale then you just shoudn't
    use it.