google / google/error-prone

AvoidCommonTypeNames false positives when using --release

Open
#5,957 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

Using Error Prone 2.50 and compiling with the `--release` option, the AvoidCommonTypeNames checker is sometimes including java.lang.X.Y classes, when really there is no reason to warn about clashes with those since they are not imported automatically with their undotted name.

Example (using Java 25 with --release 25):

```
Info.java:1: warning: [AvoidCommonTypeNames] Info clashes with java.lang.ProcessHandle.Info
class Info {}
^
(see https://errorprone.info/bugpattern/AvoidCommonTypeNames)
```

I think this was introduced by https://github.com/google/error-prone/commit/924cb63735c9e6e44b0362b8ed9fbcfdf1dc8d9d/. The `getSymbols` call sometimes includes inner classes that `getSymbolsByName` does not, varying on both the Java version and the --release version:

Java version | --release version | Classes
-- | -- | --
21 | 8 | Character.UnicodeScript
25 | 8 | Character.UnicodeScript
21 | 11 | StackWalker.StackFrame
25 | 11 | none
21 | 17 | StackWalker.StackFrame, Thread.State, Character.UnicodeScript
25 | 17 | System.LoggerFinder, Character.UnicodeScript
21 | 21 | none
25 | 21 | System.LoggerFinder, ProcessHandle.Info
25 | 25 | ProcessHandle.Info

Contributor guide

Open the contributing guide

Research direction

Start at the AvoidCommonTypeNames checker and reproduce the reported examples with Java 21/25 and the listed --release versions, comparing getSymbols with getSymbolsByName. Done means dotted inner classes such as ProcessHandle.Info no longer produce clashes for undotted declarations, while valid common-type-name warnings remain covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.