From 986334e9198a1756b839d0d13028f4a846ea29b5 Mon Sep 17 00:00:00 2001 From: Bill Burcham Date: Thu, 5 Nov 2020 12:28:55 -0800 Subject: [PATCH] Revert "GEODE-8136: Move UncheckedUtils to geode-common (#5123)" This reverts commit 10af7ea015ec85ef02b2e972c7a3dd3ec23bcb7f. --- .../util/internal/UncheckedUtilsTest.java | 60 ------------------- .../PartitionedRegionSingleHopDUnitTest.java | 14 ++--- ...butedRegionFunctionExecutionDUnitTest.java | 59 ++++++++++++------ ...WithColocationAndPersistenceDUnitTest.java | 12 ++-- ...unctionExecutionOnLonerRegressionTest.java | 27 +++++++-- .../internal/ClientMetadataService.java | 4 +- .../internal/cache/GemFireCacheImpl.java | 49 +++++++++++---- .../cache/InternalCacheForClientAccess.java | 6 +- .../geode/internal/cache/LocalRegion.java | 7 +-- .../execute/util/TypedFunctionService.java | 37 ------------ .../tier/sockets/CacheClientProxyFactory.java | 4 +- .../internal/cache/util}/UncheckedUtils.java | 19 +++--- .../internal/ClusterAlertMessagingTest.java | 6 +- .../geode/internal/tcp/TCPConduitTest.java | 4 +- 14 files changed, 134 insertions(+), 174 deletions(-) delete mode 100644 geode-common/src/test/java/org/apache/geode/util/internal/UncheckedUtilsTest.java delete mode 100644 geode-core/src/main/java/org/apache/geode/internal/cache/execute/util/TypedFunctionService.java rename {geode-common/src/main/java/org/apache/geode/util/internal => geode-core/src/main/java/org/apache/geode/internal/cache/util}/UncheckedUtils.java (68%) diff --git a/geode-common/src/test/java/org/apache/geode/util/internal/UncheckedUtilsTest.java b/geode-common/src/test/java/org/apache/geode/util/internal/UncheckedUtilsTest.java deleted file mode 100644 index 7c282b7111fc..000000000000 --- a/geode-common/src/test/java/org/apache/geode/util/internal/UncheckedUtilsTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.util.internal; - -import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.catchThrowable; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; - -@SuppressWarnings("unchecked") -public class UncheckedUtilsTest { - - @Test - public void uncheckedCast_rawList_empty() { - List rawList = new ArrayList(); - - List value = uncheckedCast(rawList); - - assertThat(value).isSameAs(rawList); - } - - @Test - public void uncheckedCast_rawList_nonEmpty() { - List rawList = new ArrayList(); - rawList.add("1"); - rawList.add("2"); - - List value = uncheckedCast(rawList); - - assertThat(value).isSameAs(rawList); - } - - @Test - public void uncheckedCast_rawList_wrongTypes() { - List rawList = new ArrayList(); - rawList.add(1); - rawList.add(2); - List wrongType = uncheckedCast(rawList); - - Throwable thrown = catchThrowable(() -> wrongType.get(0)); - - assertThat(thrown).isInstanceOf(ClassCastException.class); - } -} diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/PartitionedRegionSingleHopDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/PartitionedRegionSingleHopDUnitTest.java index 43019bf91965..943c50356eda 100755 --- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/PartitionedRegionSingleHopDUnitTest.java +++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/PartitionedRegionSingleHopDUnitTest.java @@ -22,6 +22,7 @@ import static org.apache.geode.cache.RegionShortcut.PARTITION_PERSISTENT; import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION; import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; +import static org.apache.geode.internal.cache.util.UncheckedUtils.cast; import static org.apache.geode.internal.lang.SystemPropertyHelper.GEMFIRE_PREFIX; import static org.apache.geode.management.ManagementService.getExistingManagementService; import static org.apache.geode.test.awaitility.GeodeAwaitility.await; @@ -31,7 +32,6 @@ import static org.apache.geode.test.dunit.VM.getVM; import static org.apache.geode.test.dunit.VM.getVMId; import static org.apache.geode.test.dunit.rules.DistributedRule.getDistributedSystemProperties; -import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -76,6 +76,7 @@ import org.apache.geode.cache.client.internal.InternalClientCache; import org.apache.geode.cache.execute.FunctionAdapter; import org.apache.geode.cache.execute.FunctionContext; +import org.apache.geode.cache.execute.FunctionService; import org.apache.geode.cache.execute.RegionFunctionContext; import org.apache.geode.cache.server.CacheServer; import org.apache.geode.distributed.LocatorLauncher; @@ -83,7 +84,6 @@ import org.apache.geode.distributed.internal.ServerLocation; import org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile; import org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException; -import org.apache.geode.internal.cache.execute.util.TypedFunctionService; import org.apache.geode.management.ManagementService; import org.apache.geode.management.membership.MembershipEvent; import org.apache.geode.management.membership.UniversalMembershipListenerAdapter; @@ -1336,22 +1336,22 @@ private void doGets() { } private void executeFunctions(Region region) { - TypedFunctionService.onRegion(region) + cast(FunctionService.onRegion(region)) .withFilter(filter(0)) .execute(new PutFunction()) .getResult(); - TypedFunctionService.onRegion(region) + cast(FunctionService.onRegion(region)) .withFilter(filter(0, 1)) .execute(new PutFunction()) .getResult(); - TypedFunctionService.onRegion(region) + cast(FunctionService.onRegion(region)) .withFilter(filter(0, 1, 2, 3)) .execute(new PutFunction()) .getResult(); - TypedFunctionService.onRegion(region) + cast(FunctionService.onRegion(region)) .execute(new PutFunction()) .getResult(); } @@ -1389,7 +1389,7 @@ private File[] getDiskDirs() throws IOException { } private InternalCache getInternalCache(ServerLauncher serverLauncher) { - return uncheckedCast(serverLauncher.getCache()); + return cast(serverLauncher.getCache()); } private void waitForLocalBucketsCreation() { diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/DistributedRegionFunctionExecutionDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/DistributedRegionFunctionExecutionDUnitTest.java index b308b2085150..b95a68bf71c8 100755 --- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/DistributedRegionFunctionExecutionDUnitTest.java +++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/execute/DistributedRegionFunctionExecutionDUnitTest.java @@ -22,13 +22,13 @@ import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_CLIENT_AUTHENTICATOR; import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_CLIENT_AUTH_INIT; import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER; +import static org.apache.geode.internal.cache.execute.DistributedRegionFunctionExecutionDUnitTest.UncheckedUtils.cast; import static org.apache.geode.test.awaitility.GeodeAwaitility.getTimeout; import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException; import static org.apache.geode.test.dunit.VM.getController; import static org.apache.geode.test.dunit.VM.getVM; import static org.apache.geode.test.dunit.VM.toArray; import static org.apache.geode.util.internal.GeodeGlossary.GEMFIRE_PREFIX; -import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; @@ -59,6 +59,7 @@ import org.apache.geode.cache.client.PoolFactory; import org.apache.geode.cache.client.PoolManager; import org.apache.geode.cache.client.internal.InternalClientCache; +import org.apache.geode.cache.execute.Execution; import org.apache.geode.cache.execute.Function; import org.apache.geode.cache.execute.FunctionContext; import org.apache.geode.cache.execute.FunctionException; @@ -69,7 +70,6 @@ import org.apache.geode.cache.server.CacheServer; import org.apache.geode.distributed.internal.InternalDistributedSystem; import org.apache.geode.internal.cache.InternalCache; -import org.apache.geode.internal.cache.execute.util.TypedFunctionService; import org.apache.geode.security.templates.DummyAuthenticator; import org.apache.geode.security.templates.UserPasswordAuthInit; import org.apache.geode.test.dunit.AsyncInvocation; @@ -257,7 +257,7 @@ public void testDistributedRegionFunctionExecutionOnDataPolicyReplicateNotTimedO empty.invoke(() -> populateRegion(200)); AsyncInvocation executeFunctionInReplicate1 = replicate1.invokeAsync(() -> { - ResultCollector> resultCollector = TypedFunctionService + ResultCollector> resultCollector = FunctionServiceCast .>onRegion(getRegion()) .withFilter(filter) .execute(LongRunningFunction.class.getSimpleName(), getTimeout().toMillis(), @@ -302,7 +302,7 @@ public void testDistributedRegionFunctionExecutionOnDataPolicyReplicateTimedOut( replicate1.invoke(() -> { Throwable thrown = catchThrowable(() -> { - TypedFunctionService + FunctionServiceCast .>onRegion(getRegion()) .withFilter(filter) .execute(LongRunningFunction.class.getSimpleName(), 1000, MILLISECONDS); @@ -950,7 +950,7 @@ public void inlineFunctionIsUsedOnClientInsteadOfLookingUpFunctionById() { } client.invoke(() -> { - ResultCollector> resultCollector = TypedFunctionService + ResultCollector> resultCollector = FunctionServiceCast .>onRegion(getRegion()) .setArguments(true) .execute(inlineFunction("Success", true)); @@ -1158,13 +1158,13 @@ private void registerThrowsFunctionInvocationTargetExceptionFunction(boolean isH } private void executeNoResultFunction() { - TypedFunctionService + FunctionServiceCast .onRegion(getRegion()) .execute(new NoResultFunction()); } private List executeDistributedRegionFunction() { - return TypedFunctionService + return FunctionServiceCast .>onRegion(getRegion()) .withFilter(filter) .setArguments(false) @@ -1173,7 +1173,7 @@ private List executeDistributedRegionFunction() { } private void executeThrowsRuntimeExceptionFunction() { - TypedFunctionService + FunctionServiceCast .onRegion(getRegion()) .withFilter(filter) .execute(new ThrowsRuntimeExceptionFunction()); @@ -1187,7 +1187,7 @@ private void executeResultWithExceptionFunction() { filter.add("execKey-" + 100 + i); } - ResultCollector> resultCollector = TypedFunctionService + ResultCollector> resultCollector = FunctionServiceCast .>onRegion(getRegion()) .withFilter(filter) .setArguments(true) @@ -1200,7 +1200,7 @@ private void executeResultWithExceptionFunction() { .as("First element of " + resultCollector.getResult()) .isInstanceOf(CustomRuntimeException.class); - resultCollector = TypedFunctionService + resultCollector = FunctionServiceCast ., Object, List>onRegion(getRegion()) .withFilter(filter) .setArguments(filter) @@ -1220,7 +1220,7 @@ private void executeResultWithExceptionFunction() { private void executeNoLastResultFunction() { Throwable thrown = catchThrowable(() -> { - TypedFunctionService + FunctionServiceCast .onRegion(getRegion()) .withFilter(filter) .execute(new NoLastResultFunction()) @@ -1234,7 +1234,7 @@ private void executeNoLastResultFunction() { private void executeUnregisteredFunction() { FunctionService.unregisterFunction(new DistributedRegionFunction().getId()); - TypedFunctionService + FunctionServiceCast .>onRegion(getRegion()) .withFilter(filter) .execute(new DistributedRegionFunction()) @@ -1242,7 +1242,7 @@ private void executeUnregisteredFunction() { } private void executeFunctionFunctionInvocationTargetException() { - ResultCollector> resultCollector = TypedFunctionService + ResultCollector> resultCollector = FunctionServiceCast .>onRegion(getRegion()) .setArguments(true) .execute(ThrowsFunctionInvocationTargetExceptionFunction.class.getSimpleName()); @@ -1253,7 +1253,7 @@ private void executeFunctionFunctionInvocationTargetException() { private void executeFunctionFunctionInvocationTargetExceptionWithoutHA() { Throwable thrown = catchThrowable(() -> { - TypedFunctionService + FunctionServiceCast .>onRegion(getRegion()) .setArguments(true) .execute(ThrowsFunctionInvocationTargetExceptionFunction.class.getSimpleName()) @@ -1268,7 +1268,7 @@ private void executeFunctionFunctionInvocationTargetExceptionWithoutHA() { } private void executeFunctionFunctionInvocationTargetException_ClientServer() { - ResultCollector> resultCollector = TypedFunctionService + ResultCollector> resultCollector = FunctionServiceCast .>onRegion(getRegion()) .setArguments(true) .execute(ThrowsFunctionInvocationTargetExceptionFunction.class.getSimpleName()); @@ -1279,7 +1279,7 @@ private void executeFunctionFunctionInvocationTargetException_ClientServer() { private void executeFunctionFunctionInvocationTargetException_ClientServer_WithoutHA() { Throwable thrown = catchThrowable(() -> { - TypedFunctionService + FunctionServiceCast .>onRegion(getRegion()) .setArguments(true) .execute(ThrowsFunctionInvocationTargetExceptionFunction.class.getSimpleName()) @@ -1294,7 +1294,7 @@ private void executeFunctionFunctionInvocationTargetException_ClientServer_Witho } private static Region getRegion() { - return uncheckedCast(REGION.get()); + return cast(REGION.get()); } private static void setRegion(Region region) { @@ -1327,8 +1327,7 @@ private static class ResultWithExceptionFunction implements Function { @Override public void execute(FunctionContext context) { if (context.getArguments() instanceof Set) { - Set arguments = - uncheckedCast(context.getArguments()); + Set arguments = cast(context.getArguments()); for (int i = 0; i < arguments.size(); i++) { context.getResultSender().sendResult(i); } @@ -1558,4 +1557,26 @@ public int compare(Object o1, Object o2) { return -1; } } + + @SuppressWarnings("unchecked") + static class FunctionServiceCast { + + /** + * Provide unchecked cast of FunctionService.onRegion. + */ + static Execution onRegion(Region region) { + return FunctionService.onRegion(region); + } + } + + @SuppressWarnings({"unchecked", "unused"}) + static class UncheckedUtils { + + /** + * Provide unchecked cast of specified Object. + */ + static T cast(Object object) { + return (T) object; + } + } } diff --git a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/fixed/FixedPartitioningWithColocationAndPersistenceDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/fixed/FixedPartitioningWithColocationAndPersistenceDUnitTest.java index 99db19a0a6fb..ea7c834408a4 100644 --- a/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/fixed/FixedPartitioningWithColocationAndPersistenceDUnitTest.java +++ b/geode-core/src/distributedTest/java/org/apache/geode/internal/cache/partitioned/fixed/FixedPartitioningWithColocationAndPersistenceDUnitTest.java @@ -36,10 +36,10 @@ import static org.apache.geode.internal.cache.partitioned.fixed.FixedPartitioningWithColocationAndPersistenceDUnitTest.Quarter.Q2; import static org.apache.geode.internal.cache.partitioned.fixed.FixedPartitioningWithColocationAndPersistenceDUnitTest.Quarter.Q3; import static org.apache.geode.internal.cache.partitioned.fixed.FixedPartitioningWithColocationAndPersistenceDUnitTest.Quarter.Q4; +import static org.apache.geode.internal.cache.util.UncheckedUtils.cast; import static org.apache.geode.test.awaitility.GeodeAwaitility.await; import static org.apache.geode.test.dunit.VM.getVM; import static org.apache.geode.test.dunit.VM.getVMId; -import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; import static org.mockito.Mockito.mock; @@ -1502,9 +1502,9 @@ private Region getLocalDataSet(Region region) { PartitionedRegionDataStore dataStore = partitionedRegion.getDataStore(); if (dataStore != null) { - return uncheckedCast(new LocalDataSet(partitionedRegion, dataStore.getAllLocalBucketIds())); + return cast(new LocalDataSet(partitionedRegion, dataStore.getAllLocalBucketIds())); } - return uncheckedCast(new LocalDataSet(partitionedRegion, emptySet())); + return cast(new LocalDataSet(partitionedRegion, emptySet())); } private void validateQuartersData() throws ParseException { @@ -1555,20 +1555,20 @@ private void validateColocatedData(int count) { InternalDistributedMember idmForShipment = shipments.getBucketPrimary(i); // take all the keys from the shipment for each bucket - Set customerKey = uncheckedCast(customers.getBucketKeys(i)); + Set customerKey = cast(customers.getBucketKeys(i)); assertThat(customerKey).isNotNull(); for (CustomerId customerId : customerKey) { assertThat(customers.get(customerId)).isNotNull(); - Set orderKey = uncheckedCast(orders.getBucketKeys(i)); + Set orderKey = cast(orders.getBucketKeys(i)); for (OrderId orderId : orderKey) { assertThat(orders.get(orderId)).isNotNull(); if (orderId.getCustomerId().equals(customerId)) { assertThat(idmForOrder).isEqualTo(idmForCustomer); } - Set shipmentKey = uncheckedCast(shipments.getBucketKeys(i)); + Set shipmentKey = cast(shipments.getBucketKeys(i)); for (ShipmentId shipmentId : shipmentKey) { assertThat(shipments.get(shipmentId)).isNotNull(); if (shipmentId.getOrderId().equals(orderId)) { diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/execute/FunctionExecutionOnLonerRegressionTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/execute/FunctionExecutionOnLonerRegressionTest.java index d0c4cbcdb5d9..08b75cfa1f51 100644 --- a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/execute/FunctionExecutionOnLonerRegressionTest.java +++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/execute/FunctionExecutionOnLonerRegressionTest.java @@ -19,7 +19,7 @@ import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER; -import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast; +import static org.apache.geode.internal.cache.execute.FunctionExecutionOnLonerRegressionTest.UncheckedUtils.cast; import static org.assertj.core.api.Assertions.assertThat; import java.util.Collection; @@ -35,14 +35,15 @@ import org.apache.geode.cache.CacheFactory; import org.apache.geode.cache.Region; +import org.apache.geode.cache.execute.Execution; import org.apache.geode.cache.execute.FunctionContext; +import org.apache.geode.cache.execute.FunctionService; import org.apache.geode.cache.execute.RegionFunctionContext; import org.apache.geode.cache.execute.ResultCollector; import org.apache.geode.cache.partition.PartitionRegionHelper; import org.apache.geode.distributed.internal.DistributionManager; import org.apache.geode.distributed.internal.LonerDistributionManager; import org.apache.geode.internal.cache.InternalCache; -import org.apache.geode.internal.cache.execute.util.TypedFunctionService; import org.apache.geode.test.junit.categories.FunctionServiceTest; /** @@ -87,7 +88,7 @@ public void executeFunctionOnLonerWithPartitionedRegionShouldNotThrowClassCastEx populateRegion(region); - ResultCollector, Collection> resultCollector = TypedFunctionService + ResultCollector, Collection> resultCollector = FunctionServiceCast ., Collection>onRegion(region) .withFilter(keysForGet) .execute(new TestFunction(DataSetSupplier.PARTITIONED)); @@ -104,7 +105,7 @@ public void executeFunctionOnLonerWithReplicateRegionShouldNotThrowClassCastExce populateRegion(region); - ResultCollector, Collection> resultCollector = TypedFunctionService + ResultCollector, Collection> resultCollector = FunctionServiceCast ., Collection>onRegion(region) .withFilter(keysForGet) .execute(new TestFunction(DataSetSupplier.REPLICATE)); @@ -166,7 +167,7 @@ private TestFunction(DataSetSupplier dataSetSupplier) { @Override public void execute(FunctionContext context) { RegionFunctionContext regionFunctionContext = (RegionFunctionContext) context; - Set keys = uncheckedCast(regionFunctionContext.getFilter()); + Set keys = cast(regionFunctionContext.getFilter()); String lastKey = keys.iterator().next(); keys.remove(lastKey); @@ -184,4 +185,20 @@ public String getId() { return getClass().getName(); } } + + @SuppressWarnings({"unchecked", "WeakerAccess"}) + private static class FunctionServiceCast { + + static Execution onRegion(Region region) { + return FunctionService.onRegion(region); + } + } + + @SuppressWarnings({"unchecked", "unused"}) + static class UncheckedUtils { + + static T cast(Object object) { + return (T) object; + } + } } diff --git a/geode-core/src/main/java/org/apache/geode/cache/client/internal/ClientMetadataService.java b/geode-core/src/main/java/org/apache/geode/cache/client/internal/ClientMetadataService.java index 8b89bb8d28b9..0aaa9df5ed56 100755 --- a/geode-core/src/main/java/org/apache/geode/cache/client/internal/ClientMetadataService.java +++ b/geode-core/src/main/java/org/apache/geode/cache/client/internal/ClientMetadataService.java @@ -14,7 +14,7 @@ */ package org.apache.geode.cache.client.internal; -import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast; +import static org.apache.geode.internal.cache.util.UncheckedUtils.cast; import java.util.ArrayList; import java.util.Collection; @@ -230,7 +230,7 @@ public Map getServerToFilterMap(final Collection routingKey for (Map.Entry entry : serverToBuckets.entrySet()) { ServerLocation server = (ServerLocation) entry.getKey(); - Set buckets = uncheckedCast(entry.getValue()); + Set buckets = cast(entry.getValue()); for (Integer bucket : buckets) { // use LinkedHashSet to maintain the order of keys // the keys will be iterated several times diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java index 2cd1f3cd6ff7..2f6b0b47c263 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java @@ -33,6 +33,10 @@ import static org.apache.geode.distributed.internal.DistributionConfig.DEFAULT_DURABLE_CLIENT_ID; import static org.apache.geode.distributed.internal.InternalDistributedSystem.getAnyInstance; import static org.apache.geode.internal.cache.ColocationHelper.getColocatedChildRegions; +import static org.apache.geode.internal.cache.GemFireCacheImpl.UncheckedUtils.asDistributedMemberSet; +import static org.apache.geode.internal.cache.GemFireCacheImpl.UncheckedUtils.createMapArray; +import static org.apache.geode.internal.cache.GemFireCacheImpl.UncheckedUtils.uncheckedCast; +import static org.apache.geode.internal.cache.GemFireCacheImpl.UncheckedUtils.uncheckedRegionAttributes; import static org.apache.geode.internal.cache.LocalRegion.setThreadInitLevelRequirement; import static org.apache.geode.internal.cache.PartitionedRegion.DISK_STORE_FLUSHED; import static org.apache.geode.internal.cache.PartitionedRegion.OFFLINE_EQUAL_PERSISTED; @@ -40,11 +44,11 @@ import static org.apache.geode.internal.cache.PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME; import static org.apache.geode.internal.cache.control.InternalResourceManager.ResourceType.HEAP_MEMORY; import static org.apache.geode.internal.cache.control.InternalResourceManager.ResourceType.OFFHEAP_MEMORY; +import static org.apache.geode.internal.cache.util.UncheckedUtils.cast; import static org.apache.geode.internal.logging.CoreLoggingExecutors.newThreadPoolWithFixedFeed; import static org.apache.geode.internal.tcp.ConnectionTable.threadWantsSharedResources; import static org.apache.geode.logging.internal.executors.LoggingExecutors.newFixedThreadPool; import static org.apache.geode.util.internal.GeodeGlossary.GEMFIRE_PREFIX; -import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast; import java.io.BufferedReader; import java.io.ByteArrayInputStream; @@ -1808,7 +1812,7 @@ private void shutDownOnePRGracefully(PartitionedRegion partitionedRegion) { && partitionedRegion.getDataPolicy() == DataPolicy.PERSISTENT_PARTITION) { int numBuckets = partitionedRegion.getTotalNumberOfBuckets(); Map[] bucketMaps = - uncheckedCast(new Map[numBuckets]); + createMapArray(numBuckets); PartitionedRegionDataStore dataStore = partitionedRegion.getDataStore(); // lock all the primary buckets @@ -2662,18 +2666,18 @@ public Set getMembers() { @Override public Set getAdminMembers() { - return uncheckedCast(dm.getAdminMemberSet()); + return asDistributedMemberSet(dm.getAdminMemberSet()); } @Override public Set getMembers(Region region) { if (region instanceof DistributedRegion) { DistributedRegion distributedRegion = (DistributedRegion) region; - return uncheckedCast(distributedRegion.getDistributionAdvisor().adviseCacheOp()); + return asDistributedMemberSet(distributedRegion.getDistributionAdvisor().adviseCacheOp()); } if (region instanceof PartitionedRegion) { PartitionedRegion partitionedRegion = (PartitionedRegion) region; - return uncheckedCast(partitionedRegion.getRegionAdvisor().adviseAllPRNodes()); + return asDistributedMemberSet(partitionedRegion.getRegionAdvisor().adviseAllPRNodes()); } return emptySet(); } @@ -3059,14 +3063,15 @@ public Region createVMRegion(String name, RegionAttributes p_ system.handleResourceEvent(ResourceEvent.REGION_CREATE, region); } - return uncheckedCast(region); + return cast(region); } @Override public RegionAttributes invokeRegionBefore(InternalRegion parent, String name, RegionAttributes attrs, InternalRegionArguments internalRegionArgs) { for (RegionListener listener : regionListeners) { - attrs = uncheckedCast(listener.beforeCreate(parent, name, attrs, internalRegionArgs)); + attrs = + uncheckedRegionAttributes(listener.beforeCreate(parent, name, attrs, internalRegionArgs)); } return attrs; } @@ -3182,7 +3187,7 @@ private static void validatePath(String path) { @Override public Region getRegionByPath(String path) { - return uncheckedCast(getInternalRegionByPath(path)); + return cast(getInternalRegionByPath(path)); } @Override @@ -3239,7 +3244,7 @@ public Region getRegion(String path, boolean returnDestroyedRegion) stopper.checkCancelInProgress(null); return null; } - return uncheckedCast(result); + return cast(result); } String[] pathParts = parsePath(path); @@ -3263,7 +3268,7 @@ public Region getRegion(String path, boolean returnDestroyedRegion) logger.debug("GemFireCache.getRegion, calling getSubregion on rootRegion({}): {}", pathParts[0], pathParts[1]); } - return uncheckedCast(rootRegion.getSubregion(pathParts[1], returnDestroyedRegion)); + return cast(rootRegion.getSubregion(pathParts[1], returnDestroyedRegion)); } @Override @@ -4053,7 +4058,7 @@ public FilterProfile getFilterProfile(String regionName) { @Override public RegionAttributes getRegionAttributes(String id) { - return uncheckedCast(namedRegionAttributes.get(id)); + return GemFireCacheImpl.UncheckedUtils.uncheckedCast(namedRegionAttributes).get(id); } @Override @@ -5171,6 +5176,28 @@ private void doNotify() { } } + @SuppressWarnings("unchecked") + static class UncheckedUtils { + + static Map[] createMapArray(int size) { + return new Map[size]; + } + + static Set asDistributedMemberSet( + Set internalDistributedMembers) { + return (Set) internalDistributedMembers; + } + + static RegionAttributes uncheckedRegionAttributes(RegionAttributes region) { + return region; + } + + static Map> uncheckedCast( + Map> namedRegionAttributes) { + return (Map) namedRegionAttributes; + } + } + @FunctionalInterface @VisibleForTesting interface TXManagerImplFactory { diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/InternalCacheForClientAccess.java b/geode-core/src/main/java/org/apache/geode/internal/cache/InternalCacheForClientAccess.java index dbbb98b1fd90..10635fe8cf44 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/InternalCacheForClientAccess.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/InternalCacheForClientAccess.java @@ -16,7 +16,7 @@ */ package org.apache.geode.internal.cache; -import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast; +import static org.apache.geode.internal.cache.util.UncheckedUtils.cast; import java.io.File; import java.io.IOException; @@ -162,7 +162,7 @@ public Region getInternalRegion(String path) { public Region getRegion(String path, boolean returnDestroyedRegion) { Region result = delegate.getRegion(path, returnDestroyedRegion); checkForInternalRegion(result); - return uncheckedCast(result); + return cast(result); } @Override @@ -176,7 +176,7 @@ public InternalRegion getReinitializingRegion(String fullPath) { public Region getRegionByPath(String path) { InternalRegion result = delegate.getInternalRegionByPath(path); checkForInternalRegion(result); - return uncheckedCast(result); + return cast(result); } @Override diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java index 098115b6e71e..849187bb85cc 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/LocalRegion.java @@ -17,9 +17,9 @@ import static org.apache.geode.internal.cache.LocalRegion.InitializationLevel.AFTER_INITIAL_IMAGE; import static org.apache.geode.internal.cache.LocalRegion.InitializationLevel.ANY_INIT; import static org.apache.geode.internal.cache.LocalRegion.InitializationLevel.BEFORE_INITIAL_IMAGE; +import static org.apache.geode.internal.cache.util.UncheckedUtils.cast; import static org.apache.geode.internal.lang.SystemUtils.getLineSeparator; import static org.apache.geode.internal.offheap.annotations.OffHeapIdentifier.ENTRY_EVENT_NEW_VALUE; -import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -8943,10 +8943,7 @@ VersionedObjectList basicPutAll(final Map map, txState.getRealDeal(null, this); } try { - proxyResult = getServerProxy().putAll( - uncheckedCast(map), - eventId, - !event.isGenerateCallbacks(), + proxyResult = getServerProxy().putAll(cast(map), eventId, !event.isGenerateCallbacks(), event.getCallbackArgument()); if (isDebugEnabled) { logger.debug("PutAll received response from server: {}", proxyResult); diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/execute/util/TypedFunctionService.java b/geode-core/src/main/java/org/apache/geode/internal/cache/execute/util/TypedFunctionService.java deleted file mode 100644 index 3f2143978f36..000000000000 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/execute/util/TypedFunctionService.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache.execute.util; - -import org.apache.geode.cache.Region; -import org.apache.geode.cache.execute.Execution; -import org.apache.geode.cache.execute.FunctionService; - -/** - * Utilities for casting and working around raw types in the {@link FunctionService} API. - */ -@SuppressWarnings({"unchecked", "unused"}) -public class TypedFunctionService { - - protected TypedFunctionService() { - // do not instantiate - } - - /** - * Adds parameterized type support to {@link FunctionService#onRegion(Region)}. - */ - public static Execution onRegion(Region region) { - return FunctionService.onRegion(region); - } -} diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/CacheClientProxyFactory.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/CacheClientProxyFactory.java index ae26aa7ab0e8..a3def49bb130 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/CacheClientProxyFactory.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/CacheClientProxyFactory.java @@ -14,7 +14,7 @@ */ package org.apache.geode.internal.cache.tier.sockets; -import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast; +import static org.apache.geode.internal.cache.util.UncheckedUtils.cast; import java.lang.reflect.InvocationTargetException; import java.net.Socket; @@ -55,7 +55,7 @@ private static InternalCacheClientProxyFactory factory() { } try { Class proxyClass = - uncheckedCast(ClassPathLoader.getLatest().forName(proxyClassName)); + cast(ClassPathLoader.getLatest().forName(proxyClassName)); return proxyClass.getConstructor().newInstance(); } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { diff --git a/geode-common/src/main/java/org/apache/geode/util/internal/UncheckedUtils.java b/geode-core/src/main/java/org/apache/geode/internal/cache/util/UncheckedUtils.java similarity index 68% rename from geode-common/src/main/java/org/apache/geode/util/internal/UncheckedUtils.java rename to geode-core/src/main/java/org/apache/geode/internal/cache/util/UncheckedUtils.java index 61dbd8d3bd19..c03e99062ee5 100644 --- a/geode-common/src/main/java/org/apache/geode/util/internal/UncheckedUtils.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/util/UncheckedUtils.java @@ -12,23 +12,18 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ -package org.apache.geode.util.internal; +package org.apache.geode.internal.cache.util; + +import org.apache.geode.cache.execute.Execution; -/** - * Utilities for casting and working with unchecked raw types. - */ @SuppressWarnings({"unchecked", "unused"}) public class UncheckedUtils { - protected UncheckedUtils() { - // do not instantiate + public static T cast(Object object) { + return (T) object; } - /** - * Casts an instance of a raw type to a parameterized type. Preference should be given to - * converting all code from using raw types to using parameterized types when possible. - */ - public static T uncheckedCast(Object object) { - return (T) object; + public static Execution cast(Execution execution) { + return execution; } } diff --git a/geode-core/src/test/java/org/apache/geode/alerting/internal/ClusterAlertMessagingTest.java b/geode-core/src/test/java/org/apache/geode/alerting/internal/ClusterAlertMessagingTest.java index eadf54b1f748..f7bc8d84098b 100644 --- a/geode-core/src/test/java/org/apache/geode/alerting/internal/ClusterAlertMessagingTest.java +++ b/geode-core/src/test/java/org/apache/geode/alerting/internal/ClusterAlertMessagingTest.java @@ -14,7 +14,7 @@ */ package org.apache.geode.alerting.internal; -import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast; +import static org.apache.geode.internal.cache.util.UncheckedUtils.cast; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; import static org.mockito.ArgumentMatchers.anyLong; @@ -141,7 +141,7 @@ public void sendAlertUsesAlertingAction() { public void sendAlertLogsWarning_ifAlertingIOExceptionIsCaught() { ExecutorService executor = currentThreadExecutorService(); ClusterDistributionManager distributionManager = mock(ClusterDistributionManager.class); - Consumer alertingIOExceptionLogger = uncheckedCast(mock(Consumer.class)); + Consumer alertingIOExceptionLogger = cast(mock(Consumer.class)); ClusterAlertMessaging clusterAlertMessaging = spyClusterAlertMessaging(distributionManager, executor, alertingIOExceptionLogger); doThrow(new AlertingIOException(new IOException("Cannot form connection to alert listener"))) @@ -162,7 +162,7 @@ public void sendAlertLogsWarning_ifAlertingIOExceptionIsCaught() { public void sendAlertLogsWarningOnce_ifAlertingIOExceptionIsCaught() { ExecutorService executor = currentThreadExecutorService(); ClusterDistributionManager distributionManager = mock(ClusterDistributionManager.class); - Consumer alertingIOExceptionLogger = uncheckedCast(mock(Consumer.class)); + Consumer alertingIOExceptionLogger = cast(mock(Consumer.class)); ClusterAlertMessaging clusterAlertMessaging = spyClusterAlertMessaging(distributionManager, executor, alertingIOExceptionLogger); doThrow(new AlertingIOException(new IOException("Cannot form connection to alert listener"))) diff --git a/geode-core/src/test/java/org/apache/geode/internal/tcp/TCPConduitTest.java b/geode-core/src/test/java/org/apache/geode/internal/tcp/TCPConduitTest.java index c0bf0a5f52be..0c30ce2bfc61 100644 --- a/geode-core/src/test/java/org/apache/geode/internal/tcp/TCPConduitTest.java +++ b/geode-core/src/test/java/org/apache/geode/internal/tcp/TCPConduitTest.java @@ -16,7 +16,7 @@ */ package org.apache.geode.internal.tcp; -import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast; +import static org.apache.geode.internal.cache.util.UncheckedUtils.cast; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; import static org.mockito.Mockito.anyBoolean; @@ -62,7 +62,7 @@ public class TCPConduitTest { @Before public void setUp() throws Exception { - membership = uncheckedCast(mock(Membership.class)); + membership = cast(mock(Membership.class)); directChannel = mock(DirectChannel.class); connectionTable = mock(ConnectionTable.class); socketCreator = new SocketCreator(new SSLConfig.Builder().build());