0

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

This reverts commit 8ff33dbc1d.

Reason for reland: Internal fix landed

Original change's description:
> Revert "Android: Add Error Prone warning against Java stream() apis"
>
> This reverts commit e910d272c0.
>
> Reason for revert: crbug.com/344943957#comment13
>
> Original change's description:
> > 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}
>
> Bug: 344943957
> Change-Id: Ib9b3d8db9f47383eaced5192a15e7cac6427da35
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6051419
> Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
> Auto-Submit: Keigo Oka <oka@chromium.org>
> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Reviewed-by: Andrew Grieve <agrieve@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1388467}

Bug: 344943957
Change-Id: I6668c182aa455972684e6863925c498f494fd11f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6055458
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1389041}
This commit is contained in:
Andrew Grieve
2024-11-27 21:00:13 +00:00
committed by Chromium LUCI CQ
parent babffaac09
commit 31928c9844
6 changed files with 72 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,32 @@ 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`.
Use of `stream()` without a lambda / method reference is allowed. E.g.:
```java
@SuppressWarnings("NoStreams")
private static List<Integer> boxInts(int[] arr) {
return Arrays.stream(arr).boxed().collect(Collectors.toList());
}
@SuppressWarnings("NoStreams")
private static List<String> readLines(BufferedReader bufferedReader) {
return bufferedReader.lines().collect(Collectors.toList());
}
```
[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}