Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several compiler warnings #4041

Merged
merged 2 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ private List<RuleExecution> simulateExecutionsForRule(Rule rule, ZonedDateTime f
// Only triggers that are time-based will be considered within the simulation
if (triggerHandler instanceof TimeBasedTriggerHandler handler) {
SchedulerTemporalAdjuster temporalAdjuster = handler.getTemporalAdjuster();
if (temporalAdjuster != null) {
executions.addAll(simulateExecutionsForCronBasedRule(rule, from, until, temporalAdjuster));
}
executions.addAll(simulateExecutionsForCronBasedRule(rule, from, until, temporalAdjuster));
}
}
logger.debug("Created {} rule simulations for rule {}.", executions.size(), rule.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,7 @@ public void execute(String[] args, Console console) {
}

String res = super.executeCommand(command, params);
if (res == null) {
console.println(String.format("Unsupported command %s", command));
} else {
console.println(res);
}
console.println(res);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.openhab.core.automation.internal.ruleengine;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.automation.Module;
Expand All @@ -23,7 +24,7 @@
* @author Markus Rathgeb - Initial contribution
*/
@NonNullByDefault
public class WrappedModule<M extends Module, H extends ModuleHandler> {
public class WrappedModule<@NonNull M extends Module, H extends ModuleHandler> {

private final M module;
private @Nullable H handler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package org.openhab.core.config.core;

import static java.util.Collections.*;
import static java.util.Collections.synchronizedMap;
import static org.openhab.core.config.core.ConfigUtil.normalizeTypes;

import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Objects;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -125,7 +126,7 @@ public String getName() {
private @NonNullByDefault({}) @Mock ScheduledCompletableFuture<Void> scheduledFutureMock;
private @NonNullByDefault({}) @Mock ItemRegistry itemRegistryMock;
private @NonNullByDefault({}) @Mock SafeCaller safeCallerMock;
private @NonNullByDefault({}) @Mock SafeCallerBuilder<QueryablePersistenceService> safeCallerBuilderMock;
private @NonNullByDefault({}) @Mock SafeCallerBuilder<@NonNull QueryablePersistenceService> safeCallerBuilderMock;
private @NonNullByDefault({}) @Mock ReadyService readyServiceMock;
private @NonNullByDefault({}) @Mock PersistenceServiceConfigurationRegistry persistenceServiceConfigurationRegistryMock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.HashSet;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.thing.type.ChannelType;
Expand All @@ -30,7 +31,7 @@
*/
@NonNullByDefault
@SuppressWarnings("unchecked")
abstract class AbstractChannelTypeBuilder<T extends ChannelTypeBuilder<T>> implements ChannelTypeBuilder<T> {
abstract class AbstractChannelTypeBuilder<@NonNull T extends ChannelTypeBuilder<T>> implements ChannelTypeBuilder<T> {

protected final ChannelTypeUID channelTypeUID;
protected final String label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Collection;
import java.util.HashSet;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.internal.profiles.StateProfileTypeImpl;
import org.openhab.core.thing.internal.profiles.TriggerProfileTypeImpl;
Expand All @@ -31,7 +32,7 @@
* @param <T> the concrete {@link ProfileType} sub-interface.
*/
@NonNullByDefault
public final class ProfileTypeBuilder<T extends ProfileType> {
public final class ProfileTypeBuilder<@NonNull T extends ProfileType> {

@FunctionalInterface
private interface ProfileTypeFactory<T extends ProfileType> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.net.URI;
import java.util.Collection;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.internal.type.StateChannelTypeBuilderImpl;
import org.openhab.core.thing.internal.type.TriggerChannelTypeBuilderImpl;
Expand All @@ -25,7 +26,7 @@
* @author Stefan Triller - Initial contribution
*/
@NonNullByDefault
public interface ChannelTypeBuilder<T extends ChannelTypeBuilder<T>> {
public interface ChannelTypeBuilder<@NonNull T extends ChannelTypeBuilder<T>> {
/**
* Specify whether this is an advanced channel, default is false
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public NamedThreadFactory(final String id, final boolean daemonize, final int pr
this.daemonize = daemonize;
this.priority = priority;
this.namePrefix = "OH-" + id + "-";
final SecurityManager securityManager = System.getSecurityManager();
this.group = securityManager != null ? securityManager.getThreadGroup()
: Thread.currentThread().getThreadGroup();
this.group = Thread.currentThread().getThreadGroup();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ public void execute(Runnable command) {
if (taskQueue.isEmpty()) {
super.execute(command);
} else {
if (command == null) {
throw new IllegalArgumentException("Command can not be null.");
}

// ignore incoming tasks when the executor is shutdown
if (!isShutdown()) {
addToQueue(command);
Expand Down Expand Up @@ -240,8 +236,7 @@ private static class CommonThreadFactory implements ThreadFactory {

public CommonThreadFactory(String name) {
this.name = name;
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
group = Thread.currentThread().getThreadGroup();
}

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

import java.util.concurrent.TimeUnit;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;

/**
Expand All @@ -39,5 +40,5 @@ public interface SafeCaller {
* @param interfaceType the interface which defines the relevant methods
* @return a safe call builder instance.
*/
<T> SafeCallerBuilder<T> create(T target, Class<T> interfaceType);
<T> SafeCallerBuilder<@NonNull T> create(T target, Class<T> interfaceType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.util.function.Consumer;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;

/**
Expand All @@ -24,7 +25,7 @@
* @param <T>
*/
@NonNullByDefault
public interface SafeCallerBuilder<T> {
public interface SafeCallerBuilder<@NonNull T> {

/**
* Creates a dynamic proxy with the according properties which guards the caller from hanging implementations in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,12 @@ public void added(Provider<E> provider, E element) {
*/
private boolean added(Provider<E> provider, E element, Collection<E> providerElements) {
final K uid = element.getUID();
if (identifierToElement.containsKey(uid)) {
@Nullable
E existingElement = identifierToElement.get(uid);
if (existingElement != null) {
logger.debug(
"Cannot add \"{}\" with key \"{}\". It exists already from provider \"{}\"! Failed to add a second with the same UID from provider \"{}\"!",
element.getClass().getSimpleName(), uid,
elementToProvider.get(identifierToElement.get(uid)).getClass().getSimpleName(),
element.getClass().getSimpleName(), uid, existingElement.getClass().getSimpleName(),
wborn marked this conversation as resolved.
Show resolved Hide resolved
provider.getClass().getSimpleName());
return false;
}
Expand Down Expand Up @@ -245,7 +246,7 @@ public void removed(Provider<E> provider, E element) {
return;
}
Provider<E> elementProvider = elementToProvider.get(existingElement);
if (!elementProvider.equals(provider)) {
if (elementProvider != null && !elementProvider.equals(provider)) {
logger.error(
"Provider '{}' is not allowed to remove element '{}' with key '{}' from the registry because it was added by provider '{}'.",
provider.getClass().getSimpleName(), element.getClass().getSimpleName(), uid,
Expand Down Expand Up @@ -439,7 +440,7 @@ protected void addProvider(Provider<E> provider) {
}
elementsAdded.forEach(this::notifyListenersAboutAddedElement);

if (provider instanceof ManagedProvider && readyService != null) {
if (provider instanceof ManagedProvider && providerClazz != null && readyService != null) {
readyService.markReady(
new ReadyMarker("managed", providerClazz.getSimpleName().replace("Provider", "").toLowerCase()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.function.Consumer;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.common.SafeCaller;
Expand All @@ -31,7 +32,7 @@
* @param <T>
*/
@NonNullByDefault
public class SafeCallerBuilderImpl<T> implements SafeCallerBuilder<T> {
public class SafeCallerBuilderImpl<@NonNull T> implements SafeCallerBuilder<T> {

private final T target;
private final Class<?>[] interfaceTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.common.SafeCaller;
Expand Down Expand Up @@ -62,7 +63,7 @@ public void deactivate() {
}

@Override
public <T> SafeCallerBuilder<T> create(T target, Class<T> interfaceType) {
public <T> SafeCallerBuilder<@NonNull T> create(T target, Class<T> interfaceType) {
return new SafeCallerBuilderImpl<>(target, new Class<?>[] { interfaceType }, manager);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public MetadataCommandDescriptionProvider(final @Reference MetadataRegistry meta
if (metadata != null) {
try {
CommandDescriptionImpl commandDescription = new CommandDescriptionImpl();
if (metadata.getConfiguration().containsKey("options")) {
Stream.of(metadata.getConfiguration().get("options").toString().split(",")).forEach(o -> {
Object options = metadata.getConfiguration().get("options");
if (options != null) {
Stream.of(options.toString().split(",")).forEach(o -> {
if (o.contains("=")) {
var pair = parseValueLabelPair(o.trim());
commandDescription.addCommandOption(new CommandOption(pair[0], pair[1]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ public List<String> getGroupNames() {
*/
@Override
public void addGroupName(String groupItemName) {
if (groupItemName == null) {
throw new IllegalArgumentException("Group item name must not be null!");
}
if (!groupNames.contains(groupItemName)) {
groupNames.add(groupItemName);
}
Expand Down Expand Up @@ -161,9 +158,6 @@ public void addGroupNames(List<String> groupItemNames) {
*/
@Override
public void removeGroupName(String groupItemName) {
if (groupItemName == null) {
throw new IllegalArgumentException("Group item name must not be null!");
}
groupNames.remove(groupItemName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ public Set<Item> getMembers(Predicate<Item> filterItem) {
* @throws IllegalArgumentException if the given item is null
*/
public void addMember(Item item) {
if (item == null) {
throw new IllegalArgumentException("Item must not be null!");
}

boolean added = members.addIfAbsent(item);

// in case membership is constructed programmatically this sanitizes
Expand All @@ -190,9 +186,6 @@ private void unregisterStateListener(Item old) {
}

public void replaceMember(Item oldItem, Item newItem) {
if (oldItem == null || newItem == null) {
throw new IllegalArgumentException("Items must not be null!");
}
int index = members.indexOf(oldItem);
if (index > -1) {
Item old = members.set(index, newItem);
Expand All @@ -208,9 +201,6 @@ public void replaceMember(Item oldItem, Item newItem) {
* @throws IllegalArgumentException if the given item is null
*/
public void removeMember(Item item) {
if (item == null) {
throw new IllegalArgumentException("Item must not be null!");
}
members.remove(item);
unregisterStateListener(item);
}
Expand Down Expand Up @@ -287,6 +277,7 @@ public void send(Command command) {

@Override
protected void internalSend(Command command) {
EventPublisher eventPublisher = this.eventPublisher;
if (eventPublisher != null) {
for (Item member : members) {
// try to send the command to the bus
Expand All @@ -304,7 +295,8 @@ protected void internalSend(Command command) {
newState = function.getStateAs(getStateMembers(getMembers()), typeClass);
}

if (newState == null && baseItem != null && baseItem instanceof GenericItem item) {
Item baseItem = this.baseItem;
if (newState == null && baseItem instanceof GenericItem item) {
// we use the transformation method from the base item
item.setState(state);
newState = baseItem.getStateAs(typeClass);
Expand Down Expand Up @@ -363,6 +355,7 @@ public void stateChanged(Item item, State oldState, State newState) {
public void stateUpdated(Item item, State state) {
State oldState = this.state;
State newState = oldState;
ItemStateConverter itemStateConverter = this.itemStateConverter;
if (function != null && baseItem != null && itemStateConverter != null) {
State calculatedState = function.calculate(getStateMembers(getMembers()));
newState = itemStateConverter.convertToAcceptedState(calculatedState, baseItem);
Expand All @@ -377,7 +370,8 @@ public void stateUpdated(Item item, State state) {
@Override
public void setState(State state) {
State oldState = this.state;
if (baseItem != null && baseItem instanceof GenericItem item) {
Item baseItem = this.baseItem;
if (baseItem instanceof GenericItem item) {
item.setState(state);
this.state = baseItem.getState();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
*/
package org.openhab.core.library.unit;

import static org.eclipse.jdt.annotation.DefaultLocation.FIELD;
import static org.eclipse.jdt.annotation.DefaultLocation.PARAMETER;
import static org.eclipse.jdt.annotation.DefaultLocation.RETURN_TYPE;
import static org.eclipse.jdt.annotation.DefaultLocation.TYPE_BOUND;
import static org.eclipse.jdt.annotation.DefaultLocation.*;
import static org.openhab.core.library.unit.CurrencyUnits.BASE_CURRENCY;
import static tech.units.indriya.AbstractUnit.ONE;

import java.math.BigDecimal;
import java.math.MathContext;
Expand Down Expand Up @@ -70,6 +66,7 @@ public CurrencyUnit(String name, @Nullable String symbol) throws IllegalArgument
this.name = name;
}

@Override
public UnitConverter getSystemConverter() {
return internalGetConverterTo(getSystemUnit());
}
Expand All @@ -94,6 +91,7 @@ public Dimension getDimension() {
return DIMENSION;
}

@Override
public void setName(@NonNullByDefault({}) String name) {
this.name = name;
}
Expand All @@ -108,6 +106,7 @@ public String getName() {
return symbol;
}

@Override
public void setSymbol(@Nullable String s) {
this.symbol = s;
}
Expand Down