Skip to content

Commit

Permalink
GEODE-6588: Cleanup static analyzer warnings. (apache#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-at-work committed Jul 5, 2022
1 parent 83c24ac commit 84c0963
Show file tree
Hide file tree
Showing 215 changed files with 3,630 additions and 5,045 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.apache.geode.internal.cache;

import static org.apache.geode.test.dunit.VM.getVM;
import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.Serializable;
Expand Down Expand Up @@ -133,9 +134,9 @@ private void verifyKeys(final String regionName, final List<Date> listOfKeys) {
Set<Object> bucketKeys = partitionedRegion.getBucketKeys(bucketId);
for (Object key : bucketKeys) {
EntryOperation<Date, Integer> entryOperation =
new EntryOperationImpl(partitionedRegion, null, key, null, null);
new EntryOperationImpl<>(partitionedRegion, null, key, null, null);
PartitionResolver<Date, Integer> partitionResolver =
partitionedRegion.getPartitionResolver();
uncheckedCast(partitionedRegion.getPartitionResolver());
Object routingObject = partitionResolver.getRoutingObject(entryOperation);
int routingObjectHashCode = routingObject.hashCode() % TOTAL_NUM_BUCKETS;
assertThat(routingObjectHashCode).isEqualTo(bucketId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void execute(FunctionContext context) {
try {
RegionFunctionContext rContext = (RegionFunctionContext) context;
Region pr1 = rContext.getDataSet();
LocalDataSet localCust =
LocalDataSet<?, ?> localCust =
(LocalDataSet) PartitionRegionHelper.getLocalDataForContext(rContext);
Map<String, Region<?, ?>> colocatedRegions =
PartitionRegionHelper.getColocatedRegions(pr1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import java.util.Set;

import org.apache.geode.cache.Region;
import org.apache.geode.cache.execute.FunctionAdapter;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.RegionFunctionContext;
import org.apache.geode.cache.partition.PartitionRegionHelper;
import org.apache.geode.internal.Assert;
import org.apache.geode.internal.cache.LocalDataSet;

public class LocalDataSetFunction extends FunctionAdapter {
public class LocalDataSetFunction implements Function<Void> {

private final boolean optimizeForWrite;

Expand All @@ -36,27 +36,30 @@ public LocalDataSetFunction(boolean optimizeForWrite) {
}

@Override
public void execute(FunctionContext context) {
RegionFunctionContext rContext = (RegionFunctionContext) context;
Region cust = rContext.getDataSet();
LocalDataSet localCust = (LocalDataSet) PartitionRegionHelper.getLocalDataForContext(rContext);
public void execute(FunctionContext<Void> context) {
RegionFunctionContext<Void> rContext = (RegionFunctionContext<Void>) context;
Region<?, ?> cust = rContext.getDataSet();
LocalDataSet<?, ?> localCust =
(LocalDataSet<?, ?>) PartitionRegionHelper.getLocalDataForContext(rContext);
Map<String, Region<?, ?>> colocatedRegions = PartitionRegionHelper.getColocatedRegions(cust);
Map<String, Region<?, ?>> localColocatedRegions =
PartitionRegionHelper.getLocalColocatedRegions(rContext);

Assert.assertTrue(colocatedRegions.size() == 2);
Set custKeySet = cust.keySet();
Set localCustKeySet = localCust.keySet();

Region ord = colocatedRegions.get(SEPARATOR + "OrderPR");
LocalDataSet localOrd = (LocalDataSet) localColocatedRegions.get(SEPARATOR + "OrderPR");
Set ordKeySet = ord.keySet();
Set localOrdKeySet = localOrd.keySet();

Region ship = colocatedRegions.get(SEPARATOR + "ShipmentPR");
LocalDataSet localShip = (LocalDataSet) localColocatedRegions.get(SEPARATOR + "ShipmentPR");
Set shipKeySet = ship.keySet();
Set localShipKeySet = localShip.keySet();
Set<?> custKeySet = cust.keySet();
Set<?> localCustKeySet = localCust.keySet();

Region<?, ?> ord = colocatedRegions.get(SEPARATOR + "OrderPR");
LocalDataSet<?, ?> localOrd =
(LocalDataSet<?, ?>) localColocatedRegions.get(SEPARATOR + "OrderPR");
Set<?> ordKeySet = ord.keySet();
Set<?> localOrdKeySet = localOrd.keySet();

Region<?, ?> ship = colocatedRegions.get(SEPARATOR + "ShipmentPR");
LocalDataSet<?, ?> localShip =
(LocalDataSet<?, ?>) localColocatedRegions.get(SEPARATOR + "ShipmentPR");
Set<?> shipKeySet = ship.keySet();
Set<?> localShipKeySet = localShip.keySet();

Assert.assertTrue(localCust.getBucketSet().size() == localOrd.getBucketSet().size());
Assert.assertTrue(localCust.getBucketSet().size() == localShip.getBucketSet().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public void testCurrScopeDpndntItrsBasedOnSingleIndpndntItr() throws Exception {
.isEqualTo(rIter.getInternalId());
}

List list1 = context.getCurrScopeDpndntItrsBasedOnSingleIndpndntItr(indItr);
List list1 = context.getCurrentScopeDependentIteratorsBasedOnSingleIndependentIterator(indItr);
assertThat(list1.size())
.as("The dependency set returned incorrect result with size =" + list1.size())
.isEqualTo(4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static org.apache.geode.cache.Region.SEPARATOR;
import static org.apache.geode.cache.RegionShortcut.PARTITION;
import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

Expand Down Expand Up @@ -90,7 +91,7 @@ private Object[] getRegionAndIndexMaintenanceTypes() {
};
}

private void waitForIndexUpdaterTask(boolean synchronousMaintenance, Region region) {
private void waitForIndexUpdaterTask(boolean synchronousMaintenance, Region<?, ?> region) {
if (!synchronousMaintenance) {
InternalRegion internalRegion = (InternalRegion) region;
await().untilAsserted(
Expand Down Expand Up @@ -199,8 +200,8 @@ public void indexShouldBeMarkedAsInvalidWhenAddMappingOperationFailsAfterEntryDe
if (!PARTITION.equals(regionShortcut)) {
((RangeIndex) index).valueToEntriesMap.clear();
} else {
@SuppressWarnings("unchecked")
List<RangeIndex> bucketRangeIndexList = ((PartitionedIndex) index).getBucketIndexes();
List<RangeIndex> bucketRangeIndexList =
uncheckedCast(((PartitionedIndex) index).getBucketIndexes());
bucketRangeIndexList.forEach(rangeIndex -> rangeIndex.valueToEntriesMap.clear());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1398,14 +1398,14 @@ public void testIndexesRemainInUseAfterARebalance() throws Exception {

// Get the first index entry in the PartitionedIndex bucketIndexes and delete the index from it
// (to simulate what happens when a bucket is moved)
Map.Entry<Region, List<Index>> firstIndexEntry = index.getFirstBucketIndex();
Map.Entry<Region<?, ?>, List<Index>> firstIndexEntry = index.getFirstBucketIndex();
assertTrue(!firstIndexEntry.getValue().isEmpty());
index.removeFromBucketIndexes(firstIndexEntry.getKey(),
firstIndexEntry.getValue().iterator().next());

// Verify the index was removed from the entry and the entry was removed from the bucket indexes
assertTrue(firstIndexEntry.getValue().isEmpty());
Map.Entry<Region, List<Index>> nextFirstIndexEntry = index.getFirstBucketIndex();
Map.Entry<Region<?, ?>, List<Index>> nextFirstIndexEntry = index.getFirstBucketIndex();
assertTrue(!nextFirstIndexEntry.getValue().isEmpty());

// Run query again
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ org/apache/geode/security/ResourcePermission
org/apache/geode/security/ResourcePermission$Operation
org/apache/geode/security/ResourcePermission$Resource
org/apache/geode/security/ResourcePermission$Target
org/apache/geode/internal/cache/PartitionedRegion$6
org/apache/geode/internal/cache/PartitionedRegion$3
org/apache/geode/internal/cache/TXFarSideCMTracker$2
org/apache/geode/internal/cache/TXManagerImpl$1
org/apache/geode/internal/cache/partitioned/FetchEntriesMessage$FetchEntriesResponse$1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,8 @@ fromData,46
toData,43

org/apache/geode/internal/cache/CreateRegionProcessor$CreateRegionReplyMessage,2
fromData,164
toData,208
fromData,166
toData,205

org/apache/geode/internal/cache/DestroyOperation$DestroyMessage,2
fromData,46
Expand Down Expand Up @@ -861,14 +861,14 @@ fromData,26
toData,23

org/apache/geode/internal/cache/DistributedPutAllOperation$EntryVersionsList,2
fromData,272
toData,292
fromData,275
toData,298

org/apache/geode/internal/cache/DistributedPutAllOperation$PutAllEntryData,1
toData,252

org/apache/geode/internal/cache/DistributedPutAllOperation$PutAllMessage,2
fromData,214
fromData,194
toData,188

org/apache/geode/internal/cache/DistributedRegionFunctionStreamingMessage,2
Expand Down Expand Up @@ -1287,7 +1287,7 @@ fromData,22
toData,19

org/apache/geode/internal/cache/execute/FunctionRemoteContext,2
fromData,187
fromData,193
toData,165

org/apache/geode/internal/cache/ha/HARegionQueue$DispatchedAndCurrentEvents,2
Expand Down Expand Up @@ -1535,7 +1535,7 @@ fromData,1
toData,1

org/apache/geode/internal/cache/partitioned/OfflineMemberDetailsImpl,2
fromData,97
fromData,103
toData,94

org/apache/geode/internal/cache/partitioned/PRLoad,2
Expand Down Expand Up @@ -1588,7 +1588,7 @@ toData,55

org/apache/geode/internal/cache/partitioned/QueryMessage,2
fromData,64
toData,64
toData,61

org/apache/geode/internal/cache/partitioned/RegionAdvisor$BucketProfileAndId,2
fromData,61
Expand Down
26 changes: 4 additions & 22 deletions geode-core/src/main/java/org/apache/geode/DataSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2078,25 +2078,7 @@ public static byte[][] readArrayOfByteArrays(DataInput in)
* @see #readArrayList
*/
public static void writeArrayList(ArrayList<?> list, DataOutput out) throws IOException {

InternalDataSerializer.checkOut(out);

int size;
if (list == null) {
size = -1;
} else {
size = list.size();
}
InternalDataSerializer.writeArrayLength(size, out);
if (logger.isTraceEnabled(LogMarker.SERIALIZER_VERBOSE)) {
logger.trace(LogMarker.SERIALIZER_VERBOSE, "Writing ArrayList with {} elements: {}", size,
list);
}
if (size > 0) {
for (int i = 0; i < size; i++) {
writeObject(list.get(i), out);
}
}
InternalDataSerializer.writeList(list, out);
}


Expand Down Expand Up @@ -3396,7 +3378,7 @@ public void setContext(Object/* ClientProxyMembershipID */ context) {
* maps a class to its enum constants.
*/
@MakeNotStatic
private static final ConcurrentMap<Class<? extends Enum>, Enum[]> knownEnums =
private static final ConcurrentMap<Class<? extends Enum<?>>, Enum<?>[]> knownEnums =
new ConcurrentHashMap<>();

/**
Expand All @@ -3406,7 +3388,7 @@ public void setContext(Object/* ClientProxyMembershipID */ context) {
* @return enum constants for the given class
*/
@SuppressWarnings("unchecked")
private static <E extends Enum> E[] getEnumConstantsForClass(Class<E> clazz) {
private static <E extends Enum<?>> E[] getEnumConstantsForClass(Class<E> clazz) {
E[] returnVal = (E[]) knownEnums.get(clazz);
if (returnVal == null) {
returnVal = clazz.getEnumConstants();
Expand All @@ -3429,7 +3411,7 @@ private static <E extends Enum> E[] getEnumConstantsForClass(Class<E> clazz) {
* @since GemFire 6.5
* @throws IOException if a problem occurs while writing to <code>out</code>
*/
public static void writeEnum(Enum e, DataOutput out) throws IOException {
public static void writeEnum(Enum<?> e, DataOutput out) throws IOException {

InternalDataSerializer.checkOut(out);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public String toString() {

@Override
public void fillInProfile(Profile profile) {
assert profile instanceof GatewaySenderProfile;
GatewaySenderProfile pf = (GatewaySenderProfile) profile;
pf.Id = getId();
pf.remoteDSId = getRemoteDSId();
Expand All @@ -181,8 +180,7 @@ public void fillInProfile(Profile profile) {

@Override
public void setModifiedEventId(EntryEventImpl clonedEvent) {
int bucketId = -1;
// merged from 42004
final int bucketId;
if (clonedEvent.getRegion() instanceof DistributedRegion) {
bucketId = PartitionedRegionHelper.getHashKey(clonedEvent.getKey(),
getMaxParallelismForReplicatedRegion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ public void setModifiedEventId(EntryEventImpl clonedEvent) {
EventID originalEventId = clonedEvent.getEventId();
long originalThreadId = originalEventId.getThreadID();
long newThreadId = originalThreadId;
if (ThreadIdentifier.isWanTypeThreadID(newThreadId)) {
// This thread id has already been converted. Do nothing.
} else {
if (!ThreadIdentifier.isWanTypeThreadID(newThreadId)) {
newThreadId = ThreadIdentifier.createFakeThreadIDForParallelGSPrimaryBucket(0,
originalThreadId, getEventIdIndex());
}
Expand Down
Loading

0 comments on commit 84c0963

Please sign in to comment.