google / google/error-prone

False positive for infinite recursion check on overloaded methods

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

Description

The [infinite recursion check](https://errorprone.info/bugpattern/InfiniteRecursion) incorrectly reports infinite recursion in the following code:

```
protected int findDirectoryGraphDistance(SourceFile a, SourceFile b) {
return findDirectoryGraphDistance(a.getPath(), b.getPath());
}

protected int findDirectoryGraphDistance(FilePath a, FilePath b) {
return 1234;
}
```

This is not even recursion, it's just a method calling another overloaded method with the same name but different types.

I'm not sure why this happens, but one of the reasons could be that `SourceFile` is part of our own code base while `FilePath` is a library class. That might influence ErrorProne's ability to resolve parameter types.

Sure, the quick fix would be to either rename one of the methods or to add a `@SuppressWarnings`, but for other users it would be nice if we can avoid this false positive altogether.

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.