diff --git a/bundles/org.openhab.core.auth.jaas/src/main/java/org/openhab/core/auth/jaas/internal/JaasAuthenticationProvider.java b/bundles/org.openhab.core.auth.jaas/src/main/java/org/openhab/core/auth/jaas/internal/JaasAuthenticationProvider.java index ee305aa321..0c71f5a74a 100644 --- a/bundles/org.openhab.core.auth.jaas/src/main/java/org/openhab/core/auth/jaas/internal/JaasAuthenticationProvider.java +++ b/bundles/org.openhab.core.auth.jaas/src/main/java/org/openhab/core/auth/jaas/internal/JaasAuthenticationProvider.java @@ -27,6 +27,8 @@ import javax.security.auth.callback.UnsupportedCallbackException; import javax.security.auth.login.LoginContext; import javax.security.auth.login.LoginException; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.auth.Authentication; import org.openhab.core.auth.AuthenticationException; import org.openhab.core.auth.AuthenticationProvider; @@ -48,11 +50,12 @@ import org.osgi.service.component.annotations.Modified; * @author Kai Kreuzer - Removed ManagedService and used DS configuration instead * @author Yannick Schaus - provides a configuration with the ManagedUserLoginModule as a sufficient login module */ +@NonNullByDefault @Component(configurationPid = "org.openhab.jaas") public class JaasAuthenticationProvider implements AuthenticationProvider { - private final String DEFAULT_REALM = "openhab"; + private static final String DEFAULT_REALM = "openhab"; - private String realmName; + private @Nullable String realmName; @Override public Authentication authenticate(final Credentials credentials) throws AuthenticationException { @@ -70,14 +73,14 @@ public class JaasAuthenticationProvider implements AuthenticationProvider { final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); try { - Principal userPrincipal = new GenericUser(name); Subject subject = new Subject(true, Set.of(userPrincipal), Collections.emptySet(), Set.of(userCredentials)); Thread.currentThread().setContextClassLoader(ManagedUserLoginModule.class.getClassLoader()); LoginContext loginContext = new LoginContext(realmName, subject, new CallbackHandler() { @Override - public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + public void handle(@NonNullByDefault({}) Callback[] callbacks) + throws IOException, UnsupportedCallbackException { for (Callback callback : callbacks) { if (callback instanceof PasswordCallback) { ((PasswordCallback) callback).setPassword(password); diff --git a/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthStoreHandlerImpl.java b/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthStoreHandlerImpl.java index c0f10f3722..6d37c68602 100644 --- a/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthStoreHandlerImpl.java +++ b/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/OAuthStoreHandlerImpl.java @@ -25,7 +25,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.auth.client.oauth2.AccessTokenResponse; @@ -124,7 +123,7 @@ public class OAuthStoreHandlerImpl implements OAuthStoreHandler { } @Override - public void saveAccessTokenResponse(@NonNull String handle, @Nullable AccessTokenResponse pAccessTokenResponse) { + public void saveAccessTokenResponse(String handle, @Nullable AccessTokenResponse pAccessTokenResponse) { AccessTokenResponse accessTokenResponse = pAccessTokenResponse; if (accessTokenResponse == null) { accessTokenResponse = new AccessTokenResponse(); // put empty diff --git a/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/StorageRecordType.java b/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/StorageRecordType.java index f33f7b5118..52a7eac6da 100644 --- a/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/StorageRecordType.java +++ b/bundles/org.openhab.core.auth.oauth2client/src/main/java/org/openhab/core/auth/oauth2client/internal/StorageRecordType.java @@ -12,13 +12,15 @@ */ package org.openhab.core.auth.oauth2client.internal; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; /** * Enum of types being used in the store * * @author Gary Tse - Initial contribution */ +@NonNullByDefault public enum StorageRecordType { LAST_USED(".LastUsed"), @@ -31,7 +33,7 @@ public enum StorageRecordType { this.suffix = suffix; } - public @NonNull String getKey(String handle) { + public String getKey(@Nullable String handle) { return (handle == null) ? this.suffix : (handle + this.suffix); } diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineManagerImpl.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineManagerImpl.java index 122b28b3a2..184230e3d2 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineManagerImpl.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/ScriptEngineManagerImpl.java @@ -21,7 +21,6 @@ import javax.script.Invocable; import javax.script.ScriptEngine; import javax.script.ScriptException; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.automation.module.script.ScriptEngineContainer; @@ -112,7 +111,7 @@ public class ScriptEngineManagerImpl implements ScriptEngineManager { } @Override - public @Nullable ScriptEngineContainer createScriptEngine(String scriptType, @NonNull String engineIdentifier) { + public @Nullable ScriptEngineContainer createScriptEngine(String scriptType, String engineIdentifier) { ScriptEngineContainer result = null; ScriptEngineFactory engineFactory = findEngineFactory(scriptType); if (engineFactory == null) { diff --git a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/status/ConfigStatusSource.java b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/status/ConfigStatusSource.java index c1d05f7697..4fa3a4ea7b 100644 --- a/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/status/ConfigStatusSource.java +++ b/bundles/org.openhab.core.config.core/src/main/java/org/openhab/core/config/core/status/ConfigStatusSource.java @@ -12,7 +12,7 @@ */ package org.openhab.core.config.core.status; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; /** * The {@link ConfigStatusSource} represents a source which would like to propagate its new configuration status. It is @@ -20,6 +20,7 @@ import org.eclipse.jdt.annotation.NonNull; * * @author Thomas Höfer - Initial contribution */ +@NonNullByDefault public abstract class ConfigStatusSource { /** The id of the entity whose new configuration status is to be propagated. */ @@ -30,7 +31,7 @@ public abstract class ConfigStatusSource { * * @param entityId the id of the entity whose new configuration status is to be propagated */ - public ConfigStatusSource(@NonNull String entityId) { + public ConfigStatusSource(String entityId) { super(); this.entityId = entityId; } diff --git a/bundles/org.openhab.core.config.discovery.mdns/src/main/java/org/openhab/core/config/discovery/mdns/internal/MDNSDiscoveryService.java b/bundles/org.openhab.core.config.discovery.mdns/src/main/java/org/openhab/core/config/discovery/mdns/internal/MDNSDiscoveryService.java index 5b5d787378..7b9889a89e 100644 --- a/bundles/org.openhab.core.config.discovery.mdns/src/main/java/org/openhab/core/config/discovery/mdns/internal/MDNSDiscoveryService.java +++ b/bundles/org.openhab.core.config.discovery.mdns/src/main/java/org/openhab/core/config/discovery/mdns/internal/MDNSDiscoveryService.java @@ -23,7 +23,7 @@ import javax.jmdns.ServiceEvent; import javax.jmdns.ServiceInfo; import javax.jmdns.ServiceListener; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.config.discovery.AbstractDiscoveryService; import org.openhab.core.config.discovery.DiscoveryResult; @@ -32,7 +32,9 @@ import org.openhab.core.config.discovery.mdns.MDNSDiscoveryParticipant; import org.openhab.core.io.transport.mdns.MDNSClient; import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.ThingUID; +import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Modified; import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; @@ -48,6 +50,7 @@ import org.slf4j.LoggerFactory; * @author Kai Kreuzer - Improved startup behavior and background discovery * @author Andre Fuechsel - make {@link #startScan()} asynchronous */ +@NonNullByDefault @Component(immediate = true, service = DiscoveryService.class, configurationPid = "discovery.mdns") public class MDNSDiscoveryService extends AbstractDiscoveryService implements ServiceListener { @@ -59,15 +62,17 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se private final Set participants = new CopyOnWriteArraySet<>(); - private MDNSClient mdnsClient; + private final MDNSClient mdnsClient; - public MDNSDiscoveryService() { + @Activate + public MDNSDiscoveryService(final @Nullable Map configProperties, + final @Reference MDNSClient mdnsClient) { super(5); - } - @Reference - public void setMDNSClient(MDNSClient mdnsClient) { this.mdnsClient = mdnsClient; + + super.activate(configProperties); + if (isBackgroundDiscoveryEnabled()) { for (MDNSDiscoveryParticipant participant : participants) { mdnsClient.addServiceListener(participant.getServiceType(), this); @@ -78,19 +83,22 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se } } - public void unsetMDNSClient(MDNSClient mdnsClient) { + @Deactivate + @Override + protected void deactivate() { + super.deactivate(); + for (MDNSDiscoveryParticipant participant : participants) { mdnsClient.removeServiceListener(participant.getServiceType(), this); } for (org.openhab.core.io.transport.mdns.discovery.MDNSDiscoveryParticipant participant : oldParticipants) { mdnsClient.removeServiceListener(participant.getServiceType(), this); } - this.mdnsClient = null; } @Modified @Override - protected void modified(@Nullable Map<@NonNull String, @Nullable Object> configProperties) { + protected void modified(@Nullable Map configProperties) { super.modified(configProperties); } @@ -185,16 +193,14 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se @Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC) protected void addMDNSDiscoveryParticipant(MDNSDiscoveryParticipant participant) { this.participants.add(participant); - if (mdnsClient != null && isBackgroundDiscoveryEnabled()) { + if (isBackgroundDiscoveryEnabled()) { mdnsClient.addServiceListener(participant.getServiceType(), this); } } protected void removeMDNSDiscoveryParticipant(MDNSDiscoveryParticipant participant) { this.participants.remove(participant); - if (mdnsClient != null) { - mdnsClient.removeServiceListener(participant.getServiceType(), this); - } + mdnsClient.removeServiceListener(participant.getServiceType(), this); } @Deprecated @@ -202,7 +208,7 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se protected void addMDNSDiscoveryParticipant_old( org.openhab.core.io.transport.mdns.discovery.MDNSDiscoveryParticipant participant) { this.oldParticipants.add(participant); - if (mdnsClient != null && isBackgroundDiscoveryEnabled()) { + if (isBackgroundDiscoveryEnabled()) { mdnsClient.addServiceListener(participant.getServiceType(), this); } } @@ -211,9 +217,7 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se protected void removeMDNSDiscoveryParticipant_old( org.openhab.core.io.transport.mdns.discovery.MDNSDiscoveryParticipant participant) { this.oldParticipants.remove(participant); - if (mdnsClient != null) { - mdnsClient.removeServiceListener(participant.getServiceType(), this); - } + mdnsClient.removeServiceListener(participant.getServiceType(), this); } @Override @@ -229,12 +233,12 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se } @Override - public void serviceAdded(ServiceEvent serviceEvent) { + public void serviceAdded(@NonNullByDefault({}) ServiceEvent serviceEvent) { considerService(serviceEvent); } @Override - public void serviceRemoved(ServiceEvent serviceEvent) { + public void serviceRemoved(@NonNullByDefault({}) ServiceEvent serviceEvent) { for (MDNSDiscoveryParticipant participant : participants) { if (participant.getServiceType().equals(serviceEvent.getType())) { try { @@ -262,7 +266,7 @@ public class MDNSDiscoveryService extends AbstractDiscoveryService implements Se } @Override - public void serviceResolved(ServiceEvent serviceEvent) { + public void serviceResolved(@NonNullByDefault({}) ServiceEvent serviceEvent) { considerService(serviceEvent); } diff --git a/bundles/org.openhab.core.config.discovery.usbserial/src/main/java/org/openhab/core/config/discovery/usbserial/internal/UsbSerialDiscoveryService.java b/bundles/org.openhab.core.config.discovery.usbserial/src/main/java/org/openhab/core/config/discovery/usbserial/internal/UsbSerialDiscoveryService.java index 63aaee2e89..76eb23490a 100644 --- a/bundles/org.openhab.core.config.discovery.usbserial/src/main/java/org/openhab/core/config/discovery/usbserial/internal/UsbSerialDiscoveryService.java +++ b/bundles/org.openhab.core.config.discovery.usbserial/src/main/java/org/openhab/core/config/discovery/usbserial/internal/UsbSerialDiscoveryService.java @@ -19,7 +19,6 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.config.discovery.AbstractDiscoveryService; @@ -89,7 +88,7 @@ public class UsbSerialDiscoveryService extends AbstractDiscoveryService implemen @Modified @Override - protected void modified(@Nullable Map<@NonNull String, @Nullable Object> configProperties) { + protected void modified(@Nullable Map configProperties) { super.modified(configProperties); } diff --git a/bundles/org.openhab.core.io.rest.sse/src/main/java/org/openhab/core/io/rest/sse/SseResource.java b/bundles/org.openhab.core.io.rest.sse/src/main/java/org/openhab/core/io/rest/sse/SseResource.java index dea8c2a77d..f4a175a85f 100644 --- a/bundles/org.openhab.core.io.rest.sse/src/main/java/org/openhab/core/io/rest/sse/SseResource.java +++ b/bundles/org.openhab.core.io.rest.sse/src/main/java/org/openhab/core/io/rest/sse/SseResource.java @@ -158,7 +158,6 @@ public class SseResource { @ApiOperation(value = "Initiates a new item state tracker connection", response = EventOutput.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK") }) public Object getStateEvents() throws IOException, InterruptedException { - final SseStateEventOutput eventOutput = new SseStateEventOutput(); statesBroadcaster.add(eventOutput); @@ -186,7 +185,6 @@ public class SseResource { @ApiResponse(code = 404, message = "Unknown connectionId") }) public Object updateTrackedItems(@PathParam("connectionId") String connectionId, @ApiParam("items") Set itemNames) { - try { statesBroadcaster.updateTrackedItems(connectionId, itemNames); } catch (IllegalArgumentException e) { diff --git a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/HistoricItem.java b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/HistoricItem.java index 99dd1ffeb6..6cbd5d07e5 100644 --- a/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/HistoricItem.java +++ b/bundles/org.openhab.core.persistence/src/main/java/org/openhab/core/persistence/HistoricItem.java @@ -14,7 +14,7 @@ package org.openhab.core.persistence; import java.util.Date; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.items.Item; import org.openhab.core.types.State; @@ -28,6 +28,7 @@ import org.openhab.core.types.State; * * @author Kai Kreuzer - Initial contribution */ +@NonNullByDefault public interface HistoricItem { /** @@ -35,7 +36,6 @@ public interface HistoricItem { * * @return the timestamp of the item */ - @NonNull Date getTimestamp(); /** @@ -43,7 +43,6 @@ public interface HistoricItem { * * @return the current state */ - @NonNull State getState(); /** @@ -51,7 +50,6 @@ public interface HistoricItem { * * @return the name of the item */ - @NonNull String getName(); } diff --git a/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/handler/MagicThermostatThingHandler.java b/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/handler/MagicThermostatThingHandler.java index 1b8acaf125..f29f013abe 100644 --- a/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/handler/MagicThermostatThingHandler.java +++ b/bundles/org.openhab.core.test.magic/src/main/java/org/openhab/core/magic/binding/handler/MagicThermostatThingHandler.java @@ -16,7 +16,7 @@ import static org.openhab.core.magic.binding.MagicBindingConstants.*; import java.util.concurrent.TimeUnit; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.thing.ChannelUID; @@ -30,6 +30,7 @@ import org.openhab.core.types.Command; * * @author Henning Treu - Initial contribution */ +@NonNullByDefault public class MagicThermostatThingHandler extends BaseThingHandler { public MagicThermostatThingHandler(Thing thing) { @@ -37,7 +38,7 @@ public class MagicThermostatThingHandler extends BaseThingHandler { } @Override - public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) { + public void handleCommand(ChannelUID channelUID, Command command) { if (channelUID.getId().equals(CHANNEL_SET_TEMPERATURE)) { if (command instanceof DecimalType || command instanceof QuantityType) { String state = command.toFullString() + (command instanceof DecimalType ? " °C" : ""); diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/CommunicationManager.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/CommunicationManager.java index 05199078e6..189751dcd7 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/CommunicationManager.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/internal/CommunicationManager.java @@ -27,7 +27,6 @@ import java.util.function.Function; import javax.measure.Quantity; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.common.AbstractUID; @@ -650,12 +649,12 @@ public class CommunicationManager implements EventSubscriber, RegistryChangeList private static class NoOpProfile implements Profile { @Override - public @NonNull ProfileTypeUID getProfileTypeUID() { + public ProfileTypeUID getProfileTypeUID() { return new ProfileTypeUID(ProfileTypeUID.SYSTEM_SCOPE, "noop"); } @Override - public void onStateUpdateFromItem(@NonNull State state) { + public void onStateUpdateFromItem(State state) { // no-op } } diff --git a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/link/ItemChannelLinkRegistry.java b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/link/ItemChannelLinkRegistry.java index 48ae1eae0f..dad557c266 100644 --- a/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/link/ItemChannelLinkRegistry.java +++ b/bundles/org.openhab.core.thing/src/main/java/org/openhab/core/thing/link/ItemChannelLinkRegistry.java @@ -17,7 +17,6 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.events.EventPublisher; import org.openhab.core.items.Item; @@ -74,7 +73,7 @@ public class ItemChannelLinkRegistry extends AbstractLinkRegistry getLinkedItems(final UID uid) { - return ((Stream<@NonNull Item>) super.getLinkedItemNames(uid).parallelStream() + return ((Stream) super.getLinkedItemNames(uid).parallelStream() .map(itemName -> itemRegistry.get(itemName)).filter(Objects::nonNull)).collect(Collectors.toSet()); } @@ -85,7 +84,7 @@ public class ItemChannelLinkRegistry extends AbstractLinkRegistry getBoundThings(final String itemName) { - return ((Stream<@NonNull Thing>) getBoundChannels(itemName).parallelStream() + return ((Stream) getBoundChannels(itemName).parallelStream() .map(channelUID -> thingRegistry.get(channelUID.getThingUID())).filter(Objects::nonNull)) .collect(Collectors.toSet()); } diff --git a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ThingTypeBuilderTest.java b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ThingTypeBuilderTest.java index d8c2ac25f6..8be861e5f0 100644 --- a/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ThingTypeBuilderTest.java +++ b/bundles/org.openhab.core.thing/src/test/java/org/openhab/core/thing/type/ThingTypeBuilderTest.java @@ -24,7 +24,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.Before; import org.junit.Test; import org.openhab.core.thing.ThingTypeUID; @@ -34,6 +34,7 @@ import org.openhab.core.thing.ThingTypeUID; * * @author Henning Treu - Initial contribution */ +@NonNullByDefault public class ThingTypeBuilderTest { private static final String CONF_URI = "conf:uri"; @@ -44,7 +45,7 @@ public class ThingTypeBuilderTest { private static final String THING_TYPE_ID = "thingTypeId"; private static final String BINDING_ID = "bindingId"; - private ThingTypeBuilder builder; + private @NonNullByDefault({}) ThingTypeBuilder builder; @Before public void setup() { @@ -212,15 +213,15 @@ public class ThingTypeBuilderTest { assertThat(bridgeType.getLabel(), is(LABEL)); } - private Map<@NonNull String, String> mockProperties() { - Map<@NonNull String, String> result = new HashMap<>(); + private Map mockProperties() { + Map result = new HashMap<>(); result.put("key1", "value1"); result.put("key2", "value2"); return result; } - private @NonNull List mockList(Class entityClass, int size) { + private List mockList(Class entityClass, int size) { List result = new ArrayList<>(size); for (int i = 0; i < size; i++) { result.add(mock(entityClass)); diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentProvider.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentProvider.java index 176c71699c..2c68a18388 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentProvider.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentProvider.java @@ -17,7 +17,6 @@ import java.util.Collection; import java.util.List; import org.apache.commons.lang.StringUtils; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.common.registry.AbstractProvider; @@ -62,7 +61,7 @@ public class UIComponentProvider extends AbstractProvider } @Override - public void add(@NonNull RootUIComponent element) { + public void add(RootUIComponent element) { if (StringUtils.isEmpty(element.getUID())) { throw new IllegalArgumentException("Invalid UID"); } @@ -76,7 +75,7 @@ public class UIComponentProvider extends AbstractProvider } @Override - public @Nullable RootUIComponent remove(@NonNull String key) { + public @Nullable RootUIComponent remove(String key) { RootUIComponent element = storage.remove(key); if (element != null) { notifyListenersAboutRemovedElement(element); @@ -87,7 +86,7 @@ public class UIComponentProvider extends AbstractProvider } @Override - public @Nullable RootUIComponent update(@NonNull RootUIComponent element) { + public @Nullable RootUIComponent update(RootUIComponent element) { if (storage.get(element.getUID()) != null) { RootUIComponent oldElement = storage.put(element.getUID(), element); if (oldElement != null) { diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java index ef0ab7df52..4729e231da 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/components/UIComponentSitemapProvider.java @@ -13,13 +13,14 @@ package org.openhab.core.ui.internal.components; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; import org.eclipse.emf.common.util.EList; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.openhab.core.common.registry.RegistryChangeListener; import org.openhab.core.config.core.ConfigUtil; @@ -67,6 +68,7 @@ import org.slf4j.LoggerFactory; * * @author Yannick Schaus - Initial contribution */ +@NonNullByDefault @Component(service = SitemapProvider.class) public class UIComponentSitemapProvider implements SitemapProvider, RegistryChangeListener { private final Logger logger = LoggerFactory.getLogger(UIComponentSitemapProvider.class); @@ -77,21 +79,26 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan private static final String SITEMAP_SUFFIX = ".sitemap"; private Map sitemaps = new HashMap<>(); - private UIComponentRegistryFactory componentRegistryFactory; - private UIComponentRegistry sitemapComponentRegistry; + private @Nullable UIComponentRegistryFactory componentRegistryFactory; + private @Nullable UIComponentRegistry sitemapComponentRegistry; private final Set modelChangeListeners = new CopyOnWriteArraySet<>(); @Override - public @Nullable Sitemap getSitemap(@NonNull String sitemapName) { + public @Nullable Sitemap getSitemap(String sitemapName) { buildSitemap(sitemapName.replaceFirst(SITEMAP_PREFIX, "")); return sitemaps.get(sitemapName); } @Override - public @NonNull Set<@NonNull String> getSitemapNames() { + public Set getSitemapNames() { + UIComponentRegistry registry = sitemapComponentRegistry; + if (registry == null) { + return Collections.emptySet(); + } + sitemaps.clear(); - Collection rootComponents = sitemapComponentRegistry.getAll(); + Collection rootComponents = registry.getAll(); // try building all sitemaps to leave the invalid ones out for (RootUIComponent rootComponent : rootComponents) { try { @@ -105,8 +112,13 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan return sitemaps.keySet(); } - protected Sitemap buildSitemap(String sitemapName) { - RootUIComponent rootComponent = sitemapComponentRegistry.get(sitemapName); + protected @Nullable Sitemap buildSitemap(String sitemapName) { + UIComponentRegistry registry = sitemapComponentRegistry; + if (registry == null) { + return null; + } + + RootUIComponent rootComponent = registry.get(sitemapName); if (rootComponent != null) { try { Sitemap sitemap = buildSitemap(rootComponent); @@ -141,7 +153,7 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan return sitemap; } - protected Widget buildWidget(UIComponent component) { + protected @Nullable Widget buildWidget(UIComponent component) { Widget widget = null; switch (component.getType()) { @@ -261,8 +273,8 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan return widget; } - private void setWidgetPropertyFromComponentConfig(Widget widget, UIComponent component, String configParamName, - int feature) { + private void setWidgetPropertyFromComponentConfig(Widget widget, @Nullable UIComponent component, + String configParamName, int feature) { if (component == null || component.getConfig() == null) { return; } @@ -292,12 +304,12 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan } @Override - public void addModelChangeListener(@NonNull ModelRepositoryChangeListener listener) { + public void addModelChangeListener(ModelRepositoryChangeListener listener) { modelChangeListeners.add(listener); } @Override - public void removeModelChangeListener(@NonNull ModelRepositoryChangeListener listener) { + public void removeModelChangeListener(ModelRepositoryChangeListener listener) { modelChangeListeners.remove(listener); } @@ -330,8 +342,12 @@ public class UIComponentSitemapProvider implements SitemapProvider, RegistryChan } protected void unsetComponentRegistryFactory(UIComponentRegistryFactory componentRegistryFactory) { + UIComponentRegistry registry = this.sitemapComponentRegistry; + if (registry != null) { + registry.removeRegistryChangeListener(this); + } + this.componentRegistryFactory = null; - this.sitemapComponentRegistry.removeRegistryChangeListener(this); this.sitemapComponentRegistry = null; } } diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/tiles/TileService.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/tiles/TileService.java index daab0b2ce9..19b5160ae7 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/tiles/TileService.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/internal/tiles/TileService.java @@ -42,15 +42,15 @@ import org.slf4j.LoggerFactory; @Component(immediate = true, name = "org.openhab.core.ui.tiles") public class TileService implements TileProvider { - private static final Logger logger = LoggerFactory.getLogger(TileService.class); + private final Logger logger = LoggerFactory.getLogger(TileService.class); protected ConfigurationAdmin configurationAdmin; protected Set tiles = new CopyOnWriteArraySet<>(); - private final static String LINK_NAME = "link-name"; - private final static String LINK_URL = "link-url"; - private final static String LINK_IMAGEURL = "link-imageurl"; + private static final String LINK_NAME = "link-name"; + private static final String LINK_URL = "link-url"; + private static final String LINK_IMAGEURL = "link-imageurl"; @Activate protected void activate(ComponentContext componentContext, Map properties) { diff --git a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/tiles/ExternalServiceTile.java b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/tiles/ExternalServiceTile.java index bcef666dc9..5e078d12d1 100644 --- a/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/tiles/ExternalServiceTile.java +++ b/bundles/org.openhab.core.ui/src/main/java/org/openhab/core/ui/tiles/ExternalServiceTile.java @@ -53,11 +53,11 @@ public class ExternalServiceTile implements Tile { @Override public String toString() { - final int MAXLEN = 100; + final int maxlen = 100; String limitedImageUrl = imageUrl; - if (limitedImageUrl != null && limitedImageUrl.length() > MAXLEN) { - limitedImageUrl = imageUrl.substring(0, MAXLEN) + "..."; + if (limitedImageUrl != null && limitedImageUrl.length() > maxlen) { + limitedImageUrl = imageUrl.substring(0, maxlen) + "..."; } return "[name=" + name + ", url=" + url + ", overlay=" + overlay + ", imageUrl=" + limitedImageUrl + "]"; diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/GenericUser.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/GenericUser.java index e302e980e2..f0a0ef89b7 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/GenericUser.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/GenericUser.java @@ -15,7 +15,6 @@ package org.openhab.core.auth; import java.util.HashSet; import java.util.Set; -import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNullByDefault; /** @@ -56,7 +55,7 @@ public class GenericUser implements User { } @Override - public @NonNull String getUID() { + public String getUID() { return name; } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/UserRegistry.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/UserRegistry.java index 2973551456..6a49b24303 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/UserRegistry.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/auth/UserRegistry.java @@ -35,7 +35,6 @@ public interface UserRegistry extends Registry, AuthenticationProv * @param username the username of the new user * @param password the user password * @param roles the roles attributed to the new user - * * @return the new registered {@link User} instance */ public User register(String username, String password, Set roles); diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/MetadataCommandDescriptionProvider.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/MetadataCommandDescriptionProvider.java index 10ff49a006..26b3e6d5a9 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/MetadataCommandDescriptionProvider.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/MetadataCommandDescriptionProvider.java @@ -16,7 +16,6 @@ import java.util.Locale; import java.util.Map; 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.internal.types.CommandDescriptionImpl; @@ -55,7 +54,7 @@ public class MetadataCommandDescriptionProvider implements CommandDescriptionPro } @Override - public @Nullable CommandDescription getCommandDescription(@NonNull String itemName, @Nullable Locale locale) { + public @Nullable CommandDescription getCommandDescription(String itemName, @Nullable Locale locale) { Metadata metadata = metadataRegistry.get(new MetadataKey(COMMANDDESCRIPTION_METADATA_NAMESPACE, itemName)); if (metadata != null) { diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProvider.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProvider.java index dcb6ff6b21..0b45167588 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProvider.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/internal/items/MetadataStateDescriptionFragmentProvider.java @@ -20,7 +20,6 @@ import java.util.Map; import java.util.stream.Collectors; 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.items.Metadata; @@ -69,8 +68,7 @@ public class MetadataStateDescriptionFragmentProvider implements StateDescriptio } @Override - public @Nullable StateDescriptionFragment getStateDescriptionFragment(@NonNull String itemName, - @Nullable Locale locale) { + public @Nullable StateDescriptionFragment getStateDescriptionFragment(String itemName, @Nullable Locale locale) { Metadata metadata = metadataRegistry.get(new MetadataKey(STATEDESCRIPTION_METADATA_NAMESPACE, itemName)); if (metadata != null) { @@ -145,7 +143,7 @@ public class MetadataStateDescriptionFragmentProvider implements StateDescriptio } @Override - public @NonNull Integer getRank() { + public Integer getRank() { return rank; } } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/StringListType.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/StringListType.java index d9249f230f..87c45928fb 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/StringListType.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/library/types/StringListType.java @@ -33,7 +33,7 @@ import org.openhab.core.types.State; @NonNullByDefault public class StringListType implements Command, State { - final protected List typeDetails; + protected final List typeDetails; // constants public static final String DELIMITER = ","; diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java index 1398e67325..fc54649594 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java @@ -21,7 +21,7 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.openhab.core.events.EventPublisher; @@ -45,6 +45,7 @@ import org.openhab.core.types.StateOption; * @author Christoph Knauf - Initial contribution, event tests * @author Simon Kaufmann - migrated from Groovy to Java */ +@NonNullByDefault @SuppressWarnings("null") public class GenericItemTest { @@ -150,7 +151,7 @@ public class GenericItemTest { when(commandDescriptionService.getCommandDescription("test", null)).thenReturn(new CommandDescription() { @Override - public @NonNull List<@NonNull CommandOption> getCommandOptions() { + public List getCommandOptions() { return Arrays.asList(new CommandOption("ALERT", "Alert"), new CommandOption("REBOOT", "Reboot")); } }); @@ -168,7 +169,7 @@ public class GenericItemTest { .thenReturn(new CommandDescription() { @Override - public @NonNull List<@NonNull CommandOption> getCommandOptions() { + public List getCommandOptions() { return Arrays.asList(new CommandOption("C1", "Command 1"), new CommandOption("C2", "Command 2"), new CommandOption("C3", "Command 3")); } @@ -183,7 +184,7 @@ public class GenericItemTest { TestItem item = new TestItem("test"); StateDescriptionService stateDescriptionService = mock(StateDescriptionService.class); - List<@NonNull StateOption> stateOptions = Arrays.asList(new StateOption("STATE1", "State 1"), + List stateOptions = Arrays.asList(new StateOption("STATE1", "State 1"), new StateOption("STATE2", "State 2")); when(stateDescriptionService.getStateDescription("test", null)).thenReturn( StateDescriptionFragmentBuilder.create().withOptions(stateOptions).build().toStateDescription()); diff --git a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/event/RuleEventTest.java b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/event/RuleEventTest.java index f4d3607c44..340afc9789 100644 --- a/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/event/RuleEventTest.java +++ b/itests/org.openhab.core.automation.tests/src/main/java/org/openhab/core/automation/event/RuleEventTest.java @@ -27,7 +27,8 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.junit.Before; import org.junit.Test; import org.openhab.core.automation.Action; @@ -57,7 +58,6 @@ import org.openhab.core.items.events.ItemEventFactory; import org.openhab.core.library.items.SwitchItem; import org.openhab.core.library.types.OnOffType; import org.openhab.core.test.java.JavaOSGiTest; -import org.openhab.core.test.storage.VolatileStorageService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,13 +67,13 @@ import org.slf4j.LoggerFactory; * @author Benedikt Niehues - Initial contribution * @author Kai Kreuzer - ported test to Java */ +@NonNullByDefault public class RuleEventTest extends JavaOSGiTest { - final Logger logger = LoggerFactory.getLogger(RuleEventTest.class); - VolatileStorageService volatileStorageService = new VolatileStorageService(); + private final Logger logger = LoggerFactory.getLogger(RuleEventTest.class); - Event itemEvent = null; - Event ruleRemovedEvent = null; + private @Nullable Event itemEvent = null; + private @Nullable Event ruleRemovedEvent = null; public RuleEventTest() { } @@ -87,7 +87,7 @@ public class RuleEventTest extends JavaOSGiTest { } @Override - public @NonNull Collection<@NonNull Item> getAll() { + public Collection getAll() { return Arrays.asList(new Item[] { new SwitchItem("myMotionItem"), new SwitchItem("myPresenceItem"), new SwitchItem("myLampItem"), new SwitchItem("myMotionItem2"), new SwitchItem("myPresenceItem2"), new SwitchItem("myLampItem2") }); @@ -118,7 +118,7 @@ public class RuleEventTest extends JavaOSGiTest { } @Override - public EventFilter getEventFilter() { + public @Nullable EventFilter getEventFilter() { return null; } @@ -186,7 +186,7 @@ public class RuleEventTest extends JavaOSGiTest { } @Override - public EventFilter getEventFilter() { + public @Nullable EventFilter getEventFilter() { return null; } }; @@ -215,7 +215,7 @@ public class RuleEventTest extends JavaOSGiTest { } @Override - public EventFilter getEventFilter() { + public @Nullable EventFilter getEventFilter() { return null; } diff --git a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/inbox/DynamicThingUpdateOSGiTest.java b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/inbox/DynamicThingUpdateOSGiTest.java index 413c558581..0b9d4b3ce6 100644 --- a/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/inbox/DynamicThingUpdateOSGiTest.java +++ b/itests/org.openhab.core.config.discovery.tests/src/main/java/org/openhab/core/config/discovery/inbox/DynamicThingUpdateOSGiTest.java @@ -18,7 +18,7 @@ import static org.mockito.Mockito.*; import java.util.Collections; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.junit.Before; import org.junit.Test; @@ -57,6 +57,7 @@ import org.openhab.core.thing.type.ThingTypeBuilder; * @author Andre Fuechsel - Added tests for device id * @author Simon Kaufmann - ported to Java */ +@NonNullByDefault public class DynamicThingUpdateOSGiTest extends JavaOSGiTest { private static final int DEFAULT_TTL = 60; @@ -73,11 +74,11 @@ public class DynamicThingUpdateOSGiTest extends JavaOSGiTest { private static final ThingType THING_TYPE = ThingTypeBuilder.instance(THING_TYPE_UID, "label") .withRepresentationProperty(DEVICE_ID_KEY).isListed(true).build(); - private Inbox inbox; - private ManagedThingProvider managedThingProvider; - private ThingHandler thingHandler; + private @NonNullByDefault({}) Inbox inbox; + private @NonNullByDefault({}) ManagedThingProvider managedThingProvider; + private @NonNullByDefault({}) ThingHandler thingHandler; - private volatile ThingHandlerCallback callback; + private volatile @NonNullByDefault({}) ThingHandlerCallback callback; @Before public void setUp() { @@ -110,12 +111,12 @@ public class DynamicThingUpdateOSGiTest extends JavaOSGiTest { ThingHandlerFactory thingHandlerFactory = new BaseThingHandlerFactory() { @Override - public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) { + public boolean supportsThingType(ThingTypeUID thingTypeUID) { return THING_TYPE_UID.equals(thingTypeUID); } @Override - protected @Nullable ThingHandler createHandler(@NonNull Thing thing) { + protected @Nullable ThingHandler createHandler(Thing thing) { thingHandler = createThingHandler(thing); return thingHandler; } diff --git a/itests/org.openhab.core.ephemeris.tests/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImplOSGiTest.java b/itests/org.openhab.core.ephemeris.tests/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImplOSGiTest.java index 0a9e0d9936..476011adf9 100644 --- a/itests/org.openhab.core.ephemeris.tests/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImplOSGiTest.java +++ b/itests/org.openhab.core.ephemeris.tests/src/main/java/org/openhab/core/ephemeris/internal/EphemerisManagerImplOSGiTest.java @@ -295,7 +295,6 @@ public class EphemerisManagerImplOSGiTest extends JavaOSGiTest { delay = ephemerisManager.getDaysUntil(today, next); assertEquals(4, delay); } - } @Test diff --git a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/items/ItemUpdaterOSGiTest.java b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/items/ItemUpdaterOSGiTest.java index 009ee5a8a5..2af7054f98 100644 --- a/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/items/ItemUpdaterOSGiTest.java +++ b/itests/org.openhab.core.tests/src/main/java/org/openhab/core/internal/items/ItemUpdaterOSGiTest.java @@ -18,7 +18,7 @@ import java.util.Collections; import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.junit.Before; import org.junit.Test; @@ -41,10 +41,11 @@ import org.openhab.core.test.java.JavaOSGiTest; * @author Andre Fuechsel - extended with tag tests * @author Kai Kreuzer - added tests for all items changed cases */ +@NonNullByDefault public class ItemUpdaterOSGiTest extends JavaOSGiTest { - private EventPublisher eventPublisher; - private ItemRegistry itemRegistry; + private @NonNullByDefault({}) EventPublisher eventPublisher; + private @NonNullByDefault({}) ItemRegistry itemRegistry; private final ConcurrentLinkedQueue receivedEvents = new ConcurrentLinkedQueue<>(); @Before @@ -60,12 +61,12 @@ public class ItemUpdaterOSGiTest extends JavaOSGiTest { EventSubscriber eventSubscriber = new EventSubscriber() { @Override - public void receive(@NonNull Event event) { + public void receive(Event event) { receivedEvents.add(event); } @Override - public @NonNull Set<@NonNull String> getSubscribedEventTypes() { + public Set getSubscribedEventTypes() { return Collections.singleton(ItemStateChangedEvent.TYPE); } diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java index fb6fde6332..f37663707d 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ChannelStateDescriptionProviderOSGiTest.java @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.List; import java.util.Locale; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.junit.After; import org.junit.Before; @@ -84,19 +85,20 @@ import org.osgi.service.component.ComponentContext; * @author Thomas Höfer - Thing type constructor modified because of thing properties introduction * @author Markus Rathgeb - Migrated from Groovy to plain Java */ +@NonNullByDefault public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest { private static final String TEST_BUNDLE_NAME = "thingStatusInfoI18nTest.bundle"; private static final ChannelTypeUID CHANNEL_TYPE_7_UID = new ChannelTypeUID("hue:num-dynamic"); - private ThingStatusInfoI18nLocalizationService thingStatusInfoI18nLocalizationService; - private ItemRegistry itemRegistry; - private ItemChannelLinkRegistry linkRegistry; + private @NonNullByDefault({}) ThingStatusInfoI18nLocalizationService thingStatusInfoI18nLocalizationService; + private @NonNullByDefault({}) ItemRegistry itemRegistry; + private @NonNullByDefault({}) ItemChannelLinkRegistry linkRegistry; @Mock - private ComponentContext componentContext; + private @NonNullByDefault({}) ComponentContext componentContext; - private Bundle testBundle; + private @NonNullByDefault({}) Bundle testBundle; @Before public void setup() throws Exception { @@ -145,12 +147,12 @@ public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest { registerService(new ChannelTypeProvider() { @Override - public Collection getChannelTypes(Locale locale) { + public Collection getChannelTypes(@Nullable Locale locale) { return channelTypes; } @Override - public ChannelType getChannelType(ChannelTypeUID channelTypeUID, Locale locale) { + public @Nullable ChannelType getChannelType(ChannelTypeUID channelTypeUID, @Nullable Locale locale) { for (final ChannelType channelType : channelTypes) { if (channelType.getUID().equals(channelTypeUID)) { return channelType; @@ -405,9 +407,9 @@ public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest { * Helper */ class TestDynamicStateDescriptionProvider extends BaseDynamicStateDescriptionProvider { - final StateDescription newState = StateDescriptionFragmentBuilder.create().withMinimum(BigDecimal.valueOf(10)) - .withMaximum(BigDecimal.valueOf(100)).withStep(BigDecimal.valueOf(5)).withPattern("VALUE %d") - .withReadOnly(false) + final @Nullable StateDescription newState = StateDescriptionFragmentBuilder.create() + .withMinimum(BigDecimal.valueOf(10)).withMaximum(BigDecimal.valueOf(100)) + .withStep(BigDecimal.valueOf(5)).withPattern("VALUE %d").withReadOnly(false) .withOptions(Arrays.asList(new StateOption("value0", "label0"), new StateOption("value1", "label1"))) .build().toStateDescription(); @@ -454,7 +456,7 @@ public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest { } @Override - protected ThingHandler createHandler(Thing thing) { + protected @Nullable ThingHandler createHandler(Thing thing) { return new AbstractThingHandler(thing) { @Override public void handleCommand(ChannelUID channelUID, Command command) { @@ -502,7 +504,7 @@ public class ChannelStateDescriptionProviderOSGiTest extends JavaOSGiTest { */ private class BundleResolverImpl implements BundleResolver { @Override - public Bundle resolveBundle(Class clazz) { + public Bundle resolveBundle(@Nullable Class clazz) { if (clazz != null && clazz.equals(AbstractThingHandler.class)) { return testBundle; } else { diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java index e0c15d297a..0077bc6f8d 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingManagerOSGiJavaTest.java @@ -26,7 +26,7 @@ import java.util.concurrent.Semaphore; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.junit.After; import org.junit.Before; @@ -93,20 +93,14 @@ import org.osgi.service.component.ComponentContext; * @author Simon Kaufmann - Initial contribution * @author Christoph Weitkamp - Added preconfigured ChannelGroupBuilder */ +@NonNullByDefault public class ThingManagerOSGiJavaTest extends JavaOSGiTest { - private ManagedThingProvider managedThingProvider; - private ItemRegistry itemRegistry; - private ThingRegistry thingRegistry; - private ReadyService readyService; - private ItemChannelLinkRegistry itemChannelLinkRegistry; - private ThingManager thingManager; - private static final String CONFIG_PARAM_NAME = "test"; private static final String BINDING_ID = "binding"; - private static final String CHANNEL_ID = "channel"; + private static final ChannelTypeUID CHANNEL_TYPE_UID = new ChannelTypeUID(BINDING_ID, CHANNEL_ID); private static final String CHANNEL_GROUP_ID = "channel-group"; @@ -123,16 +117,22 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { private static final ChannelGroupUID CHANNEL_GROUP_UID = new ChannelGroupUID(THING_UID, CHANNEL_GROUP_ID); - private Thing thing; - private URI configDescriptionThing; - private URI configDescriptionChannel; + private @NonNullByDefault({}) ItemChannelLinkRegistry itemChannelLinkRegistry; + private @NonNullByDefault({}) ItemRegistry itemRegistry; + private @NonNullByDefault({}) ManagedThingProvider managedThingProvider; + private @NonNullByDefault({}) ThingRegistry thingRegistry; + private @NonNullByDefault({}) ReadyService readyService; + private @NonNullByDefault({}) Storage storage; + private @NonNullByDefault({}) ThingManager thingManager; - private Storage storage; + private @NonNullByDefault({}) URI configDescriptionChannel; + private @NonNullByDefault({}) URI configDescriptionThing; + private @NonNullByDefault({}) Thing thing; @Before public void setUp() throws Exception { - configDescriptionThing = new URI("test:test"); configDescriptionChannel = new URI("test:channel"); + configDescriptionThing = new URI("test:test"); thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(Collections.singletonList( // ChannelBuilder.create(CHANNEL_UID, "Switch").withLabel("Test Label").withDescription("Test Description") .withType(CHANNEL_TYPE_UID).withDefaultTags(Collections.singleton("Test Tag")).build() // @@ -320,7 +320,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { registerChannelTypeProvider(); registerThingHandlerFactory(THING_TYPE_UID, thing -> new BaseThingHandler(thing) { @Override - public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) { + public void handleCommand(ChannelUID channelUID, Command command) { } }); @@ -354,7 +354,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { registerThingHandlerFactory(BRIDGE_TYPE_UID, bridge -> new BaseBridgeHandler((Bridge) bridge) { @Override - public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) { + public void handleCommand(ChannelUID channelUID, Command command) { } @Override @@ -373,7 +373,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { }); registerThingHandlerFactory(THING_TYPE_UID, thing -> new BaseThingHandler(thing) { @Override - public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) { + public void handleCommand(ChannelUID channelUID, Command command) { } @Override @@ -430,7 +430,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { registerThingHandlerFactory(BRIDGE_TYPE_UID, bridge -> new BaseBridgeHandler((Bridge) bridge) { @Override - public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) { + public void handleCommand(ChannelUID channelUID, Command command) { } @Override @@ -449,7 +449,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { }); registerThingHandlerFactory(THING_TYPE_UID, thing -> new BaseThingHandler(thing) { @Override - public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) { + public void handleCommand(ChannelUID channelUID, Command command) { } @Override @@ -506,7 +506,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { registerThingHandlerFactory(BRIDGE_TYPE_UID, bridge -> new BaseBridgeHandler((Bridge) bridge) { @Override - public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) { + public void handleCommand(ChannelUID channelUID, Command command) { } @Override @@ -525,7 +525,7 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { }); registerThingHandlerFactory(THING_TYPE_UID, thing -> new BaseThingHandler(thing) { @Override - public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) { + public void handleCommand(ChannelUID channelUID, Command command) { } @Override @@ -1062,12 +1062,12 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { } @Override - public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) { + public boolean supportsThingType(ThingTypeUID thingTypeUID) { return this.thingTypeUID.equals(thingTypeUID); } @Override - protected @Nullable ThingHandler createHandler(@NonNull Thing thing) { + protected @Nullable ThingHandler createHandler(Thing thing) { return thingHandlerProducer.apply(thing); } }; @@ -1079,12 +1079,12 @@ public class ThingManagerOSGiJavaTest extends JavaOSGiTest { AtomicReference thc = new AtomicReference<>(); ThingHandlerFactory thingHandlerFactory = new BaseThingHandlerFactory() { @Override - public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) { + public boolean supportsThingType(ThingTypeUID thingTypeUID) { return true; } @Override - protected @Nullable ThingHandler createHandler(@NonNull Thing thing) { + protected @Nullable ThingHandler createHandler(Thing thing) { ThingHandler mockHandler = mock(ThingHandler.class); doAnswer(a -> { thc.set((ThingHandlerCallback) a.getArguments()[0]); diff --git a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingRegistryOSGiTest.java b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingRegistryOSGiTest.java index 2bc5b8cd93..fa095d7968 100644 --- a/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingRegistryOSGiTest.java +++ b/itests/org.openhab.core.thing.tests/src/main/java/org/openhab/core/thing/internal/ThingRegistryOSGiTest.java @@ -23,7 +23,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; -import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.junit.After; import org.junit.Before; @@ -58,10 +58,11 @@ import org.osgi.framework.ServiceRegistration; * @author Stefan Bußweiler - Initial contribution * @author Kai Kreuzer - Moved createThing test from managed provider */ +@NonNullByDefault public class ThingRegistryOSGiTest extends JavaOSGiTest { - ManagedThingProvider managedThingProvider; - ServiceRegistration thingHandlerFactoryServiceReg; + private @NonNullByDefault({}) ManagedThingProvider managedThingProvider; + private @NonNullByDefault({}) ServiceRegistration thingHandlerFactoryServiceReg; private static final ThingTypeUID THING_TYPE_UID = new ThingTypeUID("binding:type"); private static final ThingUID THING_UID = new ThingUID(THING_TYPE_UID, "id"); @@ -69,8 +70,8 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest { private static final String THING1_ID = "testThing1"; private static final String THING2_ID = "testThing2"; - Map<@NonNull String, @NonNull Object> changedParameters = null; - Event receivedEvent = null; + private @Nullable Map changedParameters = null; + private @Nullable Event receivedEvent = null; @Before public void setUp() { @@ -99,7 +100,7 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest { } @Override - public EventFilter getEventFilter() { + public @Nullable EventFilter getEventFilter() { return null; } @@ -143,12 +144,11 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest { ThingHandler thingHandler = new BaseThingHandler(thing) { @Override - public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) { + public void handleCommand(ChannelUID channelUID, Command command) { } @Override - public void handleConfigurationUpdate( - @NonNull Map<@NonNull String, @NonNull Object> configurationParameters) { + public void handleConfigurationUpdate(Map configurationParameters) { changedParameters = configurationParameters; } }; @@ -158,16 +158,16 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest { ThingProvider thingProvider = new ThingProvider() { @Override - public void addProviderChangeListener(ProviderChangeListener<@NonNull Thing> listener) { + public void addProviderChangeListener(ProviderChangeListener listener) { } @Override - public Collection<@NonNull Thing> getAll() { + public Collection getAll() { return Collections.singleton(thing); } @Override - public void removeProviderChangeListener(ProviderChangeListener<@NonNull Thing> listener) { + public void removeProviderChangeListener(ProviderChangeListener listener) { } }; @@ -208,17 +208,17 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest { ThingHandlerFactory thingHandlerFactory = new BaseThingHandlerFactory() { @Override - public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) { + public boolean supportsThingType(ThingTypeUID thingTypeUID) { return true; } @Override - protected @Nullable ThingHandler createHandler(@NonNull Thing thing) { + protected @Nullable ThingHandler createHandler(Thing thing) { return null; } @Override - public @Nullable Thing createThing(@NonNull ThingTypeUID thingTypeUID, @NonNull Configuration configuration, + public @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) { assertThat(thingTypeUID, is(expectedThingTypeUID)); assertThat(configuration, is(expectedConfiguration)); @@ -237,7 +237,11 @@ public class ThingRegistryOSGiTest extends JavaOSGiTest { waitForAssert(() -> { assertTrue(thingResultWrapper.get() != null); }); - assertThat(thing, is(thingResultWrapper.get())); + + assertThat(thing, is(notNullValue())); + if (thing != null) { + assertThat(thing, is(thingResultWrapper.get())); + } } private void registerThingHandlerFactory(ThingHandlerFactory thingHandlerFactory) {