diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml
index adb6b6fe0d..9d06386f31 100644
--- a/bootstrap/pom.xml
+++ b/bootstrap/pom.xml
@@ -50,6 +50,7 @@
javax.inject
javax.inject
+ runtime
diff --git a/concurrent/pom.xml b/concurrent/pom.xml
index 74753b1749..de0dcd3bd5 100644
--- a/concurrent/pom.xml
+++ b/concurrent/pom.xml
@@ -17,7 +17,7 @@
- io.airlift
+ com.facebook.airlift
units
@@ -67,6 +67,12 @@
jmh-generator-annprocess
test
+
+
+ org.gaul
+ modernizer-maven-annotations
+ test
+
diff --git a/concurrent/src/main/java/com/facebook/airlift/concurrent/MoreFutures.java b/concurrent/src/main/java/com/facebook/airlift/concurrent/MoreFutures.java
index 0a6f23a56c..c11e3a90e3 100644
--- a/concurrent/src/main/java/com/facebook/airlift/concurrent/MoreFutures.java
+++ b/concurrent/src/main/java/com/facebook/airlift/concurrent/MoreFutures.java
@@ -1,5 +1,6 @@
package com.facebook.airlift.concurrent;
+import com.google.common.collect.Streams;
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.FluentFuture;
import com.google.common.util.concurrent.FutureCallback;
@@ -29,15 +30,14 @@
import java.util.function.Function;
import java.util.stream.Collectors;
-import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Throwables.propagateIfPossible;
import static com.google.common.base.Throwables.throwIfInstanceOf;
-import static com.google.common.collect.Iterables.isEmpty;
import static com.google.common.util.concurrent.Futures.immediateFailedFuture;
import static com.google.common.util.concurrent.Futures.immediateFuture;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static java.util.Objects.requireNonNull;
+import static java.util.Objects.requireNonNullElse;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
public final class MoreFutures
@@ -87,7 +87,7 @@ public void onFailure(Throwable t)
public static Throwable unwrapCompletionException(Throwable throwable)
{
if (throwable instanceof CompletionException) {
- return firstNonNull(throwable.getCause(), throwable);
+ return requireNonNullElse(throwable.getCause(), throwable);
}
return throwable;
}
@@ -277,7 +277,7 @@ public static void checkSuccess(Future> future, String errorMessage)
public static ListenableFuture whenAnyComplete(Iterable extends ListenableFuture extends V>> futures)
{
requireNonNull(futures, "futures is null");
- checkArgument(!isEmpty(futures), "futures is empty");
+ checkArgument(Streams.stream(futures).findAny().isPresent(), "futures is empty");
ExtendedSettableFuture firstCompletedFuture = ExtendedSettableFuture.create();
for (ListenableFuture extends V> future : futures) {
@@ -298,7 +298,7 @@ public static ListenableFuture whenAnyComplete(Iterable extends Listena
public static ListenableFuture whenAnyCompleteCancelOthers(Iterable extends ListenableFuture extends V>> futures)
{
requireNonNull(futures, "futures is null");
- checkArgument(!isEmpty(futures), "futures is empty");
+ checkArgument(Streams.stream(futures).findAny().isPresent(), "futures is empty");
// wait for the first task to unblock and then cancel all futures to free up resources
ListenableFuture anyComplete = whenAnyComplete(futures);
@@ -332,7 +332,7 @@ public static CompletableFuture firstCompletedFuture(Iterable extends C
public static CompletableFuture firstCompletedFuture(Iterable extends CompletionStage extends V>> futures, boolean propagateCancel)
{
requireNonNull(futures, "futures is null");
- checkArgument(!isEmpty(futures), "futures is empty");
+ checkArgument(Streams.stream(futures).findAny().isPresent(), "futures is empty");
CompletableFuture future = new CompletableFuture<>();
for (CompletionStage extends V> stage : futures) {
diff --git a/concurrent/src/main/java/com/facebook/airlift/concurrent/SetThreadName.java b/concurrent/src/main/java/com/facebook/airlift/concurrent/SetThreadName.java
index d8bf33578f..c1108d1231 100644
--- a/concurrent/src/main/java/com/facebook/airlift/concurrent/SetThreadName.java
+++ b/concurrent/src/main/java/com/facebook/airlift/concurrent/SetThreadName.java
@@ -26,7 +26,7 @@ public SetThreadName(String format, Object... args)
{
requireNonNull(format, "format is null");
originalThreadName = Thread.currentThread().getName();
- Thread.currentThread().setName(String.format(format, args) + "-" + Thread.currentThread().getId());
+ Thread.currentThread().setName(String.format(format, args) + "-" + Thread.currentThread().threadId());
}
@Override
diff --git a/concurrent/src/test/java/com/facebook/airlift/concurrent/TestMoreFutures.java b/concurrent/src/test/java/com/facebook/airlift/concurrent/TestMoreFutures.java
index 27cba2e41a..725b0aee8f 100644
--- a/concurrent/src/test/java/com/facebook/airlift/concurrent/TestMoreFutures.java
+++ b/concurrent/src/test/java/com/facebook/airlift/concurrent/TestMoreFutures.java
@@ -4,6 +4,7 @@
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import io.airlift.units.Duration;
+import org.gaul.modernizer_maven_annotations.SuppressModernizer;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
@@ -55,6 +56,7 @@
import static org.testng.Assert.fail;
@SuppressWarnings("deprecation")
+@SuppressModernizer
public class TestMoreFutures
{
private final ScheduledExecutorService executorService = newSingleThreadScheduledExecutor(daemonThreadsNamed("test-%s"));
diff --git a/configuration/pom.xml b/configuration/pom.xml
index e88b1ea712..c44c9616e8 100644
--- a/configuration/pom.xml
+++ b/configuration/pom.xml
@@ -13,6 +13,9 @@
${project.parent.basedir}
+
+ --add-opens java.base/java.lang=ALL-UNNAMED
+
diff --git a/configuration/src/main/java/com/facebook/airlift/configuration/ConfigurationBinding.java b/configuration/src/main/java/com/facebook/airlift/configuration/ConfigurationBinding.java
index 6aa9720338..5e64de3407 100644
--- a/configuration/src/main/java/com/facebook/airlift/configuration/ConfigurationBinding.java
+++ b/configuration/src/main/java/com/facebook/airlift/configuration/ConfigurationBinding.java
@@ -19,7 +19,7 @@ public ConfigurationBinding(Key key, Class configClass, Optional p
requireNonNull(key, "key");
requireNonNull(configClass, "configClass");
requireNonNull(prefix, "prefix is null");
- checkArgument(!prefix.isPresent() || !prefix.get().isEmpty(), "prefix is empty");
+ prefix.ifPresent(str -> checkArgument(!str.isEmpty(), "prefix is empty"));
this.key = key;
this.configClass = configClass;
diff --git a/configuration/src/test/java/com/facebook/airlift/configuration/TestConfigurationInspector.java b/configuration/src/test/java/com/facebook/airlift/configuration/TestConfigurationInspector.java
index 1b3c50b177..6f93f8a9fe 100644
--- a/configuration/src/test/java/com/facebook/airlift/configuration/TestConfigurationInspector.java
+++ b/configuration/src/test/java/com/facebook/airlift/configuration/TestConfigurationInspector.java
@@ -12,7 +12,7 @@
import static com.facebook.airlift.configuration.ConfigBinder.configBinder;
import static com.google.common.collect.ImmutableList.toImmutableList;
-import static com.google.common.collect.Iterables.getOnlyElement;
+import static com.google.common.collect.MoreCollectors.onlyElement;
import static org.testng.Assert.assertEquals;
public class TestConfigurationInspector
@@ -42,7 +42,7 @@ private ConfigRecord> getConfigRecord()
Map properties = ImmutableMap.of("stringValue", "string");
ConfigurationFactory configurationFactory = new ConfigurationFactory(properties);
configurationFactory.registerConfigurationClasses(binder -> configBinder(binder).bindConfig(ConfigWithOptionalValue.class));
- return getOnlyElement(new ConfigurationInspector().inspect(configurationFactory));
+ return new ConfigurationInspector().inspect(configurationFactory).stream().collect(onlyElement());
}
public static class ConfigWithOptionalValue
diff --git a/dbpool/pom.xml b/dbpool/pom.xml
index e3df6ef595..65e03479dd 100644
--- a/dbpool/pom.xml
+++ b/dbpool/pom.xml
@@ -13,6 +13,9 @@
${project.parent.basedir}
+
+ --add-opens java.base/java.lang=ALL-UNNAMED
+
@@ -32,7 +35,7 @@
- io.airlift
+ com.facebook.airlift
units
diff --git a/dbpool/src/main/java/com/facebook/airlift/dbpool/H2EmbeddedDataSource.java b/dbpool/src/main/java/com/facebook/airlift/dbpool/H2EmbeddedDataSource.java
index a0ffdce1a4..59220963f1 100644
--- a/dbpool/src/main/java/com/facebook/airlift/dbpool/H2EmbeddedDataSource.java
+++ b/dbpool/src/main/java/com/facebook/airlift/dbpool/H2EmbeddedDataSource.java
@@ -17,7 +17,6 @@
import com.facebook.airlift.dbpool.H2EmbeddedDataSourceConfig.Cipher;
import com.google.common.io.Resources;
-import com.google.common.primitives.Ints;
import org.h2.jdbcx.JdbcDataSource;
import org.h2.util.ScriptReader;
@@ -32,6 +31,7 @@
import java.sql.SQLException;
import java.sql.Statement;
+import static java.lang.Math.toIntExact;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -73,7 +73,7 @@ public H2EmbeddedDataSource(H2EmbeddedDataSourceConfig config)
else {
dataSource.setPassword("");
}
- dataSource.setLoginTimeout(Ints.checkedCast(config.getMaxConnectionWait().roundTo(SECONDS)));
+ dataSource.setLoginTimeout(toIntExact(config.getMaxConnectionWait().roundTo(SECONDS)));
// connect to database and initialize database
Connection connection = getConnection();
diff --git a/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSource.java b/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSource.java
index 734fe05d84..40fc262bc5 100644
--- a/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSource.java
+++ b/dbpool/src/main/java/com/facebook/airlift/dbpool/ManagedDataSource.java
@@ -15,7 +15,6 @@
*/
package com.facebook.airlift.dbpool;
-import com.google.common.primitives.Ints;
import io.airlift.units.Duration;
import org.weakref.jmx.Flatten;
import org.weakref.jmx.Managed;
@@ -36,6 +35,7 @@
import static io.airlift.units.Duration.nanosSince;
import static java.lang.Math.ceil;
+import static java.lang.Math.toIntExact;
public abstract class ManagedDataSource
implements DataSource
@@ -53,7 +53,7 @@ protected ManagedDataSource(int maxConnections, Duration maxConnectionWait)
throw new NullPointerException("maxConnectionWait is null");
}
semaphore = new ManagedSemaphore(maxConnections);
- maxConnectionWaitMillis.set(Ints.checkedCast(maxConnectionWait.toMillis()));
+ maxConnectionWaitMillis.set(toIntExact(maxConnectionWait.toMillis()));
}
@Override
@@ -143,7 +143,7 @@ public void setMaxConnectionWaitMillis(Duration maxConnectionWait)
throw new NullPointerException("maxConnectionWait is null");
}
- int millis = Ints.checkedCast(maxConnectionWait.toMillis());
+ int millis = toIntExact(maxConnectionWait.toMillis());
if (millis < 1) {
throw new IllegalArgumentException("maxConnectionWait must be greater than 1 millisecond");
}
diff --git a/discovery/pom.xml b/discovery/pom.xml
index 0be459fcac..54484e1162 100644
--- a/discovery/pom.xml
+++ b/discovery/pom.xml
@@ -12,6 +12,9 @@
${project.parent.basedir}
+
+ --add-opens java.base/java.lang=ALL-UNNAMED
+
@@ -31,7 +34,7 @@
- io.airlift
+ com.facebook.airlift
units
diff --git a/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceTypeImpl.java b/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceTypeImpl.java
index fc69f3ed43..32e5ec2348 100644
--- a/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceTypeImpl.java
+++ b/discovery/src/main/java/com/facebook/airlift/discovery/client/ServiceTypeImpl.java
@@ -39,7 +39,7 @@ public String value()
public String toString()
{
- return String.format("@%s(value=%s)", ServiceType.class.getName(), Annotations.memberValueString(value));
+ return String.format("@%s(%s)", ServiceType.class.getName(), Annotations.memberValueString(value));
}
@Override
diff --git a/discovery/src/main/java/com/facebook/airlift/discovery/client/testing/StaticServiceSelector.java b/discovery/src/main/java/com/facebook/airlift/discovery/client/testing/StaticServiceSelector.java
index 2fe1685792..79f2bdc3f2 100644
--- a/discovery/src/main/java/com/facebook/airlift/discovery/client/testing/StaticServiceSelector.java
+++ b/discovery/src/main/java/com/facebook/airlift/discovery/client/testing/StaticServiceSelector.java
@@ -19,7 +19,7 @@
import com.facebook.airlift.discovery.client.ServiceSelector;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
+import com.google.common.collect.Streams;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
@@ -44,7 +44,7 @@ public StaticServiceSelector(Iterable serviceDescriptors)
{
requireNonNull(serviceDescriptors, "serviceDescriptors is null");
- ServiceDescriptor serviceDescriptor = Iterables.getFirst(serviceDescriptors, null);
+ ServiceDescriptor serviceDescriptor = Streams.stream(serviceDescriptors).findFirst().orElse(null);
if (serviceDescriptor != null) {
this.type = serviceDescriptor.getType();
this.pool = serviceDescriptor.getPool();
diff --git a/discovery/src/test/java/com/facebook/airlift/discovery/client/AbstractTestDiscoveryModule.java b/discovery/src/test/java/com/facebook/airlift/discovery/client/AbstractTestDiscoveryModule.java
index d691486980..11c6c9fdcf 100644
--- a/discovery/src/test/java/com/facebook/airlift/discovery/client/AbstractTestDiscoveryModule.java
+++ b/discovery/src/test/java/com/facebook/airlift/discovery/client/AbstractTestDiscoveryModule.java
@@ -31,7 +31,7 @@
import static com.facebook.airlift.discovery.client.DiscoveryBinder.discoveryBinder;
import static com.facebook.airlift.discovery.client.ServiceTypes.serviceType;
-import static com.google.common.collect.Iterables.getOnlyElement;
+import static com.google.common.collect.MoreCollectors.onlyElement;
import static java.util.Objects.requireNonNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@@ -97,10 +97,10 @@ public void testMerging()
});
HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple")));
- assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("http://127.0.0.1:4444"));
+ assertEquals(selector.selectHttpService().stream().collect(onlyElement()), URI.create("http://127.0.0.1:4444"));
selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("banana")));
- assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("http://127.0.0.1:4444"));
+ assertEquals(selector.selectHttpService().stream().collect(onlyElement()), URI.create("http://127.0.0.1:4444"));
selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("carrot")));
assertTrue(selector.selectHttpService().isEmpty());
diff --git a/discovery/src/test/java/com/facebook/airlift/discovery/client/TestAnnouncement.java b/discovery/src/test/java/com/facebook/airlift/discovery/client/TestAnnouncement.java
index 1d52107387..867b5d6e8c 100644
--- a/discovery/src/test/java/com/facebook/airlift/discovery/client/TestAnnouncement.java
+++ b/discovery/src/test/java/com/facebook/airlift/discovery/client/TestAnnouncement.java
@@ -17,7 +17,6 @@
import com.facebook.airlift.json.JsonCodec;
import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
import com.google.common.io.Resources;
import org.testng.annotations.Test;
@@ -28,6 +27,7 @@
import static com.facebook.airlift.json.JsonCodec.jsonCodec;
import static com.facebook.airlift.json.JsonCodec.mapJsonCodec;
import static com.facebook.airlift.testing.EquivalenceTester.equivalenceTester;
+import static com.google.common.collect.MoreCollectors.onlyElement;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
@@ -53,7 +53,7 @@ public void testJsonEncode()
// set id in expected
List