score:1

kinda dumb error, but here is the easy fix i put in my setters to fix it:

was:

public void setname(string name) {
  this.name = name;
}

updated:

public void setname(string val) {
  this.name = val;
}

score:6

just change ur param name in ur method

private static void setserverurl(final string serverurl) {
utility.serverurl = serverurl;
}

to

private static void setserverurl(final string serverurlxyz) {
utility.serverurl = serverurlxyz;
}

enjoy...

jigar patel

score:7

i resolved it by disabling it in eclipse. i was looking for how to do that when i landed on this page. i didn't find the answer in top 10 google query so i had to figure it out the hard way. for someone who is looking for that, here is how i did it:

open

eclipse>preferences>checkstyle

find the checkstyle configuration you are using (you might have set that or your are using default in which case its a better idea to create a copy of your own and then edit that). select that and then click the configure button on the right side. find the following config in the list:

coding problems>hidden field

open the configuration (there is button called 'open' in the ui).

unselect 'parameter declaration'. click ok then click ok and then click ok.

score:11

the parameter and the static field have the same name. just rename one of them. some people follow a naming convention that prefixes all parameters with p. then you would have serverurl as field name and pserverurl as parameter name. or you could simply turn off the check.

score:51

i think it is very common in constructors and setters that the set field name is the same as the setter parameter name. this is why i recommend this configuration:

<module name="hiddenfield" >
    <property name="ignoresetter" value="true" />
    <property name="ignoreconstructorparameter" value="true" />
</module>

this way the other hidden field cases are still forbidden.

score:60

there is already a variable defined serverurl which is available to this method (additional to the formal parameter you are accepting). this is called "shadowing".

i think most java programmers turn this check off, because it's not really that confusing.

for example, this would trigger the error:

public class foo {
  private int bar = 0;

  public void somemethod(int bar) {
    // there are two bars!  all references in this method will use the parameter bar,
    // unless they are explicitly prefixed with 'this'.
    this.bar = bar;
  }
}

Related Query

More Query from same tag