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> 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 future : futures) { @@ -298,7 +298,7 @@ public static ListenableFuture whenAnyComplete(Iterable ListenableFuture whenAnyCompleteCancelOthers(Iterable> 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 CompletableFuture firstCompletedFuture(Iterable> 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 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> services = toServices(expected.get("services")); - services.get(0).put("id", Iterables.getOnlyElement(announcement.getServices()).getId().toString()); + services.get(0).put("id", announcement.getServices().stream().collect(onlyElement()).getId().toString()); assertEquals(actual, expected); } diff --git a/discovery/src/test/java/com/facebook/airlift/discovery/client/TestHttpAnnouncementBinder.java b/discovery/src/test/java/com/facebook/airlift/discovery/client/TestHttpAnnouncementBinder.java index 800790d814..6268983be3 100644 --- a/discovery/src/test/java/com/facebook/airlift/discovery/client/TestHttpAnnouncementBinder.java +++ b/discovery/src/test/java/com/facebook/airlift/discovery/client/TestHttpAnnouncementBinder.java @@ -16,7 +16,6 @@ package com.facebook.airlift.discovery.client; import com.facebook.airlift.discovery.client.testing.TestingDiscoveryModule; -import com.google.common.collect.Iterables; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Key; @@ -28,6 +27,7 @@ import static com.facebook.airlift.discovery.client.DiscoveryBinder.discoveryBinder; import static com.facebook.airlift.discovery.client.ServiceAnnouncement.serviceAnnouncement; +import static com.google.common.collect.MoreCollectors.onlyElement; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; @@ -154,7 +154,7 @@ private void assertAnnouncement(Set actualAnnouncements, Se { assertNotNull(actualAnnouncements); assertEquals(actualAnnouncements.size(), 1); - ServiceAnnouncement announcement = Iterables.getOnlyElement(actualAnnouncements); + ServiceAnnouncement announcement = actualAnnouncements.stream().collect(onlyElement()); assertEquals(announcement.getType(), expected.getType()); assertEquals(announcement.getProperties(), expected.getProperties()); } diff --git a/discovery/src/test/java/com/facebook/airlift/discovery/client/TestHttpServiceSelectorBinder.java b/discovery/src/test/java/com/facebook/airlift/discovery/client/TestHttpServiceSelectorBinder.java index bee5946c58..cd693561bc 100644 --- a/discovery/src/test/java/com/facebook/airlift/discovery/client/TestHttpServiceSelectorBinder.java +++ b/discovery/src/test/java/com/facebook/airlift/discovery/client/TestHttpServiceSelectorBinder.java @@ -33,7 +33,7 @@ import static com.facebook.airlift.discovery.client.DiscoveryBinder.discoveryBinder; import static com.facebook.airlift.discovery.client.ServiceAnnouncement.serviceAnnouncement; 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 org.testng.Assert.assertEquals; public class TestHttpServiceSelectorBinder @@ -51,7 +51,7 @@ public void testHttpSelectorString() discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("http", "fake://server-http").build())); HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple"))); - assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("fake://server-http")); + assertEquals(selector.selectHttpService().stream().collect(onlyElement()), URI.create("fake://server-http")); } @Test @@ -67,7 +67,7 @@ public void testHttpSelectorAnnotation() discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("http", "fake://server-http").build())); HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple"))); - assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("fake://server-http")); + assertEquals(selector.selectHttpService().stream().collect(onlyElement()), URI.create("fake://server-http")); ServiceSelectorManager manager = injector.getInstance(ServiceSelectorManager.class); assertEquals(manager.getServiceSelectors().size(), 1); @@ -88,7 +88,7 @@ public void testHttpsSelector() discoveryClient.announce(ImmutableSet.of(serviceAnnouncement("apple").addProperty("https", "fake://server-https").build())); HttpServiceSelector selector = injector.getInstance(Key.get(HttpServiceSelector.class, serviceType("apple"))); - assertEquals(getOnlyElement(selector.selectHttpService()), URI.create("fake://server-https")); + assertEquals(selector.selectHttpService().stream().collect(onlyElement()), URI.create("fake://server-https")); } @Test diff --git a/event/pom.xml b/event/pom.xml index 0d67014dd1..975788d2b2 100644 --- a/event/pom.xml +++ b/event/pom.xml @@ -36,8 +36,9 @@ - io.airlift + com.facebook.airlift units + runtime diff --git a/event/src/main/java/com/facebook/airlift/event/client/EventFieldMetadata.java b/event/src/main/java/com/facebook/airlift/event/client/EventFieldMetadata.java index 6bbc7da298..3f4ce17bc4 100644 --- a/event/src/main/java/com/facebook/airlift/event/client/EventFieldMetadata.java +++ b/event/src/main/java/com/facebook/airlift/event/client/EventFieldMetadata.java @@ -32,12 +32,12 @@ import java.util.Optional; import static com.facebook.airlift.event.client.EventDataType.validateFieldValueType; -import static com.google.common.base.MoreObjects.firstNonNull; +import static java.util.Objects.requireNonNullElse; @Beta public class EventFieldMetadata { - public static enum ContainerType + public enum ContainerType { ITERABLE, MAP, MULTIMAP; @@ -94,7 +94,7 @@ private Object getValue(Object event) return method.invoke(event); } catch (Exception e) { - throw new InvalidEventException(firstNonNull(e.getCause(), e), + throw new InvalidEventException(requireNonNullElse(e.getCause(), e), "Unable to get value of event field %s: Exception occurred while invoking [%s]", name, method.toGenericString()); } } @@ -111,19 +111,23 @@ private void writeField(JsonGenerator jsonGenerator, Object event, Deque Object value = getValue(event); if (value != null) { jsonGenerator.writeFieldName(name); - if (containerType.isPresent()) { - if (containerType.get() == ContainerType.ITERABLE) { + ContainerType type = containerType.orElse(null); + switch (type) { + case ITERABLE -> { validateFieldValueType(value, Iterable.class); writeArray(jsonGenerator, (Iterable) value, objectStack); } - else if (containerType.get() == ContainerType.MAP) { + case MAP -> { validateFieldValueType(value, Map.class); writeMap(jsonGenerator, (Map) value, objectStack); } - else if (containerType.get() == ContainerType.MULTIMAP) { + case MULTIMAP -> { validateFieldValueType(value, Multimap.class); writeMultimap(jsonGenerator, (Multimap) value, objectStack); } + case null -> { /* no-op */ } + } + if (type != null) { return; } writeFieldValue(jsonGenerator, value, objectStack); @@ -133,11 +137,12 @@ else if (containerType.get() == ContainerType.MULTIMAP) { private void writeFieldValue(JsonGenerator jsonGenerator, Object value, Deque objectStack) throws IOException { - if (eventDataType.isPresent()) { - eventDataType.get().writeFieldValue(jsonGenerator, value); + EventDataType dataType = eventDataType.orElse(null); + if (dataType != null) { + dataType.writeFieldValue(jsonGenerator, value); } else { - validateFieldValueType(value, nestedType.get().getEventClass()); + validateFieldValueType(value, nestedType.orElseThrow().getEventClass()); writeObject(jsonGenerator, value, objectStack); } } @@ -180,7 +185,7 @@ private void writeObject(JsonGenerator jsonGenerator, Object value, Deque @@ -143,8 +142,8 @@ else if (isMultimap(dataType)) { } else { eventDataType = Optional.ofNullable(getEventDataType(dataType)); - if (!eventDataType.isPresent()) { - Object typeSource = (containerType.isPresent()) ? containerType.get() : "return"; + if (eventDataType.isEmpty()) { + Object typeSource = containerType.map(Object.class::cast).orElse("return"); addMethodError("%s type [%s] is not supported", method, typeSource, dataType); continue; } @@ -156,7 +155,7 @@ else if (isMultimap(dataType)) { if (eventField.fieldMapping() != EventFieldMapping.DATA) { // validate special fields if (containerType.isPresent()) { - addMethodError("non-DATA fieldMapping (%s) not allowed for %s", method, eventField.fieldMapping(), containerType.get()); + containerType.ifPresent(type -> addMethodError("non-DATA fieldMapping (%s) not allowed for %s", method, eventField.fieldMapping(), type)); continue; } if (nestedEvent) { @@ -200,9 +199,9 @@ else if (isMultimap(dataType)) { } } - this.uuidField = getFirst(specialFields.get(EventFieldMapping.UUID), null); - this.timestampField = getFirst(specialFields.get(EventFieldMapping.TIMESTAMP), null); - this.hostField = getFirst(specialFields.get(EventFieldMapping.HOST), null); + this.uuidField = specialFields.get(EventFieldMapping.UUID).stream().findFirst().orElse(null); + this.timestampField = specialFields.get(EventFieldMapping.TIMESTAMP).stream().findFirst().orElse(null); + this.hostField = specialFields.get(EventFieldMapping.HOST).stream().findFirst().orElse(null); this.fields = ImmutableSortedMap.copyOf(fields); if (getErrors().isEmpty() && this.fields.isEmpty()) { diff --git a/event/src/test/java/com/facebook/airlift/event/client/TestJsonEventSerializer.java b/event/src/test/java/com/facebook/airlift/event/client/TestJsonEventSerializer.java index b3ada76059..4d05db2f52 100644 --- a/event/src/test/java/com/facebook/airlift/event/client/TestJsonEventSerializer.java +++ b/event/src/test/java/com/facebook/airlift/event/client/TestJsonEventSerializer.java @@ -39,7 +39,7 @@ public void testEventSerializer() FixedDummyEventClass event = TestingUtils.getEvents().get(0); eventSerializer.serialize(event, jsonGenerator); - String json = out.toString(UTF_8.name()); + String json = out.toString(UTF_8); assertEquals(json, TestingUtils.getNormalizedJson("event.json")); } } diff --git a/event/src/test/java/com/facebook/airlift/event/client/TestJsonEventWriter.java b/event/src/test/java/com/facebook/airlift/event/client/TestJsonEventWriter.java index 7e5e46551b..3f877692d0 100644 --- a/event/src/test/java/com/facebook/airlift/event/client/TestJsonEventWriter.java +++ b/event/src/test/java/com/facebook/airlift/event/client/TestJsonEventWriter.java @@ -28,7 +28,7 @@ import static com.facebook.airlift.event.client.ChainedCircularEventClass.ChainedPart; import static com.facebook.airlift.event.client.EventTypeMetadata.getValidEventTypeMetaDataSet; -import static com.google.common.io.ByteStreams.nullOutputStream; +import static java.io.OutputStream.nullOutputStream; import static java.nio.charset.StandardCharsets.UTF_8; import static org.testng.Assert.assertEquals; @@ -136,7 +136,7 @@ private void assertEventJson(EventClient.EventGenerator events, String resour eventWriter.writeEvents(events, out); - String json = out.toString(UTF_8.name()); + String json = out.toString(UTF_8); assertEquals(json, TestingUtils.getNormalizedJson(resource)); } diff --git a/event/src/test/java/com/facebook/airlift/event/client/privateclass/TestSerializingPrivateEvent.java b/event/src/test/java/com/facebook/airlift/event/client/privateclass/TestSerializingPrivateEvent.java index af56332eec..2bae242e05 100644 --- a/event/src/test/java/com/facebook/airlift/event/client/privateclass/TestSerializingPrivateEvent.java +++ b/event/src/test/java/com/facebook/airlift/event/client/privateclass/TestSerializingPrivateEvent.java @@ -24,7 +24,7 @@ import java.io.IOException; -import static com.google.common.io.ByteStreams.nullOutputStream; +import static java.io.OutputStream.nullOutputStream; public class TestSerializingPrivateEvent { diff --git a/http-client/pom.xml b/http-client/pom.xml index 448ed7f885..dc248d3f7d 100644 --- a/http-client/pom.xml +++ b/http-client/pom.xml @@ -12,6 +12,9 @@ ${project.parent.basedir} + + --add-opens java.base/java.lang=ALL-UNNAMED + @@ -53,6 +56,7 @@ com.facebook.airlift concurrent + runtime @@ -71,7 +75,7 @@ - io.airlift + com.facebook.airlift units @@ -155,6 +159,7 @@ com.fasterxml.jackson.core jackson-annotations + runtime diff --git a/http-client/src/main/java/com/facebook/airlift/http/client/GatheringByteArrayInputStream.java b/http-client/src/main/java/com/facebook/airlift/http/client/GatheringByteArrayInputStream.java index 1c730c3f4f..5db025f6e9 100644 --- a/http-client/src/main/java/com/facebook/airlift/http/client/GatheringByteArrayInputStream.java +++ b/http-client/src/main/java/com/facebook/airlift/http/client/GatheringByteArrayInputStream.java @@ -8,10 +8,10 @@ import java.util.List; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkPositionIndexes; import static com.google.common.base.Preconditions.checkState; import static java.lang.Math.min; import static java.lang.System.arraycopy; +import static java.util.Objects.checkFromToIndex; import static java.util.Objects.requireNonNull; @ThreadSafe @@ -79,7 +79,7 @@ public synchronized long skip(long n) public synchronized int read(byte[] buffer, int offset, int length) { requireNonNull(buffer, "buffer is null"); - checkPositionIndexes(offset, offset + length, buffer.length); + checkFromToIndex(offset, offset + length, buffer.length); if (remainingBytes == 0) { return -1; diff --git a/http-client/src/main/java/com/facebook/airlift/http/client/HttpUriBuilder.java b/http-client/src/main/java/com/facebook/airlift/http/client/HttpUriBuilder.java index 447a61dddd..d5d70de95d 100644 --- a/http-client/src/main/java/com/facebook/airlift/http/client/HttpUriBuilder.java +++ b/http-client/src/main/java/com/facebook/airlift/http/client/HttpUriBuilder.java @@ -4,9 +4,9 @@ import com.google.common.base.Ascii; import com.google.common.base.Preconditions; import com.google.common.base.Splitter; -import com.google.common.collect.Iterables; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.ListMultimap; +import com.google.common.collect.Streams; import com.google.common.net.HostAndPort; import com.google.common.primitives.Bytes; @@ -177,7 +177,7 @@ public HttpUriBuilder addParameter(String name, Iterable values) { requireNonNull(name, "name is null"); - if (Iterables.isEmpty(values)) { + if (Streams.stream(values).findAny().isEmpty()) { params.put(name, null); } diff --git a/http-client/src/main/java/com/facebook/airlift/http/client/jetty/HttpRequestEvent.java b/http-client/src/main/java/com/facebook/airlift/http/client/jetty/HttpRequestEvent.java index 75431c5e72..585c2dba3e 100644 --- a/http-client/src/main/java/com/facebook/airlift/http/client/jetty/HttpRequestEvent.java +++ b/http-client/src/main/java/com/facebook/airlift/http/client/jetty/HttpRequestEvent.java @@ -167,12 +167,8 @@ static HttpRequestEvent createHttpRequestEvent(RequestInfo requestInfo, Response method = method.toUpperCase(Locale.US); } - long responseSize = NO_RESPONSE; - int responseCode = NO_RESPONSE; - if (response.isPresent()) { - responseSize = responseInfo.getResponseSize(); - responseCode = response.get().getStatus(); - } + long responseSize = response.map(unused -> responseInfo.getResponseSize()).orElse((long) NO_RESPONSE); + int responseCode = response.map(Response::getStatus).orElse(NO_RESPONSE); long requestTotalTimeNanos = responseInfo.getResponseCompleteTimestamp() - requestInfo.getRequestCreatedTimestamp(); long requestBeginToRequestEndNanos = requestInfo.getRequestEndTimestamp() - requestInfo.getRequestBeginTimestamp(); @@ -208,17 +204,14 @@ static Optional getFailureReason(ResponseInfo responseInfo) { Optional failure = responseInfo.getFailureCause(); - if (!failure.isPresent()) { - return Optional.empty(); - } - - String className = failure.get().getClass().getSimpleName().toUpperCase(Locale.US); - - if (className.endsWith("EXCEPTION")) { - return Optional.of(className.substring(0, className.lastIndexOf("EXCEPTION"))); - } + return failure.map(throwable -> { + String className = throwable.getClass().getSimpleName().toUpperCase(Locale.US); - return Optional.of(className); + if (className.endsWith("EXCEPTION")) { + return className.substring(0, className.lastIndexOf("EXCEPTION")); + } + return className; + }); } @Nullable diff --git a/http-client/src/main/java/com/facebook/airlift/http/client/jetty/JettyAsyncSocketAddressResolver.java b/http-client/src/main/java/com/facebook/airlift/http/client/jetty/JettyAsyncSocketAddressResolver.java index ef73a311a4..75a3b8e52b 100644 --- a/http-client/src/main/java/com/facebook/airlift/http/client/jetty/JettyAsyncSocketAddressResolver.java +++ b/http-client/src/main/java/com/facebook/airlift/http/client/jetty/JettyAsyncSocketAddressResolver.java @@ -29,11 +29,11 @@ public JettyAsyncSocketAddressResolver(Executor executor, Scheduler scheduler, l public void resolve(String host, int port, Promise> promise) { Optional address = resolve(host); - if (address.isPresent()) { - promise.succeeded(ImmutableList.of(new InetSocketAddress(address.get(), port))); - return; - } - super.resolve(host, port, promise); + address.ifPresentOrElse(addr -> { + promise.succeeded(ImmutableList.of(new InetSocketAddress(addr, port))); + }, () -> { + super.resolve(host, port, promise); + }); } private static Optional resolve(String host) diff --git a/http-client/src/main/java/com/facebook/airlift/http/client/jetty/JettyHttpClient.java b/http-client/src/main/java/com/facebook/airlift/http/client/jetty/JettyHttpClient.java index 2cabdab0e1..4eda93e131 100755 --- a/http-client/src/main/java/com/facebook/airlift/http/client/jetty/JettyHttpClient.java +++ b/http-client/src/main/java/com/facebook/airlift/http/client/jetty/JettyHttpClient.java @@ -161,25 +161,23 @@ public JettyHttpClient( sslContextFactory.setEndpointIdentificationAlgorithm("HTTPS"); if (config.getKeyStorePath() != null) { Optional pemKeyStore = tryLoadPemKeyStore(config); - if (pemKeyStore.isPresent()) { - sslContextFactory.setKeyStore(pemKeyStore.get()); + pemKeyStore.ifPresentOrElse(keyStore -> { + sslContextFactory.setKeyStore(keyStore); sslContextFactory.setKeyStorePassword(""); - } - else { + }, () -> { sslContextFactory.setKeyStorePath(config.getKeyStorePath()); sslContextFactory.setKeyStorePassword(config.getKeyStorePassword()); - } + }); } if (config.getTrustStorePath() != null) { Optional pemTrustStore = tryLoadPemTrustStore(config); - if (pemTrustStore.isPresent()) { - sslContextFactory.setTrustStore(pemTrustStore.get()); + pemTrustStore.ifPresentOrElse(trustStore -> { + sslContextFactory.setTrustStore(trustStore); sslContextFactory.setTrustStorePassword(""); - } - else { + }, () -> { sslContextFactory.setTrustStorePath(config.getTrustStorePath()); sslContextFactory.setTrustStorePassword(config.getTrustStorePassword()); - } + }); } sslContextFactory.setSecureRandomAlgorithm(config.getSecureRandomAlgorithm()); List includedCipherSuites = config.getHttpsIncludedCipherSuites(); diff --git a/http-client/src/test/java/com/facebook/airlift/http/client/TestingSocksProxy.java b/http-client/src/test/java/com/facebook/airlift/http/client/TestingSocksProxy.java index e109a64285..6440588b0f 100644 --- a/http-client/src/test/java/com/facebook/airlift/http/client/TestingSocksProxy.java +++ b/http-client/src/test/java/com/facebook/airlift/http/client/TestingSocksProxy.java @@ -407,7 +407,7 @@ private Pipe(InputStream in, OutputStream out) public void run() { try { - ByteStreams.copy(in, out); + in.transferTo(out); } catch (IOException e) { // ignored nothing we can do about this diff --git a/http-client/src/test/java/com/facebook/airlift/http/client/jetty/TestHttpClientLogger.java b/http-client/src/test/java/com/facebook/airlift/http/client/jetty/TestHttpClientLogger.java index 0baf6716ed..8b7254c0d2 100644 --- a/http-client/src/test/java/com/facebook/airlift/http/client/jetty/TestHttpClientLogger.java +++ b/http-client/src/test/java/com/facebook/airlift/http/client/jetty/TestHttpClientLogger.java @@ -172,7 +172,7 @@ public void testClientLogNoResponse() assertEquals(columns[1], HTTP_1_1.toString()); assertEquals(columns[2], method); assertEquals(columns[3], uri.toString()); - assertEquals(columns[4], getFailureReason(responseInfo).get()); + assertEquals(columns[4], getFailureReason(responseInfo).orElseThrow()); assertEquals(columns[5], Integer.toString(NO_RESPONSE)); assertNotEquals(columns[6], Long.toString(0)); assertEquals(columns[7], Long.toString(0)); diff --git a/http-client/src/test/java/com/facebook/airlift/http/client/jetty/TestJettyHttpsClient.java b/http-client/src/test/java/com/facebook/airlift/http/client/jetty/TestJettyHttpsClient.java index f8b9adfb87..c1fec454bf 100755 --- a/http-client/src/test/java/com/facebook/airlift/http/client/jetty/TestJettyHttpsClient.java +++ b/http-client/src/test/java/com/facebook/airlift/http/client/jetty/TestJettyHttpsClient.java @@ -87,7 +87,7 @@ public void testConnectTimeout() super.testConnectTimeout(); } - @Test(expectedExceptions = {IOException.class}) + @Test(expectedExceptions = IOException.class) public void testCertHostnameMismatch() throws Exception { diff --git a/http-server/pom.xml b/http-server/pom.xml index d2a2eb4ae8..9d7ad7ab66 100644 --- a/http-server/pom.xml +++ b/http-server/pom.xml @@ -13,6 +13,9 @@ ${project.parent.basedir} + + --add-opens java.base/java.lang=ALL-UNNAMED + @@ -27,7 +30,7 @@ - io.airlift + com.facebook.airlift units @@ -166,6 +169,11 @@ jetty-jmx + + org.gaul + modernizer-maven-annotations + + com.facebook.airlift diff --git a/http-server/src/main/java/com/facebook/airlift/http/server/AuthenticationFilter.java b/http-server/src/main/java/com/facebook/airlift/http/server/AuthenticationFilter.java index 0b303b11a3..d7c06857c6 100644 --- a/http-server/src/main/java/com/facebook/airlift/http/server/AuthenticationFilter.java +++ b/http-server/src/main/java/com/facebook/airlift/http/server/AuthenticationFilter.java @@ -35,10 +35,9 @@ import java.util.List; import java.util.Set; -import static com.google.common.io.ByteStreams.copy; -import static com.google.common.io.ByteStreams.nullOutputStream; import static com.google.common.net.HttpHeaders.WWW_AUTHENTICATE; import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8; +import static java.io.OutputStream.nullOutputStream; import static java.util.Objects.requireNonNull; import static javax.servlet.http.HttpServletResponse.SC_UNAUTHORIZED; @@ -141,7 +140,7 @@ private static void skipRequestBody(HttpServletRequest request) // in the client by reading and discarding the entire body of the // unauthenticated request before sending the response. try (InputStream inputStream = request.getInputStream()) { - copy(inputStream, nullOutputStream()); + inputStream.transferTo(nullOutputStream()); } } } diff --git a/http-server/src/main/java/com/facebook/airlift/http/server/AuthorizationEnabledServlet.java b/http-server/src/main/java/com/facebook/airlift/http/server/AuthorizationEnabledServlet.java index a6c4f932a1..2b133d10e0 100644 --- a/http-server/src/main/java/com/facebook/airlift/http/server/AuthorizationEnabledServlet.java +++ b/http-server/src/main/java/com/facebook/airlift/http/server/AuthorizationEnabledServlet.java @@ -16,6 +16,7 @@ package com.facebook.airlift.http.server; import com.google.common.collect.ImmutableSet; +import org.gaul.modernizer_maven_annotations.SuppressModernizer; import javax.annotation.security.RolesAllowed; import javax.servlet.Servlet; @@ -33,8 +34,7 @@ import java.util.Set; import static com.facebook.airlift.http.server.HttpServerConfig.AuthorizationPolicy; -import static com.google.common.io.ByteStreams.copy; -import static com.google.common.io.ByteStreams.nullOutputStream; +import static java.io.OutputStream.nullOutputStream; import static java.lang.String.format; import static java.util.Objects.requireNonNull; @@ -71,6 +71,7 @@ public void init() delegate.init(this.getServletConfig()); } + @SuppressModernizer @Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException @@ -90,7 +91,7 @@ public void service(ServletRequest req, ServletResponse res) } Optional> allowedRoles = this.allowedRoles; - if (!allowedRoles.isPresent()) { + if (allowedRoles.isEmpty()) { switch (authorizationPolicy) { case ALLOW: delegate.service(req, res); @@ -136,7 +137,7 @@ private static void skipRequestBody(HttpServletRequest request) // in the client by reading and discarding the entire body of the // unauthenticated request before sending the response. try (InputStream inputStream = request.getInputStream()) { - copy(inputStream, nullOutputStream()); + inputStream.transferTo(nullOutputStream()); } } diff --git a/http-server/src/main/java/com/facebook/airlift/http/server/ClassPathResourceHandler.java b/http-server/src/main/java/com/facebook/airlift/http/server/ClassPathResourceHandler.java index 529b3a92fe..973c810140 100644 --- a/http-server/src/main/java/com/facebook/airlift/http/server/ClassPathResourceHandler.java +++ b/http-server/src/main/java/com/facebook/airlift/http/server/ClassPathResourceHandler.java @@ -16,7 +16,6 @@ package com.facebook.airlift.http.server; import com.google.common.collect.ImmutableList; -import com.google.common.io.ByteStreams; import com.google.common.net.HttpHeaders; import org.eclipse.jetty.http.HttpMethod; import org.eclipse.jetty.http.MimeTypes; @@ -134,7 +133,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques return; } - ByteStreams.copy(resourceStream, response.getOutputStream()); + resourceStream.transferTo(response.getOutputStream()); } finally { closeQuietly(resourceStream); diff --git a/http-server/src/main/java/com/facebook/airlift/http/server/HttpServer.java b/http-server/src/main/java/com/facebook/airlift/http/server/HttpServer.java index afde06d977..e0e9b53d51 100644 --- a/http-server/src/main/java/com/facebook/airlift/http/server/HttpServer.java +++ b/http-server/src/main/java/com/facebook/airlift/http/server/HttpServer.java @@ -24,7 +24,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.primitives.Ints; import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory; import org.eclipse.jetty.io.ConnectionStatistics; import org.eclipse.jetty.jmx.MBeanContainer; @@ -82,7 +81,6 @@ import java.util.concurrent.TimeoutException; import static com.facebook.airlift.http.utils.jetty.ConcurrentScheduler.createConcurrentScheduler; -import static com.google.common.base.MoreObjects.firstNonNull; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static java.lang.Math.toIntExact; @@ -91,6 +89,7 @@ import static java.util.Collections.list; import static java.util.Comparator.naturalOrder; import static java.util.Objects.requireNonNull; +import static java.util.Objects.requireNonNullElse; import static java.util.concurrent.TimeUnit.SECONDS; public class HttpServer @@ -131,7 +130,7 @@ public HttpServer(HttpServerInfo httpServerInfo, QueuedThreadPool threadPool = new QueuedThreadPool(config.getMaxThreads()); threadPool.setMinThreads(config.getMinThreads()); - threadPool.setIdleTimeout(Ints.checkedCast(config.getThreadMaxIdleTime().toMillis())); + threadPool.setIdleTimeout(toIntExact(config.getThreadMaxIdleTime().toMillis())); threadPool.setName("http-worker"); threadPool.setDetailedDump(true); server = new Server(threadPool); @@ -194,8 +193,8 @@ public HttpServer(HttpServerInfo httpServerInfo, server, null, concurrentScheduler, - firstNonNull(acceptors, -1), - firstNonNull(selectors, -1), + requireNonNullElse(acceptors, -1), + requireNonNullElse(selectors, -1), http1, http2c); httpConnector.setName("http"); @@ -227,27 +226,25 @@ public HttpServer(HttpServerInfo httpServerInfo, SslContextFactory.Server sslContextFactory = new SslContextFactory.Server(); Optional pemKeyStore = tryLoadPemKeyStore(config); - if (pemKeyStore.isPresent()) { - sslContextFactory.setKeyStore(pemKeyStore.get()); + pemKeyStore.ifPresentOrElse(keyStore -> { + sslContextFactory.setKeyStore(keyStore); sslContextFactory.setKeyStorePassword(""); - } - else { + }, () -> { sslContextFactory.setKeyStorePath(config.getKeystorePath()); sslContextFactory.setKeyStorePassword(config.getKeystorePassword()); if (config.getKeyManagerPassword() != null) { sslContextFactory.setKeyManagerPassword(config.getKeyManagerPassword()); } - } + }); if (config.getTrustStorePath() != null) { Optional pemTrustStore = tryLoadPemTrustStore(config); - if (pemTrustStore.isPresent()) { - sslContextFactory.setTrustStore(pemTrustStore.get()); + pemTrustStore.ifPresentOrElse(trustStore -> { + sslContextFactory.setTrustStore(trustStore); sslContextFactory.setTrustStorePassword(""); - } - else { + }, () -> { sslContextFactory.setTrustStorePath(config.getTrustStorePath()); sslContextFactory.setTrustStorePassword(config.getTrustStorePassword()); - } + }); } sslContextFactory.setIncludeCipherSuites(includedCipherSuites.toArray(new String[0])); @@ -265,8 +262,8 @@ public HttpServer(HttpServerInfo httpServerInfo, server, null, concurrentScheduler, - firstNonNull(acceptors, -1), - firstNonNull(selectors, -1), + requireNonNullElse(acceptors, -1), + requireNonNullElse(selectors, -1), sslConnectionFactory, new HttpConnectionFactory(httpsConfiguration)); httpsConnector.setName("https"); @@ -295,7 +292,7 @@ public HttpServer(HttpServerInfo httpServerInfo, QueuedThreadPool adminThreadPool = new QueuedThreadPool(config.getAdminMaxThreads()); adminThreadPool.setName("http-admin-worker"); adminThreadPool.setMinThreads(config.getAdminMinThreads()); - adminThreadPool.setIdleTimeout(Ints.checkedCast(config.getThreadMaxIdleTime().toMillis())); + adminThreadPool.setIdleTimeout(toIntExact(config.getThreadMaxIdleTime().toMillis())); if (config.isHttpsEnabled()) { adminConfiguration.addCustomizer(new SecureRequestCustomizer()); diff --git a/http-server/src/main/java/com/facebook/airlift/http/server/KerberosAuthenticator.java b/http-server/src/main/java/com/facebook/airlift/http/server/KerberosAuthenticator.java index 0b4ef7bda4..d3d8f01299 100644 --- a/http-server/src/main/java/com/facebook/airlift/http/server/KerberosAuthenticator.java +++ b/http-server/src/main/java/com/facebook/airlift/http/server/KerberosAuthenticator.java @@ -15,6 +15,7 @@ import com.facebook.airlift.log.Logger; import com.sun.security.auth.module.Krb5LoginModule; +import org.gaul.modernizer_maven_annotations.SuppressModernizer; import org.ietf.jgss.GSSContext; import org.ietf.jgss.GSSCredential; import org.ietf.jgss.GSSException; @@ -117,6 +118,7 @@ public void shutdown() } } + @SuppressModernizer @Override public Principal authenticate(HttpServletRequest request) throws AuthenticationException diff --git a/http-server/src/test/java/com/facebook/airlift/http/server/TestHttpServerModule.java b/http-server/src/test/java/com/facebook/airlift/http/server/TestHttpServerModule.java index d097a4550d..a7ad86ca9a 100644 --- a/http-server/src/test/java/com/facebook/airlift/http/server/TestHttpServerModule.java +++ b/http-server/src/test/java/com/facebook/airlift/http/server/TestHttpServerModule.java @@ -34,7 +34,6 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ListMultimap; -import com.google.common.io.ByteStreams; import com.google.common.io.Files; import com.google.common.net.MediaType; import com.google.inject.Guice; @@ -48,7 +47,6 @@ import javax.servlet.Filter; import javax.servlet.Servlet; -import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -75,6 +73,7 @@ import static com.google.common.net.HttpHeaders.USER_AGENT; import static com.google.common.net.MediaType.PLAIN_TEXT_UTF_8; import static com.google.inject.multibindings.Multibinder.newSetBinder; +import static java.io.OutputStream.nullOutputStream; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Collections.nCopies; import static org.testng.Assert.assertEquals; @@ -347,9 +346,9 @@ private static final class EchoServlet @Override protected void service(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException + throws IOException { - ByteStreams.copy(request.getInputStream(), ByteStreams.nullOutputStream()); + request.getInputStream().transferTo(nullOutputStream()); remoteAddress = request.getRemoteAddr(); for (Entry entry : responseHeaders.entries()) { diff --git a/jaxrs-testing/pom.xml b/jaxrs-testing/pom.xml index 6d330be5cf..4d9c6d20b1 100644 --- a/jaxrs-testing/pom.xml +++ b/jaxrs-testing/pom.xml @@ -60,21 +60,25 @@ com.facebook.drift drift-codec + runtime com.facebook.drift drift-transport-netty + runtime com.facebook.drift drift-api + runtime com.facebook.drift drift-protocol + runtime diff --git a/jaxrs-testing/src/main/java/com/facebook/airlift/jaxrs/testing/JaxrsTestingHttpProcessor.java b/jaxrs-testing/src/main/java/com/facebook/airlift/jaxrs/testing/JaxrsTestingHttpProcessor.java index 83de805f90..99cf4ab839 100644 --- a/jaxrs-testing/src/main/java/com/facebook/airlift/jaxrs/testing/JaxrsTestingHttpProcessor.java +++ b/jaxrs-testing/src/main/java/com/facebook/airlift/jaxrs/testing/JaxrsTestingHttpProcessor.java @@ -42,7 +42,7 @@ import java.util.Map; import java.util.Set; -import static com.google.common.collect.Iterables.getOnlyElement; +import static com.google.common.collect.MoreCollectors.onlyElement; public class JaxrsTestingHttpProcessor implements TestingHttpClient.Processor @@ -95,7 +95,7 @@ public Response handle(Request request) request.getBodyGenerator().write(byteArrayOutputStream); byteArrayOutputStream.close(); byte[] bytes = byteArrayOutputStream.toByteArray(); - Entity entity = Entity.entity(bytes, (String) getOnlyElement(requestHeaders.get("Content-Type"))); + Entity entity = Entity.entity(bytes, (String) requestHeaders.get("Content-Type").stream().collect(onlyElement())); invocation = invocationBuilder.build(request.getMethod(), entity); } diff --git a/jaxrs-testing/src/test/java/com/facebook/airlift/jaxrs/testing/TestJaxrsThriftTestingHttpProcessor.java b/jaxrs-testing/src/test/java/com/facebook/airlift/jaxrs/testing/TestJaxrsThriftTestingHttpProcessor.java index 42951475f2..3f9160d92a 100644 --- a/jaxrs-testing/src/test/java/com/facebook/airlift/jaxrs/testing/TestJaxrsThriftTestingHttpProcessor.java +++ b/jaxrs-testing/src/test/java/com/facebook/airlift/jaxrs/testing/TestJaxrsThriftTestingHttpProcessor.java @@ -77,10 +77,10 @@ public void setup() httpClient = new TestingHttpClient( new JaxrsTestingHttpProcessor( - URI.create("http://fake.invalid/"), - new Resource(), - new ThriftMapper(codecManager), - new ParsingExceptionMapper())); + URI.create("http://fake.invalid/"), + new Resource(), + new ThriftMapper(codecManager), + new ParsingExceptionMapper())); testThriftMessageThriftCodec = codecManager.getCodec(TestThriftMessage.class); testThriftMessageTestThriftResponseHandler = new ThriftResponseHandler<>(testThriftMessageThriftCodec); } diff --git a/jaxrs/pom.xml b/jaxrs/pom.xml index cd49ec7c52..44922f38cc 100644 --- a/jaxrs/pom.xml +++ b/jaxrs/pom.xml @@ -34,11 +34,13 @@ com.facebook.airlift node + runtime com.facebook.airlift json + runtime @@ -59,6 +61,7 @@ com.facebook.drift drift-api + provided @@ -85,6 +88,7 @@ org.glassfish.jersey.core jersey-common + provided diff --git a/jaxrs/src/main/java/com/facebook/airlift/jaxrs/AuthorizationFilter.java b/jaxrs/src/main/java/com/facebook/airlift/jaxrs/AuthorizationFilter.java index efbf355350..df8be85cf1 100644 --- a/jaxrs/src/main/java/com/facebook/airlift/jaxrs/AuthorizationFilter.java +++ b/jaxrs/src/main/java/com/facebook/airlift/jaxrs/AuthorizationFilter.java @@ -99,7 +99,7 @@ public void filter(ContainerRequestContext request) } Optional> allowedRoles = getAllowedRoles(); - if (!allowedRoles.isPresent()) { + if (allowedRoles.isEmpty()) { switch (authorizationPolicy) { case ALLOW: return; @@ -116,7 +116,7 @@ public void filter(ContainerRequestContext request) } } else if (roleMaps.containsKey(resourceInfo.getResourceClass())) { - allowedRoles = Optional.of(allowedRoles.get() + allowedRoles = Optional.of(allowedRoles.orElseThrow() .stream() .map(role -> roleMaps.get(resourceInfo.getResourceClass()).getOrDefault(role, role)) .collect(toImmutableSet())); @@ -124,7 +124,7 @@ else if (roleMaps.containsKey(resourceInfo.getResourceClass())) { AuthorizationResult result = authorizer.authorize( principal, - allowedRoles.get(), + allowedRoles.orElseThrow(), request.getUriInfo().getRequestUri().toString()); if (!result.isAllowed()) { request.abortWith(Response.status(Response.Status.FORBIDDEN) diff --git a/jaxrs/src/main/java/com/facebook/airlift/jaxrs/testing/GuavaMultivaluedMap.java b/jaxrs/src/main/java/com/facebook/airlift/jaxrs/testing/GuavaMultivaluedMap.java index 4c7a771dc3..3b6a569abe 100644 --- a/jaxrs/src/main/java/com/facebook/airlift/jaxrs/testing/GuavaMultivaluedMap.java +++ b/jaxrs/src/main/java/com/facebook/airlift/jaxrs/testing/GuavaMultivaluedMap.java @@ -3,7 +3,6 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ForwardingMap; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; import com.google.common.collect.ListMultimap; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; @@ -63,7 +62,7 @@ public void addAll(K key, List valueList) @Override public V getFirst(K key) { - return Iterables.getFirst(multimap.get(key), null); + return multimap.get(key).stream().findFirst().orElse(null); } @Override diff --git a/jaxrs/src/main/java/com/facebook/airlift/jaxrs/testing/MockUriInfo.java b/jaxrs/src/main/java/com/facebook/airlift/jaxrs/testing/MockUriInfo.java index 513af11bf0..43416f29a1 100644 --- a/jaxrs/src/main/java/com/facebook/airlift/jaxrs/testing/MockUriInfo.java +++ b/jaxrs/src/main/java/com/facebook/airlift/jaxrs/testing/MockUriInfo.java @@ -26,9 +26,9 @@ import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; -import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.List; public class MockUriInfo @@ -184,12 +184,7 @@ public static MultivaluedMap decodeQuery(String query, boolean d private static String urlDecode(String value) { - try { - return URLDecoder.decode(value, "UTF-8"); - } - catch (UnsupportedEncodingException e) { - throw new IllegalArgumentException(e); - } + return URLDecoder.decode(value, StandardCharsets.UTF_8); } @Override diff --git a/jmx-http-rpc/pom.xml b/jmx-http-rpc/pom.xml index fa96d039b1..307ca43ff3 100644 --- a/jmx-http-rpc/pom.xml +++ b/jmx-http-rpc/pom.xml @@ -12,6 +12,9 @@ ${project.parent.basedir} + + --add-opens java.base/java.lang=ALL-UNNAMED + @@ -23,6 +26,7 @@ com.facebook.airlift json + runtime @@ -58,6 +62,7 @@ org.weakref jmxutils + runtime diff --git a/jmx-http/pom.xml b/jmx-http/pom.xml index 556f1a521a..18e41235ed 100644 --- a/jmx-http/pom.xml +++ b/jmx-http/pom.xml @@ -75,17 +75,20 @@ com.facebook.airlift http-client + runtime com.facebook.airlift node + runtime com.facebook.airlift http-server + runtime diff --git a/jmx-http/src/main/java/com/facebook/airlift/jmx/MBeanRepresentation.java b/jmx-http/src/main/java/com/facebook/airlift/jmx/MBeanRepresentation.java index 1c0ba02f85..2edb4a93d9 100644 --- a/jmx-http/src/main/java/com/facebook/airlift/jmx/MBeanRepresentation.java +++ b/jmx-http/src/main/java/com/facebook/airlift/jmx/MBeanRepresentation.java @@ -35,7 +35,7 @@ import java.util.List; import java.util.Map; -import static com.google.common.io.ByteStreams.nullOutputStream; +import static java.io.OutputStream.nullOutputStream; @JsonPropertyOrder({"objectName", "className", "description", "descriptor", "attributes", "operations"}) public class MBeanRepresentation diff --git a/jmx/pom.xml b/jmx/pom.xml index 9393cbd713..38558dd4ac 100644 --- a/jmx/pom.xml +++ b/jmx/pom.xml @@ -13,6 +13,10 @@ ${project.parent.basedir} + + -Djdk.attach.allowAttachSelf=true + --add-opens java.base/java.lang=ALL-UNNAMED + @@ -71,38 +75,16 @@ - - - - - lib/tools.jar - - [1.8,1.9) - - !idea.maven.embedder.version - - - - - com.sun - tools - 1.8 - system - ${java.home}/../lib/tools.jar - - - - - org.apache.maven.plugins - maven-surefire-plugin + maven-compiler-plugin - -Djdk.attach.allowAttachSelf=true + + --add-exports=jdk.management.agent/sun.management.jmxremote=ALL-UNNAMED + --add-exports=java.rmi/sun.rmi.server=ALL-UNNAMED + diff --git a/jmx/src/main/java/com/facebook/airlift/jmx/JmxAgent9.java b/jmx/src/main/java/com/facebook/airlift/jmx/JmxAgent21.java similarity index 97% rename from jmx/src/main/java/com/facebook/airlift/jmx/JmxAgent9.java rename to jmx/src/main/java/com/facebook/airlift/jmx/JmxAgent21.java index 24e7b286f5..87d8ffe50e 100644 --- a/jmx/src/main/java/com/facebook/airlift/jmx/JmxAgent9.java +++ b/jmx/src/main/java/com/facebook/airlift/jmx/JmxAgent21.java @@ -30,7 +30,7 @@ import static java.lang.String.format; -class JmxAgent9 +class JmxAgent21 implements JmxAgent { private static final Logger log = Logger.get(JmxAgent.class); @@ -42,7 +42,7 @@ class JmxAgent9 private final JMXServiceURL url; @Inject - public JmxAgent9(JmxConfig config) + public JmxAgent21(JmxConfig config) throws IOException { int registryPort; @@ -151,7 +151,7 @@ private static long getProcessId() public static void main(String[] args) throws IOException { - new JmxAgent9(new JmxConfig()); - new JmxAgent9(new JmxConfig()); + new JmxAgent21(new JmxConfig()); + new JmxAgent21(new JmxConfig()); } } diff --git a/jmx/src/main/java/com/facebook/airlift/jmx/JmxAgent8.java b/jmx/src/main/java/com/facebook/airlift/jmx/JmxAgent8.java deleted file mode 100644 index 16ce8057c2..0000000000 --- a/jmx/src/main/java/com/facebook/airlift/jmx/JmxAgent8.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright 2010 Proofpoint, 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.facebook.airlift.jmx; - -import com.facebook.airlift.log.Logger; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.net.HostAndPort; -import sun.management.jmxremote.ConnectorBootstrap; -import sun.rmi.server.UnicastRef; - -import javax.inject.Inject; -import javax.management.remote.JMXConnectorServer; -import javax.management.remote.JMXServiceURL; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.net.MalformedURLException; -import java.rmi.server.RemoteObject; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; -import static com.google.common.base.Throwables.throwIfUnchecked; -import static java.lang.String.format; - -class JmxAgent8 - implements JmxAgent -{ - private static final Logger log = Logger.get(JmxAgent.class); - - private static final Class AGENT_CLASS = getAgentClass(); - - private final JMXServiceURL url; - - @Inject - public JmxAgent8(JmxConfig config) - throws IOException - { - // first, see if the jmx agent is already started (e.g., via command line properties passed to the jvm) - HostAndPort address = getRunningAgentAddress(config.getRmiRegistryPort(), config.getRmiServerPort()); - if (address != null) { - log.info("JMX agent already running and listening on %s", address); - } - else { - // otherwise, start it manually - int registryPort; - if (config.getRmiRegistryPort() == null) { - registryPort = NetUtils.findUnusedPort(); - } - else { - registryPort = config.getRmiRegistryPort(); - } - - int serverPort = 0; - if (config.getRmiServerPort() != null) { - serverPort = config.getRmiServerPort(); - } - - // This is somewhat of a hack, but the jmx agent in Oracle/OpenJDK doesn't - // have a programmatic API for starting it and controlling its parameters - System.setProperty("com.sun.management.jmxremote", "true"); - System.setProperty("com.sun.management.jmxremote.port", Integer.toString(registryPort)); - System.setProperty("com.sun.management.jmxremote.rmi.port", Integer.toString(serverPort)); - System.setProperty("com.sun.management.jmxremote.authenticate", "false"); - System.setProperty("com.sun.management.jmxremote.ssl", "false"); - - try { - AGENT_CLASS.getMethod("startAgent").invoke(null); - } - catch (Exception e) { - throwIfUnchecked(e); - throw new RuntimeException(e); - } - - try { - // This is how the jdk jmx agent constructs its url - JMXServiceURL url = new JMXServiceURL("rmi", null, registryPort); - address = HostAndPort.fromParts(url.getHost(), url.getPort()); - } - catch (MalformedURLException e) { - // should not happen... - throw new AssertionError(e); - } - - log.info("JMX agent started and listening on %s", address); - } - - this.url = new JMXServiceURL(String.format("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", address.getHost(), address.getPort())); - } - - public JMXServiceURL getUrl() - { - return url; - } - - @VisibleForTesting - static HostAndPort getRunningAgentAddress(Integer registryPort, Integer serverPort) - { - JMXConnectorServer jmxServer; - RemoteObject registry; - int actualRegistryPort; - try { - jmxServer = getField(AGENT_CLASS, JMXConnectorServer.class, "jmxServer"); - registry = getField(ConnectorBootstrap.class, RemoteObject.class, "registry"); - - if (jmxServer == null || registry == null) { - log.warn("Cannot determine if JMX agent is already running (not an Oracle JVM?). Will try to start it manually."); - return null; - } - - actualRegistryPort = ((UnicastRef) registry.getRef()).getLiveRef().getPort(); - } - catch (Exception e) { - log.warn(e, "Cannot determine if JMX agent is already running. Will try to start it manually."); - return null; - } - - checkState(actualRegistryPort > 0, "Expected actual RMI registry port to be > 0, actual: %s", actualRegistryPort); - - // if registry port and server port were configured and the agent is already running, make sure - // the configuration agrees to avoid surprises - if (registryPort != null && registryPort != 0) { - checkArgument(actualRegistryPort == registryPort, - "JMX agent is already running, but actual RMI registry port (%s) doesn't match configured port (%s)", - actualRegistryPort, - registryPort); - } - - if (serverPort != null && serverPort != 0) { - int actualServerPort = jmxServer.getAddress().getPort(); - checkArgument(actualServerPort == serverPort, - "JMX agent is already running, but actual RMI server port (%s) doesn't match configured port (%s)", - actualServerPort, - serverPort); - } - - return HostAndPort.fromParts(jmxServer.getAddress().getHost(), actualRegistryPort); - } - - private static T getField(Class clazz, Class returnType, String name) - throws Exception - { - Field field = clazz.getDeclaredField(name); - field.setAccessible(true); - try { - return returnType.cast(field.get(clazz)); - } - catch (ClassCastException e) { - throw new IllegalArgumentException(format("Field %s in class %s is not of type %s, actual: %s", name, clazz.getName(), returnType.getName(), field.getType().getName()), e); - } - } - - private static Class getAgentClass() - { - try { - return Class.forName("sun.management.Agent"); - } - catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - } -} diff --git a/jmx/src/main/java/com/facebook/airlift/jmx/JmxModule.java b/jmx/src/main/java/com/facebook/airlift/jmx/JmxModule.java index 771b846db4..43503a6c78 100644 --- a/jmx/src/main/java/com/facebook/airlift/jmx/JmxModule.java +++ b/jmx/src/main/java/com/facebook/airlift/jmx/JmxModule.java @@ -47,13 +47,9 @@ public void configure(Binder binder) discoveryBinder(binder).bindServiceAnnouncement(JmxAnnouncementProvider.class); - if (JavaVersion.current().getMajor() < 9) { - binder.bind(JmxAgent8.class).in(Scopes.SINGLETON); - binder.bind(JmxAgent.class).to(JmxAgent8.class); - } - else { - binder.bind(JmxAgent9.class).in(Scopes.SINGLETON); - binder.bind(JmxAgent.class).to(JmxAgent9.class); + if (JavaVersion.current().getMajor() == 21) { + binder.bind(JmxAgent21.class).in(Scopes.SINGLETON); + binder.bind(JmxAgent.class).to(JmxAgent21.class); } } diff --git a/jmx/src/test/java/com/facebook/airlift/jmx/TestJmxAgent.java b/jmx/src/test/java/com/facebook/airlift/jmx/TestJmxAgent.java index e0412a6507..2d3d705c9b 100644 --- a/jmx/src/test/java/com/facebook/airlift/jmx/TestJmxAgent.java +++ b/jmx/src/test/java/com/facebook/airlift/jmx/TestJmxAgent.java @@ -1,6 +1,5 @@ package com.facebook.airlift.jmx; -import com.google.common.net.HostAndPort; import org.testng.SkipException; import org.testng.annotations.Test; @@ -8,47 +7,19 @@ import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; -import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; public class TestJmxAgent { @Test - public void testJava8Agent() + public void testJava21Agent() throws Exception { - if (JavaVersion.current().getMajor() > 8) { + if (JavaVersion.current().getMajor() < 21) { throw new SkipException("Incompatible Java version: " + JavaVersion.current()); } - HostAndPort address = JmxAgent8.getRunningAgentAddress(null, null); - - JmxAgent agent = new JmxAgent8(new JmxConfig()); - if (address == null) { - // if agent wasn't running, it must have been started by the instantiation of JmxAgent - address = JmxAgent8.getRunningAgentAddress(null, null); - assertNotNull(address); - } - - JMXServiceURL url = agent.getUrl(); - - assertEquals(url.toString(), format("service:jmx:rmi:///jndi/rmi://%s:%s/jmxrmi", address.getHost(), address.getPort())); - - JMXConnector connector = JMXConnectorFactory.connect(url); - connector.connect(); - } - - @Test - public void testJava9Agent() - throws Exception - { - if (JavaVersion.current().getMajor() < 9) { - throw new SkipException("Incompatible Java version: " + JavaVersion.current()); - } - - JmxAgent agent = new JmxAgent9(new JmxConfig()); + JmxAgent agent = new JmxAgent21(new JmxConfig()); JMXServiceURL url = agent.getUrl(); diff --git a/log-manager/pom.xml b/log-manager/pom.xml index adc32c6fc9..97b5b3bac4 100644 --- a/log-manager/pom.xml +++ b/log-manager/pom.xml @@ -13,6 +13,9 @@ ${project.parent.basedir} + + --add-opens java.base/java.lang=ALL-UNNAMED + @@ -27,7 +30,7 @@ - io.airlift + com.facebook.airlift units diff --git a/node/pom.xml b/node/pom.xml index a80837651d..877751b945 100644 --- a/node/pom.xml +++ b/node/pom.xml @@ -13,6 +13,9 @@ ${project.parent.basedir} + + --add-opens java.base/java.lang=ALL-UNNAMED + diff --git a/node/src/main/java/com/facebook/airlift/node/testing/TestingNodeModule.java b/node/src/main/java/com/facebook/airlift/node/testing/TestingNodeModule.java index e8d8061b13..e66aef2200 100644 --- a/node/src/main/java/com/facebook/airlift/node/testing/TestingNodeModule.java +++ b/node/src/main/java/com/facebook/airlift/node/testing/TestingNodeModule.java @@ -78,9 +78,7 @@ public void configure(Binder binder) .setNodeInternalAddress(InetAddresses.toAddrString(getV4Localhost())) .setNodeBindIp(getV4Localhost()); - if (pool.isPresent()) { - nodeConfig.setPool(pool.get()); - } + pool.ifPresent(nodeConfig::setPool); binder.bind(NodeConfig.class).toInstance(nodeConfig); diff --git a/pom.xml b/pom.xml index ae4347903d..0b82d83425 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ com.facebook.airlift airbase - 100 + 104-SNAPSHOT 2010 @@ -23,13 +23,13 @@ true true true - 1.8.0-40 + 21 0.216-SNAPSHOT ${dep.airlift.version} 9.4.55.v20240627 2.26 - 1.31 + 1.40-SNAPSHOT @@ -235,7 +235,7 @@ aopalliance-repackaged - io.airlift + com.facebook.airlift units @@ -298,9 +298,9 @@ - io.airlift + com.facebook.airlift units - 1.0 + 1.4-SNAPSHOT diff --git a/sample-server/pom.xml b/sample-server/pom.xml index f9d1c1847a..b8ccb396da 100644 --- a/sample-server/pom.xml +++ b/sample-server/pom.xml @@ -13,6 +13,9 @@ ${project.parent.basedir} com.facebook.airlift.sample.Main + + --add-opens java.base/java.lang=ALL-UNNAMED + @@ -118,7 +121,7 @@ - io.airlift + com.facebook.airlift units @@ -135,6 +138,7 @@ com.facebook.airlift http-client + runtime diff --git a/security/pom.xml b/security/pom.xml index a0e8e83a2d..54b0294766 100644 --- a/security/pom.xml +++ b/security/pom.xml @@ -22,7 +22,7 @@ - io.airlift + com.facebook.airlift units diff --git a/security/src/main/java/com/facebook/airlift/security/pem/PemReader.java b/security/src/main/java/com/facebook/airlift/security/pem/PemReader.java index 2b5e99d9f8..41895c512f 100644 --- a/security/src/main/java/com/facebook/airlift/security/pem/PemReader.java +++ b/security/src/main/java/com/facebook/airlift/security/pem/PemReader.java @@ -209,12 +209,10 @@ public static PrivateKey loadPrivateKey(String privateKey, Optional keyP encodedKeySpec = new PKCS8EncodedKeySpec(encodedKey); } else if ("ENCRYPTED".equals(keyType)) { - if (!keyPassword.isPresent()) { - throw new KeyStoreException("Private key is encrypted, but no password was provided"); - } + String password = keyPassword.orElseThrow(() -> new KeyStoreException("Private key is encrypted, but no password was provided")); EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(encodedKey); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(encryptedPrivateKeyInfo.getAlgName()); - SecretKey secretKey = keyFactory.generateSecret(new PBEKeySpec(keyPassword.get().toCharArray())); + SecretKey secretKey = keyFactory.generateSecret(new PBEKeySpec(password.toCharArray())); Cipher cipher = Cipher.getInstance(encryptedPrivateKeyInfo.getAlgName()); cipher.init(DECRYPT_MODE, secretKey, encryptedPrivateKeyInfo.getAlgParameters()); diff --git a/security/src/test/java/com/facebook/airlift/security/pem/TestPemReader.java b/security/src/test/java/com/facebook/airlift/security/pem/TestPemReader.java index 2097fc2178..abeb38d672 100644 --- a/security/src/test/java/com/facebook/airlift/security/pem/TestPemReader.java +++ b/security/src/test/java/com/facebook/airlift/security/pem/TestPemReader.java @@ -45,7 +45,7 @@ import static com.facebook.airlift.security.pem.PemWriter.writeCertificate; import static com.facebook.airlift.security.pem.PemWriter.writePrivateKey; import static com.facebook.airlift.security.pem.PemWriter.writePublicKey; -import static com.google.common.collect.Iterables.getOnlyElement; +import static com.google.common.collect.MoreCollectors.onlyElement; import static com.google.common.io.Files.asCharSource; import static java.nio.charset.StandardCharsets.US_ASCII; import static org.testng.Assert.assertEquals; @@ -123,7 +123,7 @@ private static void testLoadPublicKey(String certFile, String keyFile) { PublicKey publicKey = loadPublicKey(getResourceFile(keyFile)); assertNotNull(publicKey); - X509Certificate certificate = getOnlyElement(readCertificateChain(getResourceFile(certFile))); + X509Certificate certificate = readCertificateChain(getResourceFile(certFile)).stream().collect(onlyElement()); assertEquals(publicKey, certificate.getPublicKey()); String encodedPrivateKey = writePublicKey(publicKey); @@ -170,7 +170,7 @@ private static void assertCertificateChain(KeyStore keyStore, String expectedNam assertX509Certificate(x509Certificate, expectedName); - X509Certificate certificateCopy = getOnlyElement(readCertificateChain(writeCertificate(x509Certificate))); + X509Certificate certificateCopy = readCertificateChain(writeCertificate(x509Certificate)).stream().collect(onlyElement()); assertX509Certificate(certificateCopy, expectedName); } diff --git a/skeleton-server/pom.xml b/skeleton-server/pom.xml index a2a47ea13b..561c2279e3 100644 --- a/skeleton-server/pom.xml +++ b/skeleton-server/pom.xml @@ -84,6 +84,7 @@ javax.ws.rs javax.ws.rs-api + runtime @@ -99,6 +100,7 @@ com.facebook.airlift http-client + runtime diff --git a/stats/pom.xml b/stats/pom.xml index 5714ff4744..ff01001ce7 100644 --- a/stats/pom.xml +++ b/stats/pom.xml @@ -33,7 +33,7 @@ - io.airlift + com.facebook.airlift units @@ -64,8 +64,9 @@ - io.airlift + com.facebook slice + 0.38-SNAPSHOT diff --git a/stats/src/main/java/com/facebook/airlift/stats/QuantileDigest.java b/stats/src/main/java/com/facebook/airlift/stats/QuantileDigest.java index a26b838dd2..3815a08088 100644 --- a/stats/src/main/java/com/facebook/airlift/stats/QuantileDigest.java +++ b/stats/src/main/java/com/facebook/airlift/stats/QuantileDigest.java @@ -1,5 +1,11 @@ package com.facebook.airlift.stats; +import com.facebook.slice.BasicSliceInput; +import com.facebook.slice.DynamicSliceOutput; +import com.facebook.slice.SizeOf; +import com.facebook.slice.Slice; +import com.facebook.slice.SliceInput; +import com.facebook.slice.SliceOutput; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Ticker; @@ -10,12 +16,6 @@ import com.google.common.collect.Ordering; import com.google.common.collect.PeekingIterator; import com.google.common.util.concurrent.AtomicDouble; -import io.airlift.slice.BasicSliceInput; -import io.airlift.slice.DynamicSliceOutput; -import io.airlift.slice.SizeOf; -import io.airlift.slice.Slice; -import io.airlift.slice.SliceInput; -import io.airlift.slice.SliceOutput; import org.openjdk.jol.info.ClassLayout; import javax.annotation.concurrent.NotThreadSafe; diff --git a/stats/src/main/java/com/facebook/airlift/stats/cardinality/DenseHll.java b/stats/src/main/java/com/facebook/airlift/stats/cardinality/DenseHll.java index 5a7848a5d5..35f079da90 100644 --- a/stats/src/main/java/com/facebook/airlift/stats/cardinality/DenseHll.java +++ b/stats/src/main/java/com/facebook/airlift/stats/cardinality/DenseHll.java @@ -13,13 +13,13 @@ */ package com.facebook.airlift.stats.cardinality; +import com.facebook.slice.BasicSliceInput; +import com.facebook.slice.DynamicSliceOutput; +import com.facebook.slice.SizeOf; +import com.facebook.slice.Slice; import com.google.common.annotations.VisibleForTesting; import com.google.common.primitives.Bytes; import com.google.common.primitives.Ints; -import io.airlift.slice.BasicSliceInput; -import io.airlift.slice.DynamicSliceOutput; -import io.airlift.slice.SizeOf; -import io.airlift.slice.Slice; import org.openjdk.jol.info.ClassLayout; import java.util.Arrays; diff --git a/stats/src/main/java/com/facebook/airlift/stats/cardinality/HllInstance.java b/stats/src/main/java/com/facebook/airlift/stats/cardinality/HllInstance.java index 6b8bbcd247..6a12427c3a 100644 --- a/stats/src/main/java/com/facebook/airlift/stats/cardinality/HllInstance.java +++ b/stats/src/main/java/com/facebook/airlift/stats/cardinality/HllInstance.java @@ -13,8 +13,8 @@ */ package com.facebook.airlift.stats.cardinality; +import com.facebook.slice.Slice; import com.google.common.annotations.VisibleForTesting; -import io.airlift.slice.Slice; interface HllInstance { diff --git a/stats/src/main/java/com/facebook/airlift/stats/cardinality/HyperLogLog.java b/stats/src/main/java/com/facebook/airlift/stats/cardinality/HyperLogLog.java index 93f798baf9..971377cf5f 100644 --- a/stats/src/main/java/com/facebook/airlift/stats/cardinality/HyperLogLog.java +++ b/stats/src/main/java/com/facebook/airlift/stats/cardinality/HyperLogLog.java @@ -13,9 +13,9 @@ */ package com.facebook.airlift.stats.cardinality; +import com.facebook.slice.Murmur3Hash128; +import com.facebook.slice.Slice; import com.google.common.annotations.VisibleForTesting; -import io.airlift.slice.Murmur3Hash128; -import io.airlift.slice.Slice; import org.openjdk.jol.info.ClassLayout; import static com.facebook.airlift.stats.cardinality.Utils.indexBitLength; @@ -68,7 +68,7 @@ public void add(Slice value) * Adds a value that has already been hashed to the set of values tracked by this HyperLogLog instance. * * @param hash The hash should be the 64 least significant bits of the murmur3_128 hash of the value. - * For example: io.airlift.slice.Murmur3.hash64(value). + * For example: com.facebook.slice.Murmur3.hash64(value). */ public void addHash(long hash) { diff --git a/stats/src/main/java/com/facebook/airlift/stats/cardinality/PrivateLpcaSketch.java b/stats/src/main/java/com/facebook/airlift/stats/cardinality/PrivateLpcaSketch.java index 0faf08200d..fe1e4542d7 100644 --- a/stats/src/main/java/com/facebook/airlift/stats/cardinality/PrivateLpcaSketch.java +++ b/stats/src/main/java/com/facebook/airlift/stats/cardinality/PrivateLpcaSketch.java @@ -13,11 +13,11 @@ */ package com.facebook.airlift.stats.cardinality; +import com.facebook.slice.BasicSliceInput; +import com.facebook.slice.DynamicSliceOutput; +import com.facebook.slice.SizeOf; +import com.facebook.slice.Slice; import com.google.common.annotations.VisibleForTesting; -import io.airlift.slice.BasicSliceInput; -import io.airlift.slice.DynamicSliceOutput; -import io.airlift.slice.SizeOf; -import io.airlift.slice.Slice; import javax.annotation.concurrent.NotThreadSafe; diff --git a/stats/src/main/java/com/facebook/airlift/stats/cardinality/SparseHll.java b/stats/src/main/java/com/facebook/airlift/stats/cardinality/SparseHll.java index 1052d0574b..cdfaa962b4 100644 --- a/stats/src/main/java/com/facebook/airlift/stats/cardinality/SparseHll.java +++ b/stats/src/main/java/com/facebook/airlift/stats/cardinality/SparseHll.java @@ -13,13 +13,13 @@ */ package com.facebook.airlift.stats.cardinality; +import com.facebook.slice.BasicSliceInput; +import com.facebook.slice.DynamicSliceOutput; +import com.facebook.slice.SizeOf; +import com.facebook.slice.Slice; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Ordering; import com.google.common.primitives.Ints; -import io.airlift.slice.BasicSliceInput; -import io.airlift.slice.DynamicSliceOutput; -import io.airlift.slice.SizeOf; -import io.airlift.slice.Slice; import org.openjdk.jol.info.ClassLayout; import java.util.Arrays; @@ -28,9 +28,9 @@ import static com.facebook.airlift.stats.cardinality.Utils.linearCounting; import static com.facebook.airlift.stats.cardinality.Utils.numberOfBuckets; import static com.facebook.airlift.stats.cardinality.Utils.numberOfLeadingZeros; +import static com.facebook.slice.SizeOf.sizeOf; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; -import static io.airlift.slice.SizeOf.sizeOf; import static java.lang.Math.toIntExact; import static java.util.Comparator.comparingInt; diff --git a/stats/src/test/java/com/facebook/airlift/stats/BenchmarkQuantileDigest.java b/stats/src/test/java/com/facebook/airlift/stats/BenchmarkQuantileDigest.java index 3969280a3f..e7e7b332c4 100644 --- a/stats/src/test/java/com/facebook/airlift/stats/BenchmarkQuantileDigest.java +++ b/stats/src/test/java/com/facebook/airlift/stats/BenchmarkQuantileDigest.java @@ -1,7 +1,7 @@ package com.facebook.airlift.stats; +import com.facebook.slice.Slice; import com.google.common.collect.ImmutableList; -import io.airlift.slice.Slice; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Measurement; diff --git a/stats/src/test/java/com/facebook/airlift/stats/TestQuantileDigest.java b/stats/src/test/java/com/facebook/airlift/stats/TestQuantileDigest.java index 3834d72c90..e7bbc429cc 100644 --- a/stats/src/test/java/com/facebook/airlift/stats/TestQuantileDigest.java +++ b/stats/src/test/java/com/facebook/airlift/stats/TestQuantileDigest.java @@ -1,10 +1,10 @@ package com.facebook.airlift.stats; import com.facebook.airlift.testing.TestingTicker; +import com.facebook.slice.Slice; import com.google.common.base.Ticker; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; -import io.airlift.slice.Slice; import org.testng.annotations.Test; import java.io.IOException; diff --git a/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestDenseHll.java b/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestDenseHll.java index b7efe4895c..e1dc85fc37 100644 --- a/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestDenseHll.java +++ b/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestDenseHll.java @@ -13,7 +13,7 @@ */ package com.facebook.airlift.stats.cardinality; -import io.airlift.slice.XxHash64; +import com.facebook.slice.XxHash64; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -22,7 +22,7 @@ import static com.facebook.airlift.stats.cardinality.TestUtils.createHashForBucket; import static com.facebook.airlift.stats.cardinality.TestUtils.sequence; import static com.facebook.airlift.stats.cardinality.Utils.numberOfBuckets; -import static io.airlift.slice.testing.SliceAssertions.assertSlicesEqual; +import static com.facebook.slice.testing.SliceAssertions.assertSlicesEqual; import static org.testng.Assert.assertEquals; public class TestDenseHll diff --git a/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestDenseSerialization.java b/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestDenseSerialization.java index 3d294db171..8460226a52 100644 --- a/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestDenseSerialization.java +++ b/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestDenseSerialization.java @@ -13,14 +13,14 @@ */ package com.facebook.airlift.stats.cardinality; -import io.airlift.slice.DynamicSliceOutput; -import io.airlift.slice.Murmur3Hash128; -import io.airlift.slice.Slice; -import io.airlift.slice.SliceOutput; +import com.facebook.slice.DynamicSliceOutput; +import com.facebook.slice.Murmur3Hash128; +import com.facebook.slice.Slice; +import com.facebook.slice.SliceOutput; import org.testng.annotations.Test; import static com.facebook.airlift.stats.cardinality.Utils.numberOfBuckets; -import static io.airlift.slice.testing.SliceAssertions.assertSlicesEqual; +import static com.facebook.slice.testing.SliceAssertions.assertSlicesEqual; import static org.testng.Assert.assertEquals; public class TestDenseSerialization diff --git a/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestHyperLogLog.java b/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestHyperLogLog.java index 6dd0b0816c..3ae1ccae7e 100644 --- a/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestHyperLogLog.java +++ b/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestHyperLogLog.java @@ -13,7 +13,7 @@ */ package com.facebook.airlift.stats.cardinality; -import io.airlift.slice.Slice; +import com.facebook.slice.Slice; import org.openjdk.jol.info.ClassLayout; import org.testng.annotations.Test; @@ -23,7 +23,7 @@ import java.util.concurrent.ThreadLocalRandom; import static com.facebook.airlift.stats.cardinality.TestUtils.sequence; -import static io.airlift.slice.testing.SliceAssertions.assertSlicesEqual; +import static com.facebook.slice.testing.SliceAssertions.assertSlicesEqual; import static java.lang.Math.toIntExact; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; diff --git a/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestPrivateLpcaSketch.java b/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestPrivateLpcaSketch.java index 2c0574f7f6..4ec12f163d 100644 --- a/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestPrivateLpcaSketch.java +++ b/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestPrivateLpcaSketch.java @@ -13,10 +13,10 @@ */ package com.facebook.airlift.stats.cardinality; -import io.airlift.slice.Slice; +import com.facebook.slice.Slice; import org.testng.annotations.Test; -import static io.airlift.slice.testing.SliceAssertions.assertSlicesEqual; +import static com.facebook.slice.testing.SliceAssertions.assertSlicesEqual; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; diff --git a/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestSparseHll.java b/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestSparseHll.java index 3f936110f5..a5b6880dbd 100644 --- a/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestSparseHll.java +++ b/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestSparseHll.java @@ -13,8 +13,8 @@ */ package com.facebook.airlift.stats.cardinality; +import com.facebook.slice.Murmur3Hash128; import com.google.common.collect.ImmutableList; -import io.airlift.slice.Murmur3Hash128; import org.openjdk.jol.info.ClassLayout; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -22,8 +22,8 @@ import java.util.List; import static com.facebook.airlift.stats.cardinality.TestUtils.sequence; -import static io.airlift.slice.SizeOf.sizeOf; -import static io.airlift.slice.testing.SliceAssertions.assertSlicesEqual; +import static com.facebook.slice.SizeOf.sizeOf; +import static com.facebook.slice.testing.SliceAssertions.assertSlicesEqual; import static org.testng.Assert.assertEquals; public class TestSparseHll diff --git a/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestSparseSerialization.java b/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestSparseSerialization.java index 6cb14b98be..00f5e04eea 100644 --- a/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestSparseSerialization.java +++ b/stats/src/test/java/com/facebook/airlift/stats/cardinality/TestSparseSerialization.java @@ -13,13 +13,13 @@ */ package com.facebook.airlift.stats.cardinality; -import io.airlift.slice.DynamicSliceOutput; -import io.airlift.slice.Murmur3Hash128; -import io.airlift.slice.Slice; -import io.airlift.slice.Slices; +import com.facebook.slice.DynamicSliceOutput; +import com.facebook.slice.Murmur3Hash128; +import com.facebook.slice.Slice; +import com.facebook.slice.Slices; import org.testng.annotations.Test; -import static io.airlift.slice.testing.SliceAssertions.assertSlicesEqual; +import static com.facebook.slice.testing.SliceAssertions.assertSlicesEqual; public class TestSparseSerialization {