google / google/error-prone

A check for (a + b) / 2

Open
#116 1 comment 0 reactions 0 assignees View on GitHub
migrated Priority-Medium Type-Defect Type-NewCheck
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

_[Original issue](https://code.google.com/p/error-prone/issues/detail?id=116) created by **kevinb@google.com** on 2013-04-04 at 03:45 PM_

---

Fact: _some_ percentage of all occurrences of "(a + b) / 2" out there are bugs, or bugs waiting to happen.
(http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html)

Unfortunately, there's no reasonable fix we can suggest that is guaranteed to work for _all_ possible values of a and b... except Guava's IntMath.mean(a, b) / LongMath.mean(a, b) methods.

If there is ever a place in error-prone for "checks for which the fix _requires_ Guava", then it might be worth having a check that forces users of "(a + b) / 2" to change to use mean(). Most of those users probably weren't vulnerable to the bug, but we can't tell which they are.

If we don't do this, we'll probably just have to give up on ever catching that bug, and we will sadly probably give up on these Guava methods entirely, because literally NO ONE is using them (why would they? They already know how to get the mean of two numbers!).

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.