FieldCanBeLocal false positive for record with constructor
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
I have the following record as an inner class
```java
public record DatasetProductIdentifiersPair(
Product.Id productId,
@Nullable String identifier
)
{
public DatasetProductIdentifiersPair(
final Product.Id productId,
@Nullable final String identifier
)
{
this.productId = Objects.requireNonNull(productId, "productId must not be null");
this.identifier = identifier;
}
}
```
when I Compile, error prone reports incorrectly
```
[WARNING] ProductRepository.java:[300,43] [FieldCanBeLocal] This field can be replaced with a local variable in the methods that use it.
(see https://errorprone.info/bugpattern/FieldCanBeLocal)
Did you mean ','?
[WARNING] ProductRepository.java:[301,26] [FieldCanBeLocal] This field can be replaced with a local variable in the methods that use it.
(see https://errorprone.info/bugpattern/FieldCanBeLocal)
Did you mean to remove this line?
```
If I remove the constructor, the code compiles... it also compiles when I replace the parametrized constructor with
```java
public DatasetProductIdentifiersPair
{
Objects.requireNonNull(productId, "productId must not be null");
}
```
but IMHO it should also compile with my original code
Contributor guide
Assessment
This issue has not been assessed yet.