0

Android: Add Error Prone warning against Java stream() apis

And minor clarifying tweaks to style guide wrt streams

Bug: 344943957
Change-Id: I90b976866c8f3f71826459b7d3097692e1f533b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6042674
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1388426}
This commit is contained in:
Andrew Grieve
2024-11-26 20:20:34 +00:00
committed by Chromium LUCI CQ
parent 7ad9bf26b7
commit e910d272c0
6 changed files with 58 additions and 8 deletions
build/android/gyp
chrome/browser/tabmodel/android/java/src/org/chromium/chrome/browser/tabmodel
styleguide/java
tools/android/errorprone_plugin
BUILD.gnOWNERS
src
org
chromium
tools
errorprone

@ -261,16 +261,18 @@ Log.d(TAG, "There are %d cats", countCats()); // countCats() not stripped.
### Streams
Most uses of [Java streams] are discouraged. If you can write your code as an
explicit loop, then do so. The primary reason for this guidance is because the
lambdas (and method references) needed for streams almost always result in
larger binary size ([example](https://chromium-review.googlesource.com/c/chromium/src/+/4329952).
Using [Java streams] outside of tests is strongly discouraged. If you can write
your code as an explicit loop, then do so. The primary reason for this guidance
is because the lambdas (and method references) needed for streams almost always
result in larger binary size than their loop equivalents (see
[crbug.com/344943957] for examples).
The `parallel()` and `parallelStream()` APIs are simpler than their loop
equivalents, but are are currently banned due to a lack of a compelling use case
in Chrome. If you find one, please discuss on `java@chromium.org`.
equivalents, but are banned due to a lack of a compelling use case in Chrome.
If you find one, please discuss on `java@chromium.org`.
[Java streams]: https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html
[crbug.com/344943957]: https://crbug.com/344943957
### AndroidX Annotations {#annotations}