google / google/error-prone

`StringCaseLocaleUsage ` false negative for `@VisibleForTesting` annotation

Open
#5,776 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

### Error Prone version

2.49.0 (error_prone_core)

### Check name

StringCaseLocaleUsage

### Description

`StringCaseLocaleUsage` should report any call to `String#toLowerCase()` or `toUpperCase()` without a `Locale` argument. In the reproducer, both classes contain the same offending call (`trimmed.toLowerCase()`), but Error Prone only reports one of them. Changing the enclosing method to `public` and adding `@VisibleForTesting` should not affect an expression-level check, so the missing report is a false negative.

### Reproducer

```java
// BEFORE — StringCaseLocaleUsage is reported (expected)
package demo.before;

public class DataProcessor {
String normalize(String value) {
String trimmed = value.trim();
return trimmed.toLowerCase(); // flagged
}
}
```

```java
// AFTER — StringCaseLocaleUsage is NOT reported (unexpected)
package demo.after;

import com.google.common.annotations.VisibleForTesting;

public class DataProcessor {
@VisibleForTesting
public String normalize(String value) {
String trimmed = value.trim();
return trimmed.toLowerCase(); // NOT flagged
}
}
```

Both files are compiled with the same Error Prone 2.49.0 configuration and default check severities. The only differences between them are the package name, the method's access modifier (`String` → `public String`), and the `@VisibleForTesting` annotation — none of which change the semantics of the `toLowerCase()` call.

### Expected behavior

`StringCaseLocaleUsage` is reported on the `trimmed.toLowerCase()` call in both versions, since both invoke `String#toLowerCase()` without a `Locale`.

### Actual behavior

`StringCaseLocaleUsage` is reported only in the BEFORE version; the identical call in the AFTER version (public method annotated `@VisibleForTesting`) is not flagged.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.