Skip to content

Commit

Permalink
Fix compiler warnings in :server - part 1 (#75708)
Browse files Browse the repository at this point in the history
Part of #40366. Fix a number of javac issues when linting is enforced in `server/`.
  • Loading branch information
pugnascotia committed Jul 27, 2021
1 parent 348bd92 commit 84346d9
Show file tree
Hide file tree
Showing 86 changed files with 295 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ static void writeDocumentRequestThin(StreamOutput out, DocWriteRequest<?> reques
}

static ActionRequestValidationException validateSeqNoBasedCASParams(
DocWriteRequest request, ActionRequestValidationException validationException) {
DocWriteRequest<?> request, ActionRequestValidationException validationException) {
final long version = request.version();
final VersionType versionType = request.versionType();
if (versionType.validateVersionForWrites(version) == false) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public PutMappingRequestBuilder setSource(XContentBuilder mappingBuilder) {
/**
* The mapping source definition.
*/
public PutMappingRequestBuilder setSource(Map mappingSource) {
public PutMappingRequestBuilder setSource(Map<String, ?> mappingSource) {
request.source(mappingSource);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implem
PARSER.declareField((parser, request, includeTypeName) -> {
if (includeTypeName) {
for (Map.Entry<String, Object> mappingsEntry : parser.map().entrySet()) {
request.createIndexRequest.mapping(mappingsEntry.getKey(), (Map<String, Object>) mappingsEntry.getValue());
@SuppressWarnings("unchecked")
final Map<String, Object> value = (Map<String, Object>) mappingsEntry.getValue();
request.createIndexRequest.mapping(mappingsEntry.getKey(), value);
}
} else {
// a type is not included, add a dummy _doc type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ public long getVersion() {
* The actual response ({@link IndexResponse} or {@link DeleteResponse}). {@code null} in
* case of failure.
*/
@SuppressWarnings("unchecked")
public <T extends DocWriteResponse> T getResponse() {
return (T) response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
* @see org.elasticsearch.client.Requests#getRequest(String)
* @see org.elasticsearch.client.Client#get(GetRequest)
*/
// It's not possible to suppress teh warning at #realtime(boolean) at a method-level.
@SuppressWarnings("unchecked")
public class GetRequest extends SingleShardRequest<GetRequest> implements RealtimeRequest {

private String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import java.util.List;
import java.util.Locale;

// It's not possible to suppress teh warning at #realtime(boolean) at a method-level.
@SuppressWarnings("unchecked")
public class MultiGetRequest extends ActionRequest
implements Iterable<MultiGetRequest.Item>, CompositeIndicesRequest, RealtimeRequest, ToXContentObject {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ private static List<IngestDocument> parseDocs(Map<String, Object> config) {
if ((object instanceof Map) == false) {
throw new IllegalArgumentException("malformed [docs] section, should include an inner object");
}
@SuppressWarnings("unchecked")
Map<String, Object> dataMap = (Map<String, Object>) object;
Map<String, Object> document = ConfigurationUtils.readMap(null, null,
dataMap, Fields.SOURCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected ResyncReplicationResponse newResponseInstance(StreamInput in) throws I
}

@Override
protected ReplicationOperation.Replicas newReplicasProxy() {
protected ReplicationOperation.Replicas<ResyncReplicationRequest> newReplicasProxy() {
return new ResyncActionReplicasProxy();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class MultiSearchResponse extends ActionResponse implements Iterable<Mult

private static final ParseField RESPONSES = new ParseField(Fields.RESPONSES);
private static final ParseField TOOK_IN_MILLIS = new ParseField("took");
@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<MultiSearchResponse, Void> PARSER = new ConstructingObjectParser<>("multi_search",
true, a -> new MultiSearchResponse(((List<Item>)a[0]).toArray(new Item[0]), (long) a[1]));
static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,15 @@ public final class SearchExecutionStatsCollector extends ActionListener.Delegati
this.nodeId = nodeId;
}

public static BiFunction<Transport.Connection, SearchActionListener, ActionListener> makeWrapper(ResponseCollectorService service) {
return (connection, originalListener) -> new SearchExecutionStatsCollector(originalListener, service, connection.getNode().getId());
@SuppressWarnings("unchecked")
public static
BiFunction<Transport.Connection, SearchActionListener<? super SearchPhaseResult>, ActionListener<? super SearchPhaseResult>>
makeWrapper(ResponseCollectorService service) {
return (connection, originalListener) -> new SearchExecutionStatsCollector(
(ActionListener<SearchPhaseResult>) originalListener,
service,
connection.getNode().getId()
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ ReducedQueryPhase reducedQueryPhase(Collection<? extends SearchPhaseResult> quer
final boolean hasProfileResults = queryResults.stream().anyMatch(res -> res.queryResult().hasProfileResults());

// count the total (we use the query result provider here, since we might not get any hits (we scrolled past them))
final Map<String, List<Suggestion>> groupedSuggestions = hasSuggest ? new HashMap<>() : Collections.emptyMap();
final Map<String, List<Suggestion<?>>> groupedSuggestions = hasSuggest ? new HashMap<>() : Collections.emptyMap();
final Map<String, ProfileShardResult> profileResults = hasProfileResults ? new HashMap<>(queryResults.size())
: Collections.emptyMap();
int from = 0;
Expand All @@ -440,7 +440,7 @@ ReducedQueryPhase reducedQueryPhase(Collection<? extends SearchPhaseResult> quer
if (hasSuggest) {
assert result.suggest() != null;
for (Suggestion<? extends Suggestion.Entry<? extends Suggestion.Entry.Option>> suggestion : result.suggest()) {
List<Suggestion> suggestionList = groupedSuggestions.computeIfAbsent(suggestion.getName(), s -> new ArrayList<>());
List<Suggestion<?>> suggestionList = groupedSuggestions.computeIfAbsent(suggestion.getName(), s -> new ArrayList<>());
suggestionList.add(suggestion);
if (suggestion instanceof CompletionSuggestion) {
CompletionSuggestion completionSuggestion = (CompletionSuggestion) suggestion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public SearchRequestBuilder setRescorer(RescorerBuilder<?> rescorer) {
* @param window rescore window
* @return this for chaining
*/
public SearchRequestBuilder setRescorer(RescorerBuilder rescorer, int window) {
public SearchRequestBuilder setRescorer(RescorerBuilder<?> rescorer, int window) {
sourceBuilder().clearRescorers();
return addRescorer(rescorer.windowSize(window));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ SearchResponse getMergedResponse(Clusters clusters) {
List<InternalAggregations> aggs = new ArrayList<>();
Map<ShardIdAndClusterAlias, Integer> shards = new TreeMap<>();
List<TopDocs> topDocsList = new ArrayList<>(searchResponses.size());
Map<String, List<Suggest.Suggestion>> groupedSuggestions = new HashMap<>();
Map<String, List<Suggest.Suggestion<?>>> groupedSuggestions = new HashMap<>();
Boolean trackTotalHits = null;

TopDocsStats topDocsStats = new TopDocsStats(trackTotalHitsUpTo);
Expand All @@ -138,7 +138,8 @@ SearchResponse getMergedResponse(Clusters clusters) {
Suggest suggest = searchResponse.getSuggest();
if (suggest != null) {
for (Suggest.Suggestion<? extends Suggest.Suggestion.Entry<? extends Suggest.Suggestion.Entry.Option>> entries : suggest) {
List<Suggest.Suggestion> suggestionList = groupedSuggestions.computeIfAbsent(entries.getName(), s -> new ArrayList<>());
List<Suggest.Suggestion<?>> suggestionList =
groupedSuggestions.computeIfAbsent(entries.getName(), s -> new ArrayList<>());
suggestionList.add(entries);
}
List<CompletionSuggestion> completionSuggestions = suggest.filter(CompletionSuggestion.class);
Expand Down Expand Up @@ -297,10 +298,10 @@ private static void setTopDocsShardIndex(Map<ShardIdAndClusterAlias, Integer> sh
}

private static void setSuggestShardIndex(Map<ShardIdAndClusterAlias, Integer> shards,
Map<String, List<Suggest.Suggestion>> groupedSuggestions) {
Map<String, List<Suggest.Suggestion<?>>> groupedSuggestions) {
assignShardIndex(shards);
for (List<Suggest.Suggestion> suggestions : groupedSuggestions.values()) {
for (Suggest.Suggestion suggestion : suggestions) {
for (List<Suggest.Suggestion<?>> suggestions : groupedSuggestions.values()) {
for (Suggest.Suggestion<?> suggestion : suggestions) {
if (suggestion instanceof CompletionSuggestion) {
CompletionSuggestion completionSuggestion = (CompletionSuggestion) suggestion;
for (CompletionSuggestion.Entry options : completionSuggestion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,20 @@ public class SearchTransportService {

private final TransportService transportService;
private final NodeClient client;
private final BiFunction<Transport.Connection, SearchActionListener, ActionListener> responseWrapper;
private final BiFunction<
Transport.Connection,
SearchActionListener<? super SearchPhaseResult>,
ActionListener<? super SearchPhaseResult>> responseWrapper;
private final Map<String, Long> clientConnections = ConcurrentCollections.newConcurrentMapWithAggressiveConcurrency();

public SearchTransportService(TransportService transportService, NodeClient client,
BiFunction<Transport.Connection, SearchActionListener, ActionListener> responseWrapper) {
public SearchTransportService(
TransportService transportService,
NodeClient client,
BiFunction<
Transport.Connection,
SearchActionListener<? super SearchPhaseResult>,
ActionListener<? super SearchPhaseResult>> responseWrapper
) {
this.transportService = transportService;
this.client = client;
this.responseWrapper = responseWrapper;
Expand Down Expand Up @@ -125,13 +134,13 @@ public void sendExecuteDfs(Transport.Connection connection, final ShardSearchReq
}

public void sendExecuteQuery(Transport.Connection connection, final ShardSearchRequest request, SearchTask task,
final SearchActionListener<SearchPhaseResult> listener) {
final SearchActionListener<? super SearchPhaseResult> listener) {
// we optimize this and expect a QueryFetchSearchResult if we only have a single shard in the search request
// this used to be the QUERY_AND_FETCH which doesn't exist anymore.
final boolean fetchDocuments = request.numberOfShards() == 1;
Writeable.Reader<SearchPhaseResult> reader = fetchDocuments ? QueryFetchSearchResult::new : QuerySearchResult::new;

final ActionListener handler = responseWrapper.apply(connection, listener);
final ActionListener<? super SearchPhaseResult> handler = responseWrapper.apply(connection, listener);
transportService.sendChildRequest(connection, QUERY_ACTION_NAME, request, task,
new ConnectionCountingHandler<>(handler, reader, clientConnections, connection.getNode().getId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ListenableActionFuture<T> extends AdapterActionFuture<T, T> {
* Registers an {@link ActionListener} to be notified when this future is completed. If the future is already completed then the
* listener is notified immediately, on the calling thread. If not, the listener is notified on the thread that completes the listener.
*/
@SuppressWarnings("unchecked,rawtypes")
@SuppressWarnings({"unchecked", "rawtypes"})
public void addListener(final ActionListener<T> listener) {
final boolean executeImmediate;
synchronized (this) {
Expand Down Expand Up @@ -56,7 +56,7 @@ public void addListener(final ActionListener<T> listener) {
}

@Override
@SuppressWarnings("unchecked,rawtypes")
@SuppressWarnings({"unchecked", "rawtypes"})
protected void done(boolean success) {
super.done(success);
final Object listenersToExecute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.core.TimeValue;

public abstract class NodesOperationRequestBuilder<Request extends BaseNodesRequest<Request>, Response extends BaseNodesResponse,
public abstract class NodesOperationRequestBuilder<Request extends BaseNodesRequest<Request>, Response extends BaseNodesResponse<?>,
RequestBuilder extends NodesOperationRequestBuilder<Request, Response, RequestBuilder>>
extends ActionRequestBuilder<Request, Response> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.concurrent.atomic.AtomicReferenceArray;

public abstract class TransportNodesAction<NodesRequest extends BaseNodesRequest<NodesRequest>,
NodesResponse extends BaseNodesResponse,
NodesResponse extends BaseNodesResponse<?>,
NodeRequest extends BaseNodeRequest,
NodeResponse extends BaseNodeResponse>
extends HandledTransportAction<NodesRequest, NodesResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.List;
import java.util.Set;

// It's not possible to suppress teh warning at #realtime(boolean) at a method-level.
@SuppressWarnings("unchecked")
public class MultiTermVectorsRequest extends ActionRequest
implements Iterable<TermVectorsRequest>, CompositeIndicesRequest, RealtimeRequest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
* Note, the {@link #index()}, {@link #type(String)} and {@link #id(String)} are
* required.
*/
// It's not possible to suppress teh warning at #realtime(boolean) at a method-level.
@SuppressWarnings("unchecked")
public class TermVectorsRequest extends SingleShardRequest<TermVectorsRequest> implements RealtimeRequest {
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(TermVectorsRequest.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public boolean implies(ProtectionDomain domain, Permission permission) {
* Classy puzzler to rethrow any checked exception as an unchecked one.
*/
private static class Rethrower<T extends Throwable> {
@SuppressWarnings("unchecked")
private void rethrow(Throwable t) throws T {
throw (T) t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ interface LinuxLibrary extends Library {
LinuxLibrary lib = null;
if (Constants.LINUX) {
try {
lib = (LinuxLibrary) Native.loadLibrary("c", LinuxLibrary.class);
lib = Native.loadLibrary("c", LinuxLibrary.class);
} catch (UnsatisfiedLinkError e) {
logger.warn("unable to link C library. native methods (seccomp) will be disabled.", e);
}
Expand Down Expand Up @@ -424,7 +424,7 @@ interface MacLibrary extends Library {
MacLibrary lib = null;
if (Constants.MAC_OS_X) {
try {
lib = (MacLibrary) Native.loadLibrary("c", MacLibrary.class);
lib = Native.loadLibrary("c", MacLibrary.class);
} catch (UnsatisfiedLinkError e) {
logger.warn("unable to link C library. native methods (seatbelt) will be disabled.", e);
}
Expand Down Expand Up @@ -493,7 +493,7 @@ interface SolarisLibrary extends Library {
SolarisLibrary lib = null;
if (Constants.SUN_OS) {
try {
lib = (SolarisLibrary) Native.loadLibrary("c", SolarisLibrary.class);
lib = Native.loadLibrary("c", SolarisLibrary.class);
} catch (UnsatisfiedLinkError e) {
logger.warn("unable to link C library. native methods (priv_set) will be disabled.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public class NodeClient extends AbstractClient {

private Map<ActionType, TransportAction> actions;
private Map<ActionType<? extends ActionResponse>, TransportAction<? extends ActionRequest, ? extends ActionResponse>> actions;
/**
* The id of the local {@link DiscoveryNode}. Useful for generating task ids from tasks returned by
* {@link #executeLocally(ActionType, ActionRequest, TaskListener)}.
Expand All @@ -45,8 +45,12 @@ public NodeClient(Settings settings, ThreadPool threadPool) {
super(settings, threadPool);
}

public void initialize(Map<ActionType, TransportAction> actions, Supplier<String> localNodeId,
RemoteClusterService remoteClusterService, NamedWriteableRegistry namedWriteableRegistry) {
public void initialize(
Map<ActionType<? extends ActionResponse>, TransportAction<? extends ActionRequest, ? extends ActionResponse>> actions,
Supplier<String> localNodeId,
RemoteClusterService remoteClusterService,
NamedWriteableRegistry namedWriteableRegistry
) {
this.actions = actions;
this.localNodeId = localNodeId;
this.remoteClusterService = remoteClusterService;
Expand Down Expand Up @@ -109,14 +113,14 @@ public String getLocalNodeId() {
/**
* Get the {@link TransportAction} for an {@link ActionType}, throwing exceptions if the action isn't available.
*/
@SuppressWarnings("unchecked")
private < Request extends ActionRequest,
Response extends ActionResponse
> TransportAction<Request, Response> transportAction(ActionType<Response> action) {
if (actions == null) {
throw new IllegalStateException("NodeClient has not been initialized");
}
TransportAction<Request, Response> transportAction = actions.get(action);
@SuppressWarnings("unchecked")
TransportAction<Request, Response> transportAction = (TransportAction<Request, Response>) actions.get(action);
if (transportAction == null) {
throw new IllegalStateException("failed to find action [" + action + "] to execute");
}
Expand Down
Loading

0 comments on commit 84346d9

Please sign in to comment.