NamedParameters and anonymous classes
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
Take the following code:
```java
class Foo {
Foo(Demo common) {}
}
class Demo {
Foo bar() {
return new Foo(this) {
// A comment anywhere in the anonymous class
// body that randomly happens to use the name
// of one of the constructor parameters, in this
// case `common`, results in a NamedParameters error.
};
}
}
```
Running error-prone 2.1.0 results in:
```
Demo.java:7: warning: [NamedParameters] Parameters with incorrectly labelled arguments: `// case `common`, results in a NamedParameters error.` should be `/* common= */ `
return new Foo(this) {
^
(see http://errorprone.info/bugpattern/NamedParameters)
Did you mean 'return new Foo(/* common= */this) {'?
1 warning
```
I wouldn't expect a warning about the usage of a parameter name somewhere in the body of an anonymous class. Maybe a regex should terminate on the `{` that begins the class body?
I ran into this when upgrading error-prone to 2.1.0 and running it on the Checker Framework sources.
(Also, the NamedParameters documentation is rather empty: http://errorprone.info/bugpattern/NamedParameters)
Contributor guide
Assessment
This issue has not been assessed yet.