You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, first time writing an issue, so bear with me as I try to explain it...
Let's start with the error:
[ERROR] ../generated/Item.java:119:55: 'name' hides a field. [HiddenField]
When I tried to build my project using maven, the eclipse checkstyle plugin flagged every builder method with a HiddenField error. I understand this error is cause by 'variable shadowing'. It doesn't cause any compilation issues. It is also possible to add a rule in the checkstyle for setters to ignore parameter names that are identical to instance variables, so long as the method name begins with 'set'. For builder methods however, it is not possible as they begin with 'with':
The checkstyle docs say it is possible to add a rule to ignore the formatting of parameters but not method names. Which I tried to use initially but of course that entails adding every parameter as a rule.
I was able to make my project build by removing every HiddenField property in the checkstyle.xml file.
Alternatively, I added SuppressWarnings filter to the checkstyle.xml and added the annotation to each of the classes that had HiddenField errors like so:
@SuppressWarnings({"HiddenField"})
I think it would be ideal if the builder method parameters were prefixed with 'p' or 'new' so that checkstyle files don't have to be tampered with and it's possible to stick with the default coding conventions.
We won't update the code we're generating based on rules like this I'm afraid. I don't think the alternative is easier to read (it's best if those withXXX methods are similar to over accessors) but also there are other checkstyle warnings that we will no doubt have.
The solution to this is to reinstate the @Generated annotation (#835), because this indicates to static analysis libraries to ignore these classes when examining the code. for now I suggest you generate these source files to a src folder, or package, you can tell checkstyle to ignore.
Hi, first time writing an issue, so bear with me as I try to explain it...
Let's start with the error:
[ERROR] ../generated/Item.java:119:55: 'name' hides a field. [HiddenField]
When I tried to build my project using maven, the eclipse checkstyle plugin flagged every builder method with a HiddenField error. I understand this error is cause by 'variable shadowing'. It doesn't cause any compilation issues. It is also possible to add a rule in the checkstyle for setters to ignore parameter names that are identical to instance variables, so long as the method name begins with 'set'. For builder methods however, it is not possible as they begin with 'with':
private String name;
public Item withName(final String name) { this.name = name; return this; }
The checkstyle docs say it is possible to add a rule to ignore the formatting of parameters but not method names. Which I tried to use initially but of course that entails adding every parameter as a rule.
I was able to make my project build by removing every HiddenField property in the checkstyle.xml file.
Alternatively, I added SuppressWarnings filter to the checkstyle.xml and added the annotation to each of the classes that had HiddenField errors like so:
@SuppressWarnings({"HiddenField"})
I think it would be ideal if the builder method parameters were prefixed with 'p' or 'new' so that checkstyle files don't have to be tampered with and it's possible to stick with the default coding conventions.
e.g.:
public Item withName(final String newName) { this.name = newName; return this; }
The text was updated successfully, but these errors were encountered: