From 5b60a42eb9d3cd7a2073d549bd0cb833f5a7e7e9 Mon Sep 17 00:00:00 2001 From: cpovirk Date: Tue, 30 May 2023 11:56:29 -0700 Subject: [PATCH] Target Java 8: - Set `-source 8 -target 8`. We already have a depencdency on `guava-android`, which began requiring Java 8 a while back, so we might as well unlock the ability to use Java 8 language features ourselves. (I also found I had to set `-source 8` in `maven-javadoc-plugin` to prevent it from trying to pass a `--module-path`, which leads to problems with our usages of `@NullableDecl`, which isn't in a module. That's probably unrelated: We probably just haven't run Javadoc since some `maven-javadoc-plugin` upgrade.) Work toward https://github.com/google/jimfs/pull/240, and fixes https://github.com/google/jimfs/issues/229 - Don't refer to Java 9+ `ByteBuffer` methods, and set up Error Prone enforcement of future such mistakes. Compare https://github.com/google/guava/pull/6334. Fixes https://github.com/google/jimfs/issues/113 RELNOTES=Officially dropped support for Java 7, and restored accidentally dropped support for Java 8. PiperOrigin-RevId: 536468340 --- README.md | 2 +- .../common/jimfs/Java8Compatibility.java | 29 +++++++++++++++++++ .../com/google/common/jimfs/RegularFile.java | 4 +-- pom.xml | 5 ++-- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 jimfs/src/main/java/com/google/common/jimfs/Java8Compatibility.java diff --git a/README.md b/README.md index 9cfe0dfe..f14e9ca6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Jimfs ===== -Jimfs is an in-memory file system for Java 7 and above, implementing the +Jimfs is an in-memory file system for Java 8 and above, implementing the [java.nio.file](http://docs.oracle.com/javase/7/docs/api/java/nio/file/package-summary.html) abstract file system APIs. diff --git a/jimfs/src/main/java/com/google/common/jimfs/Java8Compatibility.java b/jimfs/src/main/java/com/google/common/jimfs/Java8Compatibility.java new file mode 100644 index 00000000..522f5444 --- /dev/null +++ b/jimfs/src/main/java/com/google/common/jimfs/Java8Compatibility.java @@ -0,0 +1,29 @@ +/* + * Copyright 2020 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.common.jimfs; + +import java.nio.Buffer; + +/** + * Wrappers around {@link Buffer} methods that are covariantly overridden in Java 9+. See + * https://github.com/google/guava/issues/3990 + */ +final class Java8Compatibility { + static void clear(Buffer b) { + b.clear(); + } + + private Java8Compatibility() {} +} diff --git a/jimfs/src/main/java/com/google/common/jimfs/RegularFile.java b/jimfs/src/main/java/com/google/common/jimfs/RegularFile.java index f83b80d9..57ea576d 100644 --- a/jimfs/src/main/java/com/google/common/jimfs/RegularFile.java +++ b/jimfs/src/main/java/com/google/common/jimfs/RegularFile.java @@ -579,7 +579,7 @@ public long transferTo(long pos, long count, WritableByteChannel dest) throws IO while (buf.hasRemaining()) { remaining -= dest.write(buf); } - buf.clear(); + Java8Compatibility.clear(buf); while (remaining > 0) { int index = ++blockIndex; @@ -589,7 +589,7 @@ public long transferTo(long pos, long count, WritableByteChannel dest) throws IO while (buf.hasRemaining()) { remaining -= dest.write(buf); } - buf.clear(); + Java8Compatibility.clear(buf); } } diff --git a/pom.xml b/pom.xml index 74c6f857..4a74fd2f 100644 --- a/pom.xml +++ b/pom.xml @@ -96,7 +96,7 @@ UTF-8 1.0.1 1.2.1 - 1.7 + 1.8 31.1-android -XDcompilePolicy=simple - -Xplugin:ErrorProne + -Xplugin:ErrorProne -Xep:Java8ApiChecker:ERROR