Skip to content

Commit

Permalink
Addressing compiler warnings (#9017)
Browse files Browse the repository at this point in the history
* Addressing compiler warnings

* Addressing rest of the compiler warnings, removing failonerror:false from pom

* Fixing java8 compiler warnings

* Rename: CosmosItemResponse::getResource to getItem

* Using super.hashCode() for PartitionKeyInternal and VectorSessionToken

* Removing raw-type supressions those are not required anymore, cleanup

* Note -> TODO, remove extra-space and replacing instanceof with class eqality
  • Loading branch information
anuchandy authored Mar 14, 2020
1 parent 591d77d commit 1300def
Show file tree
Hide file tree
Showing 85 changed files with 402 additions and 274 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,6 @@ <V> V getOrThrow(Future<V> f) {
}

PojoizedJson toPojoizedJson(CosmosItemResponse<PojoizedJson> resp) throws Exception {
return resp.getResource();
return resp.getItem();
}
}
12 changes: 0 additions & 12 deletions sdk/cosmos/azure-cosmos/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,6 @@ Licensed under the MIT License.
</configuration>
</plugin>

<!-- CosmosSkip - Needed temporary to not fail on warning on compilation -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <!-- {x-version-update;org.apache.maven.plugins:maven-compiler-plugin;external_dependency} -->
<configuration>
<source>1.8</source>
<target>1.8</target>
<failOnWarning>false</failOnWarning>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public <T> Mono<CosmosAsyncItemResponse<T>> createItem(T item, CosmosItemRequest
if (options == null) {
options = new CosmosItemRequestOptions();
}
@SuppressWarnings("unchecked")
Class<T> itemType = (Class<T>) item.getClass();
RequestOptions requestOptions = ModelBridgeInternal.toRequestOptions(options);
return database.getDocClientWrapper()
Expand Down Expand Up @@ -256,6 +257,7 @@ public <T> Mono<CosmosAsyncItemResponse<T>> upsertItem(T item, CosmosItemRequest
if (options == null) {
options = new CosmosItemRequestOptions();
}
@SuppressWarnings("unchecked")
Class<T> itemType = (Class<T>) item.getClass();
return this.getDatabase().getDocClientWrapper()
.upsertDocument(this.getLink(), item,
Expand Down Expand Up @@ -312,7 +314,7 @@ public <T> CosmosPagedFlux<T> readAllItems(FeedOptions options, Class<T> classTy
* @param <T> the type parameter
* @param query the query.
* @param classType the class type
* @return a {@link CosmosPagedFlux} containing one or several feed response pages of the obtained items or an
* @return a {@link CosmosPagedFlux} containing one or several feed response pages of the obtained items or an
* error.
*/
public <T> CosmosPagedFlux<T> queryItems(String query, Class<T> classType) {
Expand All @@ -330,7 +332,7 @@ public <T> CosmosPagedFlux<T> queryItems(String query, Class<T> classType) {
* @param query the query.
* @param options the feed options.
* @param classType the class type
* @return a {@link CosmosPagedFlux} containing one or several feed response pages of the obtained items or an
* @return a {@link CosmosPagedFlux} containing one or several feed response pages of the obtained items or an
* error.
*/
public <T> CosmosPagedFlux<T> queryItems(String query, FeedOptions options, Class<T> classType) {
Expand All @@ -347,7 +349,7 @@ public <T> CosmosPagedFlux<T> queryItems(String query, FeedOptions options, Clas
* @param <T> the type parameter
* @param querySpec the SQL query specification.
* @param classType the class type
* @return a {@link CosmosPagedFlux} containing one or several feed response pages of the obtained items or an
* @return a {@link CosmosPagedFlux} containing one or several feed response pages of the obtained items or an
* error.
*/
public <T> CosmosPagedFlux<T> queryItems(SqlQuerySpec querySpec, Class<T> classType) {
Expand All @@ -365,7 +367,7 @@ public <T> CosmosPagedFlux<T> queryItems(SqlQuerySpec querySpec, Class<T> classT
* @param querySpec the SQL query specification.
* @param options the feed options.
* @param classType the class type
* @return a {@link CosmosPagedFlux} containing one or several feed response pages of the obtained items or an
* @return a {@link CosmosPagedFlux} containing one or several feed response pages of the obtained items or an
* error.
*/
public <T> CosmosPagedFlux<T> queryItems(SqlQuerySpec querySpec, FeedOptions options, Class<T> classType) {
Expand Down Expand Up @@ -475,6 +477,7 @@ public <T> Mono<CosmosAsyncItemResponse<T>> replaceItem(
options = new CosmosItemRequestOptions();
}
ModelBridgeInternal.setPartitionKey(options, partitionKey);
@SuppressWarnings("unchecked")
Class<T> itemType = (Class<T>) item.getClass();
return this.getDatabase()
.getDocClientWrapper()
Expand All @@ -494,7 +497,7 @@ public <T> Mono<CosmosAsyncItemResponse<T>> replaceItem(
* @param partitionKey the partition key
* @return an {@link Mono} containing the cosmos item resource response.
*/
public Mono<CosmosAsyncItemResponse> deleteItem(String itemId, PartitionKey partitionKey) {
public Mono<CosmosAsyncItemResponse<Object>> deleteItem(String itemId, PartitionKey partitionKey) {
return deleteItem(itemId, partitionKey, new CosmosItemRequestOptions());
}

Expand All @@ -510,7 +513,7 @@ public Mono<CosmosAsyncItemResponse> deleteItem(String itemId, PartitionKey part
* @param options the request options
* @return an {@link Mono} containing the cosmos item resource response.
*/
public Mono<CosmosAsyncItemResponse> deleteItem(
public Mono<CosmosAsyncItemResponse<Object>> deleteItem(
String itemId, PartitionKey partitionKey,
CosmosItemRequestOptions options) {
if (options == null) {
Expand All @@ -521,7 +524,7 @@ public Mono<CosmosAsyncItemResponse> deleteItem(
return this.getDatabase()
.getDocClientWrapper()
.deleteDocument(getItemLink(itemId), requestOptions)
.map(response -> ModelBridgeInternal.createCosmosAsyncItemResponseWithObjectType(response, Object.class))
.map(response -> ModelBridgeInternal.createCosmosAsyncItemResponseWithObjectType(response))
.single();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ public <T> CosmosItemResponse<T> upsertItem(T item) throws CosmosClientException
* @return the cosmos sync item response
* @throws CosmosClientException the cosmos client exception
*/
@SuppressWarnings("unchecked")
// Note: @kushagraThapar and @moderakh to ensure this casting is valid
public <T> CosmosItemResponse<T> upsertItem(Object item, CosmosItemRequestOptions options) throws
CosmosClientException {
return (CosmosItemResponse<T>) this.mapItemResponseAndBlock(this.asyncContainer.upsertItem(item, options));
Expand All @@ -218,9 +220,9 @@ public <T> CosmosItemResponse<T> upsertItem(Object item, CosmosItemRequestOption
<T> CosmosItemResponse<T> mapItemResponseAndBlock(Mono<CosmosAsyncItemResponse<T>> itemMono) throws
CosmosClientException {
try {
return (CosmosItemResponse<T>) itemMono
.map(this::convertResponse)
.block();
return itemMono
.map(this::convertResponse)
.block();
} catch (Exception ex) {
final Throwable throwable = Exceptions.unwrap(ex);
if (throwable instanceof CosmosClientException) {
Expand All @@ -231,8 +233,8 @@ <T> CosmosItemResponse<T> mapItemResponseAndBlock(Mono<CosmosAsyncItemResponse<T
}
}

private CosmosItemResponse mapDeleteItemResponseAndBlock(Mono<CosmosAsyncItemResponse> deleteItemMono) throws
CosmosClientException {
private CosmosItemResponse<Object> mapDeleteItemResponseAndBlock(Mono<CosmosAsyncItemResponse<Object>> deleteItemMono)
throws CosmosClientException {
try {
return deleteItemMono
.map(this::convertResponse)
Expand Down Expand Up @@ -347,7 +349,7 @@ public <T> CosmosItemResponse<T> replaceItem(T item,
* @return the cosmos sync item response
* @throws CosmosClientException the cosmos client exception
*/
public CosmosItemResponse deleteItem(String itemId, PartitionKey partitionKey,
public CosmosItemResponse<Object> deleteItem(String itemId, PartitionKey partitionKey,
CosmosItemRequestOptions options) throws CosmosClientException {
return this.mapDeleteItemResponseAndBlock(asyncContainer.deleteItem(itemId, partitionKey, options));
}
Expand All @@ -372,8 +374,8 @@ public CosmosScripts getScripts() {
* @param response the cosmos item response
* @return the cosmos sync item response
*/
private <T> CosmosItemResponse<T> convertResponse(CosmosAsyncItemResponse response) {
return ModelBridgeInternal.createCosmosItemResponse(response);
private <T> CosmosItemResponse<T> convertResponse(CosmosAsyncItemResponse<T> response) {
return ModelBridgeInternal.<T>createCosmosItemResponse(response);
}

private <T> CosmosPagedIterable<T> getCosmosPagedIterable(CosmosPagedFlux<T> cosmosPagedFlux) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ static <T> List<T> getTypedResultsFromV2Results(List<Document> results, Class<T>
* @return the object
* @throws IOException the io exception
*/
public <T> T getObject(Class<?> klass) throws IOException {
return (T) MAPPER.readValue(this.toJson(), klass);
public <T> T getObject(Class<T> klass) throws IOException {
return MAPPER.readValue(this.toJson(), klass);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.azure.cosmos.models.CosmosError;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

/**
Expand Down Expand Up @@ -79,7 +80,7 @@ public NotFoundException(String message, HttpHeaders headers, URI requestUri) {
}

NotFoundException(Exception innerException) {
this(RMResources.NotFound, innerException, (Map) null, null);
this(RMResources.NotFound, innerException, (Map<String, String>) null, null);
}

NotFoundException(String message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,21 @@ public static Pair<Boolean, ResourceId> tryParse(String id) {
ResourceId.blockCopy(buffer, 8, subCollRes, 0, 8);

long subCollectionResource = ByteBuffer.wrap(buffer, 8, 8).getLong();
if ((subCollRes[7] >> 4) == (byte) CollectionChildResourceType.Document) {
if ((subCollRes[7] >> 4) == CollectionChildResourceType.Document) {
rid.document = subCollectionResource;

if (buffer.length == 20) {
rid.attachment = ByteBuffer.wrap(buffer, 16, 4).getInt();
}
} else if (Math.abs(subCollRes[7] >> 4) == (byte) CollectionChildResourceType.StoredProcedure) {
} else if (Math.abs(subCollRes[7] >> 4) == CollectionChildResourceType.StoredProcedure) {
rid.storedProcedure = subCollectionResource;
} else if ((subCollRes[7] >> 4) == (byte) CollectionChildResourceType.Trigger) {
} else if ((subCollRes[7] >> 4) == CollectionChildResourceType.Trigger) {
rid.trigger = subCollectionResource;
} else if ((subCollRes[7] >> 4) == (byte) CollectionChildResourceType.UserDefinedFunction) {
} else if ((subCollRes[7] >> 4) == CollectionChildResourceType.UserDefinedFunction) {
rid.userDefinedFunction = subCollectionResource;
} else if ((subCollRes[7] >> 4) == (byte) CollectionChildResourceType.Conflict) {
} else if ((subCollRes[7] >> 4) == CollectionChildResourceType.Conflict) {
rid.conflict = subCollectionResource;
} else if ((subCollRes[7] >> 4) == (byte) CollectionChildResourceType.PartitionKeyRange) {
} else if ((subCollRes[7] >> 4) == CollectionChildResourceType.PartitionKeyRange) {
rid.partitionKeyRange = subCollectionResource;
} else {
return Pair.of(false, rid);
Expand Down Expand Up @@ -372,7 +372,7 @@ public ResourceId getDocumentId() {
rid.document = this.document;
return rid;
}

public long getPartitionKeyRange() {
return this.partitionKeyRange;
}
Expand Down Expand Up @@ -456,22 +456,22 @@ else if (this.database != 0)

if (this.documentCollection != 0)
ResourceId.blockCopy(
convertToBytesUsingByteBuffer(this.documentCollection),
convertToBytesUsingByteBuffer(this.documentCollection),
0, val, 4, 4);
else if (this.user != 0)
ResourceId.blockCopy(convertToBytesUsingByteBuffer(this.user),
ResourceId.blockCopy(convertToBytesUsingByteBuffer(this.user),
0, val, 4, 4);

if (this.storedProcedure != 0)
ResourceId.blockCopy(
convertToBytesUsingByteBuffer(this.storedProcedure),
convertToBytesUsingByteBuffer(this.storedProcedure),
0, val, 8, 8);
else if (this.trigger != 0)
ResourceId.blockCopy(convertToBytesUsingByteBuffer(this.trigger),
0, val, 8, 8);
else if (this.userDefinedFunction != 0)
ResourceId.blockCopy(
convertToBytesUsingByteBuffer(this.userDefinedFunction),
convertToBytesUsingByteBuffer(this.userDefinedFunction),
0, val, 8, 8);
else if (this.conflict != 0)
ResourceId.blockCopy(convertToBytesUsingByteBuffer(this.conflict),
Expand All @@ -481,16 +481,16 @@ else if (this.document != 0)
0, val, 8, 8);
else if (this.permission != 0)
ResourceId.blockCopy(
convertToBytesUsingByteBuffer(this.permission),
convertToBytesUsingByteBuffer(this.permission),
0, val, 8, 8);
else if (this.partitionKeyRange != 0)
ResourceId.blockCopy(
convertToBytesUsingByteBuffer(this.partitionKeyRange),
convertToBytesUsingByteBuffer(this.partitionKeyRange),
0, val, 8, 8);

if (this.attachment != 0)
ResourceId.blockCopy(
convertToBytesUsingByteBuffer(this.attachment),
convertToBytesUsingByteBuffer(this.attachment),
0, val, 16, 4);

return val;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ private <T extends Resource> Flux<FeedResponse<T>> createQuery(
IDocumentQueryClient queryClient = DocumentQueryClientImpl(RxDocumentClientImpl.this);
Flux<? extends IDocumentQueryExecutionContext<T>> executionContext =
DocumentQueryExecutionContextFactory.createDocumentQueryExecutionContextAsync(queryClient, resourceTypeEnum, klass, sqlQuery , options, queryResourceLink, false, activityId);
return executionContext.flatMap(IDocumentQueryExecutionContext::executeAsync);
return executionContext.flatMap(IDocumentQueryExecutionContext<T>::executeAsync);
}


Expand Down Expand Up @@ -1569,7 +1569,7 @@ private <T extends Resource> Flux<FeedResponse<T>> createReadManyQuery(
activityId,
klass,
resourceTypeEnum);
return executionContext.flatMap(IDocumentQueryExecutionContext::executeAsync);
return executionContext.flatMap(IDocumentQueryExecutionContext<T>::executeAsync);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public <T extends Resource> T getResource(Class<T> c) {
return resource;
}

@SuppressWarnings("unchecked")
// Given cls (where cls == Class<T>), objectNode is first decoded to cls and then casted to T.
public <T extends Resource> List<T> getQueryResponse(Class<T> c) {
byte[] responseBody = this.getResponseBodyAsByteArray();
if (responseBody == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private void addSessionToken(ResourceId resourceId, String partitionKeyRangeId,
if (existingTokens == null) {
logger.info("Registering a new collection resourceId [{}] in SessionTokens", resourceId);
ConcurrentHashMap<String, ISessionToken> tokens =
new ConcurrentHashMap(200, 0.75f, 2000);
new ConcurrentHashMap<String, ISessionToken>(200, 0.75f, 2000);
tokens.put(partitionKeyRangeId, parsedSessionToken);
return tokens;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.azure.cosmos.implementation.Utils.ValueHolder;
Expand Down Expand Up @@ -109,6 +110,15 @@ public boolean equals(Object obj) {
return this.version == other.version
&& this.globalLsn == other.globalLsn
&& this.areRegionProgressEqual(other.localLsnByRegion);

}

@Override
public int hashCode() {
// TODO: @kushagraThapar, @moderakh, mbhaskar to identify proper implementation.
// Issue: https://github.com/Azure/azure-sdk-for-java/issues/9046
// return Objects.hash(this.version, this.globalLsn, this.localLsnByRegion);
return super.hashCode();
}

public boolean isValid(ISessionToken otherSessionToken) throws CosmosClientException {
Expand Down Expand Up @@ -198,7 +208,7 @@ public ISessionToken merge(ISessionToken obj) throws CosmosClientException {
return new VectorSessionToken(
Math.max(this.version, other.version),
Math.max(this.globalLsn, other.globalLsn),
(UnmodifiableMap) UnmodifiableMap.unmodifiableMap(highestLocalLsnByRegion));
(UnmodifiableMap<Integer, Long>) UnmodifiableMap.unmodifiableMap(highestLocalLsnByRegion));
}

public String convertToString() {
Expand Down Expand Up @@ -275,7 +285,7 @@ private static boolean tryParseSessionToken(
lsnByRegion.put(regionId.v, localLsn.v);
}

localLsnByRegion.v = (UnmodifiableMap) UnmodifiableMap.unmodifiableMap(lsnByRegion);
localLsnByRegion.v = (UnmodifiableMap<Integer, Long>) UnmodifiableMap.unmodifiableMap(lsnByRegion);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ <T> Mono<CosmosAsyncItemResponse<T>> createItem(CosmosAsyncContainer containerLi
* @param options the request options.
* @return an {@link Mono} containing the cosmos item resource response with the deleted item or an error.
*/
Mono<CosmosAsyncItemResponse> deleteItem(String itemId, PartitionKey partitionKey,
Mono<CosmosAsyncItemResponse<Object>> deleteItem(String itemId, PartitionKey partitionKey,
CosmosItemRequestOptions options);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public <T> Mono<CosmosAsyncItemResponse<T>> createItem(CosmosAsyncContainer cont
}

@Override
public Mono<CosmosAsyncItemResponse> deleteItem(String itemId, PartitionKey partitionKey,
public Mono<CosmosAsyncItemResponse<Object>> deleteItem(String itemId, PartitionKey partitionKey,
CosmosItemRequestOptions options) {
return cosmosContainer.deleteItem(itemId, partitionKey, options)
.publishOn(this.rxScheduler);
Expand All @@ -137,7 +137,7 @@ public <T> Mono<CosmosAsyncItemResponse<T>> replaceItem(String itemId, Partition
}

@Override
public <T> Mono<CosmosAsyncItemResponse<T>> readItem(String itemId, PartitionKey partitionKey,
public <T> Mono<CosmosAsyncItemResponse<T>> readItem(String itemId, PartitionKey partitionKey,
CosmosItemRequestOptions options, Class<T> itemType) {
return cosmosContainer.readItem(itemId, partitionKey, options, itemType)
.publishOn(this.rxScheduler);
Expand Down
Loading

0 comments on commit 1300def

Please sign in to comment.