From 6405852bbf453b14d097b8ec3bcae494334b357d Mon Sep 17 00:00:00 2001 From: cpovirk Date: Thu, 23 Feb 2023 10:54:25 -0800 Subject: [PATCH] Enable [Java8ApiChecker](https://errorprone.info/bugpattern/Java8ApiChecker) for Maven builds. We already have it on for our builds inside Google, but Maven checking provides an additional line of defense against https://github.com/google/guava/issues/3990. Because this CL enables checking for our _tests_, too (which is hard not to do, as discussed in the existing `pom.xml` comment about NullArgumentForNonNullParameter), I had to edit a couple benchmarks to avoid using what are _in a limited sense_ "Java 9+ APIs." They wouldn't be practical problems, though. RELNOTES=n/a PiperOrigin-RevId: 511830560 --- .../benchmark/com/google/common/hash/ChecksumBenchmark.java | 4 ++-- .../com/google/common/io/CharStreamsCopyBenchmark.java | 5 +++-- android/pom.xml | 2 +- .../benchmark/com/google/common/hash/ChecksumBenchmark.java | 4 ++-- .../com/google/common/io/CharStreamsCopyBenchmark.java | 5 +++-- pom.xml | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/android/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java b/android/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java index 0fa3e2a88ebd..4bb0031dc2b0 100644 --- a/android/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java +++ b/android/guava-tests/benchmark/com/google/common/hash/ChecksumBenchmark.java @@ -63,7 +63,7 @@ byte crc32Checksum(int reps) throws Exception { byte result = 0x01; for (int i = 0; i < reps; i++) { CRC32 checksum = new CRC32(); - checksum.update(testBytes); + checksum.update(testBytes, 0, testBytes.length); result = (byte) (result ^ checksum.getValue()); } return result; @@ -81,7 +81,7 @@ byte adler32Checksum(int reps) throws Exception { byte result = 0x01; for (int i = 0; i < reps; i++) { Adler32 checksum = new Adler32(); - checksum.update(testBytes); + checksum.update(testBytes, 0, testBytes.length); result = (byte) (result ^ checksum.getValue()); } return result; diff --git a/android/guava-tests/benchmark/com/google/common/io/CharStreamsCopyBenchmark.java b/android/guava-tests/benchmark/com/google/common/io/CharStreamsCopyBenchmark.java index 52532bb61ac2..0b9c87489c67 100644 --- a/android/guava-tests/benchmark/com/google/common/io/CharStreamsCopyBenchmark.java +++ b/android/guava-tests/benchmark/com/google/common/io/CharStreamsCopyBenchmark.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; +import java.nio.Buffer; import java.nio.CharBuffer; import java.util.Random; @@ -40,10 +41,10 @@ long copy(Readable from, Appendable to) throws IOException { CharBuffer buf = CharStreams.createBuffer(); long total = 0; while (from.read(buf) != -1) { - buf.flip(); + ((Buffer) buf).flip(); to.append(buf); total += buf.remaining(); - buf.clear(); + ((Buffer) buf).clear(); } return total; } diff --git a/android/pom.xml b/android/pom.xml index 5ca3e868029b..f1e8a2596ddd 100644 --- a/android/pom.xml +++ b/android/pom.xml @@ -508,7 +508,7 @@ be passed as part of the same as -Xplugin:ErrorProne, and I gave up trying to figure out how to do that for test compilation only. --> - -Xplugin:ErrorProne -Xep:NullArgumentForNonNullParameter:OFF + -Xplugin:ErrorProne -Xep:NullArgumentForNonNullParameter:OFF -Xep:Java8ApiChecker:ERROR - -Xplugin:ErrorProne -Xep:NullArgumentForNonNullParameter:OFF + -Xplugin:ErrorProne -Xep:NullArgumentForNonNullParameter:OFF -Xep:Java8ApiChecker:ERROR