Skip to content

Commit

Permalink
fix raw generic type usages and other sonar issues
Browse files Browse the repository at this point in the history
* + removed deprecated code

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Apr 19, 2021
1 parent 4a3aa71 commit b0db7c6
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.ditto.model.base.entity.id.WithEntityId;
import org.eclipse.ditto.model.base.entity.type.WithEntityType;
import org.eclipse.ditto.model.base.headers.DittoHeadersSettable;
import org.eclipse.ditto.model.base.entity.id.WithEntityId;

/**
* Common interface for all Thing related changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private static final class WebSocketMessagingConfigurationBuilder implements Mes

private static final List<String> ALLOWED_URI_SCHEME = Arrays.asList("wss", "ws");
private static final String WS_PATH = "/ws/";
private static final String WS_PATH_REGEX = "/ws/([12])/?";
private static final String WS_PATH_REGEX = "/ws/2/?";

private JsonSchemaVersion jsonSchemaVersion;
private Duration timeout = Duration.ofSeconds(60L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ protected String signalToJsonString(final Signal<?> signal) {
* @param adaptable the adaptable.
* @return the signal.
*/
protected Signal<?> signalFromAdaptable(final Adaptable adaptable) {
@SuppressWarnings({"rawtypes", "java:S3740"})
protected Signal signalFromAdaptable(final Adaptable adaptable) {
return PROTOCOL_ADAPTER.fromAdaptable(adaptable);
}

Expand Down Expand Up @@ -253,8 +254,8 @@ protected Adaptable adaptOutgoingLiveSignal(final Signal<?> liveSignal) {
return PROTOCOL_ADAPTER.toAdaptable(adjustHeadersForLiveSignal(liveSignal));
}

@SuppressWarnings({"unchecked", "rawtypes"})
protected static Signal<?> adjustHeadersForLiveSignal(final Signal<?> signal) {
@SuppressWarnings({"unchecked", "rawtypes", "java:S3740"})
protected static Signal adjustHeadersForLiveSignal(final Signal<?> signal) {
return adjustHeadersForLive((Signal) signal);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
*/
class BusAddressFactory {

private BusAddressFactory() {
throw new AssertionError();
}

private static final ThingResourceMapper<ThingId, String> RESOURCE_PATH_MAPPER =
ThingResourceMapper.from(PathToBusAddressVisitor.getInstance());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public final class HandlerRegistry<T extends ThingHandle<F>, F extends FeatureHandle> {

private final PointerBus bus;
private final Map<String, Registration<Consumer<PointerWithData>>> registry;
private final Map<String, Registration<Consumer<PointerWithData<?>>>> registry;
private final Map<ThingId, T> thingHandles;
private final Map<String, F> featureHandles;

Expand Down Expand Up @@ -82,7 +82,7 @@ public Executor getBusExecutor() {
* registrationId}
*/
public void register(final String registrationId, final JsonPointerSelector selector,
final Consumer<PointerWithData> consumer) {
final Consumer<PointerWithData<?>> consumer) {
checkRegistrationId(registrationId);

registry.compute(registrationId, (k, v) -> {
Expand All @@ -104,7 +104,7 @@ public void register(final String registrationId, final JsonPointerSelector sele
public boolean deregister(final String registrationId) {
checkRegistrationId(registrationId);

final Registration<Consumer<PointerWithData>> registration = registry.remove(registrationId);
final Registration<Consumer<PointerWithData<?>>> registration = registry.remove(registrationId);
if (registration == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
final class DefaultAdaptableBus implements AdaptableBus {

private static final String ACK_SUFFIX = ":ACK";
private static final Logger LOGGER = LoggerFactory.getLogger(AdaptableBus.class);
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultAdaptableBus.class);

private final ExecutorService singleThreadedExecutorService;
private final ScheduledExecutorService scheduledExecutorService;
Expand Down Expand Up @@ -168,7 +168,8 @@ public void shutdownExecutor() {
scheduledExecutorService.shutdownNow();
singleThreadedExecutorService.awaitTermination(2, TimeUnit.SECONDS);
scheduledExecutorService.awaitTermination(2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
LOGGER.info("Waiting for termination was interrupted.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class DefaultPointerBus implements PointerBus {

private final String name;
private final ExecutorService executor;
private final Registry<Consumer<PointerWithData>> consumerRegistry;
private final Registry<Consumer<PointerWithData<?>>> consumerRegistry;

DefaultPointerBus(final String name, final ExecutorService executor) {
this.name = name;
Expand All @@ -50,8 +50,8 @@ public <T> void notify(final PointerWithData<T> pointerWithData) {
}

@Override
public Registration<Consumer<PointerWithData>> on(final JsonPointerSelector selector,
final Consumer<PointerWithData> consumer) {
public Registration<Consumer<PointerWithData<?>>> on(final JsonPointerSelector selector,
final Consumer<PointerWithData<?>> consumer) {

return consumerRegistry.register(selector, consumer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ default <T> void notify(final JsonPointer key, final T object) {
* @param consumer The {@literal Consumer} to be triggered
* @return A {@link Registration} object that allows the caller to interact with the given mapping
*/
Registration<Consumer<PointerWithData>> on(JsonPointerSelector selector, Consumer<PointerWithData> consumer);
Registration<Consumer<PointerWithData<?>>> on(JsonPointerSelector selector, Consumer<PointerWithData<?>> consumer);

/**
* @return the ExecutorService used for this Bus instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public static JsonPointerSelector formatJsonPointer(final Logger logger, final S
* occurred ThingEvent
* @param <T> the type of the ThingEvent
*/
@SuppressWarnings({"rawtypes", "java:S3740"})
public static <T extends org.eclipse.ditto.signals.events.base.Event> void addHandlerForThingEvent(
final Logger logger,
final PointerBus in,
Expand Down Expand Up @@ -319,10 +320,8 @@ private static <T extends Change> void resolveTemplateParametersAndPassChangeToH
return valueToSet;
} else {
JsonValue valueToSet = value;
if (value.isObject()) {
if (value.asObject().contains(diff)) {
valueToSet = value.asObject().getValue(diff).get();
}
if (value.isObject() && value.asObject().contains(diff)) {
valueToSet = value.asObject().getValue(diff).get();
}
return JsonObject.newBuilder().set(parsedPath, valueToSet).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public final class LiveCommandFactory {
private static final int STRATEGIES_NUMBER = 26;
private static final LiveCommandFactory INSTANCE = new LiveCommandFactory();

private final Map<String, Function<Command, LiveCommand>> mappingStrategies;
private final Map<String, Function<Command<?>, LiveCommand<?, ?>>> mappingStrategies;

private LiveCommandFactory() {
mappingStrategies = Collections.unmodifiableMap(initMappingStrategies());
}

private static Map<String, Function<Command, LiveCommand>> initMappingStrategies() {
final Map<String, Function<Command, LiveCommand>> result = new HashMap<>(STRATEGIES_NUMBER);
private static Map<String, Function<Command<?>, LiveCommand<?, ?>>> initMappingStrategies() {
final Map<String, Function<Command<?>, LiveCommand<?, ?>>> result = new HashMap<>(STRATEGIES_NUMBER);
result.put(CreateThing.TYPE, ModifyLiveCommandFactory::createThing);
result.put(DeleteAttribute.TYPE, ModifyLiveCommandFactory::deleteAttribute);
result.put(DeleteAttributes.TYPE, ModifyLiveCommandFactory::deleteAttributes);
Expand Down Expand Up @@ -125,11 +125,11 @@ public static LiveCommandFactory getInstance() {
* mapping strategy associated with the command's type.
*/
@Nonnull
public LiveCommand getLiveCommand(@Nonnull final Command<?> command) {
public LiveCommand<?, ?> getLiveCommand(@Nonnull final Command<?> command) {
checkNotNull(command, "command");

final String commandType = command.getType();
final Function<Command, LiveCommand> commandToLiveCommand = mappingStrategies.get(commandType);
final Function<Command<?>, LiveCommand<?, ?>> commandToLiveCommand = mappingStrategies.get(commandType);
if (null == commandToLiveCommand) {
final String msgTemplate = "No mapping strategy for command <{0}> available!"
+ " The command type <{1}> is unknown!";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public interface LiveCommandAnswer {
* @return the CommandResponse or an empty Optional.
*/
@Nonnull
@SuppressWarnings({"rawtypes", "java:S3740"})
Optional<CommandResponse> getResponse();

/**
Expand All @@ -40,6 +41,7 @@ public interface LiveCommandAnswer {
* @return the Event or an empty Optional.
*/
@Nonnull
@SuppressWarnings({"rawtypes", "java:S3740"})
Optional<Event> getEvent();

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,6 @@ default ThingErrorResponse errorResponse(final DittoRuntimeException dittoRuntim
return ThingErrorResponse.of(dittoRuntimeException);
}

/**
* Creates a generic {@link ErrorResponse} which includes the passed {@link DittoRuntimeException}.
* <p>
* Use this method only if you are absolutely sure that the counterpart which issued the {@link
* org.eclipse.ditto.signals.commands.base.Command} expects such a type of {@code ErrorResponse}
* for the issued {@code Command}.
*
* @param thingId the Thing ID of the related Thing.
* @param dittoRuntimeException the DittoRuntimeException to include in the ErrorResponse.
* @return the built ErrorResponse.
* @throws NullPointerException if {@code dittoRuntimeException} is {@code null}.
* @deprecated Thing ID is now typed.
* Use {@link #errorResponse(org.eclipse.ditto.model.things.ThingId, org.eclipse.ditto.model.base.exceptions.DittoRuntimeException)}
* instead.
*/
@Deprecated
default ThingErrorResponse errorResponse(final String thingId, final DittoRuntimeException dittoRuntimeException) {
return errorResponse(ThingId.of(thingId), dittoRuntimeException);
}

/**
* Creates a generic {@link ErrorResponse} which includes the passed {@link DittoRuntimeException}.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public LiveCommandAnswer build() {
* @return the CommandResponse.
*/
@Nullable
@SuppressWarnings({"rawtypes", "java:S3740"})
protected abstract CommandResponse doCreateResponse(Function<R, CommandResponse<?>> createResponseFunction);

/**
Expand All @@ -113,6 +114,7 @@ public LiveCommandAnswer build() {
* @return the Event.
*/
@Nullable
@SuppressWarnings({"rawtypes", "java:S3740"})
protected abstract Event doCreateEvent(Function<E, Event<?>> createEventFunction);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package org.eclipse.ditto.client.live.commands.query;

import java.util.List;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;

Expand All @@ -22,7 +21,6 @@
import org.eclipse.ditto.signals.commands.base.WithNamespace;
import org.eclipse.ditto.signals.commands.things.WithSelectedFields;
import org.eclipse.ditto.signals.commands.things.query.RetrieveThings;
import org.eclipse.ditto.signals.commands.things.query.ThingQueryCommand;

/**
* {@link RetrieveThings} live command giving access to the command and all of its special accessors.
Expand All @@ -39,14 +37,7 @@ public interface RetrieveThingsLiveCommand
* Returns the identifiers of the {@code Thing}s to be retrieved.
*
* @return the identifiers
* @deprecated the thing ID is now typed. Use {@link #getEntityIds()} instead.
*/
@Nonnull
@Deprecated
default List<String> getThingIds() {
return getEntityIds().stream().map(String::valueOf).collect(Collectors.toList());
}

@Nonnull
List<ThingId> getEntityIds();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import org.eclipse.ditto.client.live.commands.base.AbstractLiveCommand;
import org.eclipse.ditto.model.base.headers.DittoHeaders;
import org.eclipse.ditto.model.base.json.Jsonifiable;
import org.eclipse.ditto.model.things.ThingId;
import org.eclipse.ditto.signals.commands.base.Command;
import org.eclipse.ditto.signals.commands.things.ThingCommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
* LiveCommand} and {@link org.eclipse.ditto.client.live.commands.base.LiveCommandAnswerBuilder
* LiveCommandAnswerBuilder} for query operations.
*/
@org.eclipse.ditto.utils.jsr305.annotations.AllParametersAndReturnValuesAreNonnullByDefault
package org.eclipse.ditto.client.live.commands.query;
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.eclipse.ditto.protocoladapter.ProtocolAdapter;
import org.eclipse.ditto.protocoladapter.TopicPath;
import org.eclipse.ditto.signals.acks.base.Acknowledgement;
import org.eclipse.ditto.signals.base.Signal;
import org.eclipse.ditto.signals.commands.messages.MessageCommand;
import org.eclipse.ditto.signals.commands.messages.MessageCommandResponse;
import org.eclipse.ditto.signals.commands.messages.SendFeatureMessage;
Expand Down Expand Up @@ -71,7 +70,7 @@ static <T> void checkSerializerExistForMessageType(final MessageSerializerRegist
}
}

static <T, U> Consumer<PointerWithData> createEventConsumerForRepliableMessage(
static <T, U> Consumer<PointerWithData<?>> createEventConsumerForRepliableMessage(
final ProtocolAdapter protocolAdapter,
final MessagingProvider messagingProvider,
final OutgoingMessageFactory outgoingMessageFactory,
Expand All @@ -95,7 +94,7 @@ static <T, U> Consumer<PointerWithData> createEventConsumerForRepliableMessage(
};
}

static <U> Consumer<PointerWithData> createEventConsumerForRepliableMessage(
static <U> Consumer<PointerWithData<?>> createEventConsumerForRepliableMessage(
final ProtocolAdapter protocolAdapter,
final MessagingProvider messagingProvider,
final OutgoingMessageFactory outgoingMessageFactory,
Expand Down Expand Up @@ -133,10 +132,10 @@ private static <U> Consumer<Message<U>> responsePublisher(

private static Consumer<Acknowledgement> acknowledgementPublisher(final ProtocolAdapter protocolAdapter,
final MessagingProvider messagingProvider) {
return ack -> messagingProvider.emitAdaptable(protocolAdapter.toAdaptable((Signal<?>) ack));
return ack -> messagingProvider.emitAdaptable(protocolAdapter.toAdaptable(ack));
}

private static <T> Message<T> eventToMessage(final PointerWithData e, final Class<T> type, final boolean
private static <T> Message<T> eventToMessage(final PointerWithData<?> e, final Class<T> type, final boolean
copyRawPayloadToPayload) {
final Message<?> incomingMessage = (Message<?>) e.getData();
LOGGER.trace("Received message {} for message handler.", incomingMessage);
Expand All @@ -158,7 +157,7 @@ public static Adaptable constructAdaptableFromMessage(final Message<?> message,
final ProtocolAdapter protocolAdapter) {

final TopicPath.Channel channel = TopicPath.Channel.LIVE;
final DittoHeadersBuilder headersBuilder = DittoHeaders.newBuilder().channel(channel.getName());
final DittoHeadersBuilder<?, ?> headersBuilder = DittoHeaders.newBuilder().channel(channel.getName());
final Optional<String> optionalCorrelationId = message.getCorrelationId();
optionalCorrelationId.ifPresent(headersBuilder::correlationId);
final DittoHeaders dittoHeaders = headersBuilder.build();
Expand All @@ -173,12 +172,12 @@ public static Adaptable constructAdaptableFromMessage(final Message<?> message,
final MessageCommandResponse<?, ?> messageCommandResponse = featureIdOptional.isPresent()
? SendFeatureMessageResponse.of(thingId, featureIdOptional.get(), message, httpStatus, dittoHeaders)
: SendThingMessageResponse.of(thingId, message, httpStatus, dittoHeaders);
adaptable = protocolAdapter.toAdaptable((Signal<?>) messageCommandResponse);
adaptable = protocolAdapter.toAdaptable(messageCommandResponse);
} else {
final MessageCommand<?, ?> messageCommand = featureIdOptional.isPresent()
? SendFeatureMessage.of(thingId, featureIdOptional.get(), message, dittoHeaders)
: SendThingMessage.of(thingId, message, dittoHeaders);
adaptable = protocolAdapter.toAdaptable((Signal<?>) messageCommand);
adaptable = protocolAdapter.toAdaptable(messageCommand);
}
return adaptable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public <T> Optional<MessageSerializerKey<T>> findKeyFor(final Class<T> javaType,
.collect(Collectors.toList());
if (foundCandidates.size() == 1) {
return Optional.of((MessageSerializerKey<T>) foundCandidates.get(0));
} else if (foundCandidates.size() == 0) {
} else if (foundCandidates.isEmpty()) {
if (!subject.equals(MessageSerializerKey.SUBJECT_WILDCARD)) {
final Optional<MessageSerializerKey<?>> wildcardKey = getSerializerKeysForJavaTypeAndSubject(javaType,
MessageSerializerKey.SUBJECT_WILDCARD).findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class AcknowledgementsFailedException extends RuntimeException {

private static final String MESSAGE_TEMPLATE = "Requested acknowledgements failed with status code %d.";

private final Acknowledgements acknowledgements;
private final transient Acknowledgements acknowledgements;

private AcknowledgementsFailedException(final Acknowledgements acknowledgements) {
super(String.format(MESSAGE_TEMPLATE, checkNotNull(acknowledgements, "acknowledgements").getHttpStatus().getCode()));
Expand Down

0 comments on commit b0db7c6

Please sign in to comment.