Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

add some nullness annotations #4080

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bundle-Name: Eclipse SmartHome Automation API
Bundle-SymbolicName: org.eclipse.smarthome.automation.api
Bundle-Version: 0.9.0.qualifier
Bundle-Vendor: Eclipse.org/SmartHome
Import-Package:
Import-Package: org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.automation,
org.eclipse.smarthome.automation.dto,
org.eclipse.smarthome.automation.events,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package org.eclipse.smarthome.automation;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.common.registry.DefaultAbstractManagedProvider;

/**
Expand All @@ -24,7 +25,7 @@ protected String getStorageName() {
}

@Override
protected String keyToString(String key) {
protected @NonNull String keyToString(@NonNull String key) {
return key;
}

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

import java.util.Map;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.automation.Action;
import org.eclipse.smarthome.automation.Rule;

Expand All @@ -31,6 +32,7 @@ public interface ActionHandler extends ModuleHandler {
* in form: ModuleId.outputId
* @return values map of values which must be set to outputs of the {@link Action} (may be null).
*/
public Map<String, Object> execute(Map<String, Object> context);
@Nullable
Map<String, Object> execute(Map<String, Object> context);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.HashMap;
import java.util.Map;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.automation.Module;
import org.osgi.framework.BundleContext;

Expand Down Expand Up @@ -59,7 +60,7 @@ public ModuleHandler getHandler(Module module, String ruleUID) {
* @param ruleUID the id of the rule for which the handler should be created
* @return A {@link ModuleHandler} instance or <code>null</code> if thins module type is not supported
*/
abstract protected ModuleHandler internalCreate(Module module, String ruleUID);
abstract protected @Nullable ModuleHandler internalCreate(Module module, String ruleUID);

public void dispose() {
for (ModuleHandler handler : handlers.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ protected void removeModuleHandlerFactory(ModuleHandlerFactory moduleHandlerFact
* when a module id contains dot or when the rule with the same UID already exists.
*/
@Override
public Rule add(Rule rule) {
public @NonNull Rule add(@NonNull Rule rule) {
String rUID = rule.getUID();
if (rUID == null) {
rUID = ruleEngine.getUniqueId();
Expand Down Expand Up @@ -517,7 +517,7 @@ protected void addProvider(Provider<Rule> provider) {
}

@Override
public void added(Provider<Rule> provider, Rule element) {
public void added(Provider<Rule> provider, @NonNull Rule element) {
Rule ruleWithUID = element;
if (element.getUID() == null) {
String rUID = ruleEngine.getUniqueId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Bundle-Name: Eclipse SmartHome Automation Module Core
Bundle-SymbolicName: org.eclipse.smarthome.automation.module.core
Bundle-Version: 0.9.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.eclipse.smarthome.automation,
Import-Package: org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.automation,
org.eclipse.smarthome.automation.handler,
org.eclipse.smarthome.automation.module.core.factory,
org.eclipse.smarthome.automation.module.core.handler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ public boolean containsValue(Object value) {

@Override
public State get(Object key) {
return itemRegistry.get((String) key).getState();
final Item item = itemRegistry.get((String) key);
if (item != null) {
return item.getState();
} else {
return null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Bundle-Version: 0.9.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.google.common.base,
javax.script,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.automation,
org.eclipse.smarthome.automation.handler,
org.eclipse.smarthome.automation.module.script,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Bundle-Version: 0.9.0.qualifier
Bundle-Activator: org.eclipse.smarthome.automation.module.timer.internal.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.google.common.collect,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.automation,
org.eclipse.smarthome.automation.handler,
org.eclipse.smarthome.automation.module.timer.factory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Bundle-Version: 0.9.0.qualifier
Bundle-Vendor: Eclipse.org/SmartHome
Import-Package:
org.apache.commons.lang,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.automation,
org.eclipse.smarthome.automation.handler,
org.eclipse.smarthome.automation.template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Bundle-Version: 0.9.0.qualifier
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Name: Automation Sample JSON
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package:
Import-Package: org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.automation,
org.eclipse.smarthome.automation.handler,
org.eclipse.smarthome.automation.parser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.Collection;
import java.util.Locale;

import org.eclipse.jdt.annotation.Nullable;

/**
* The {@link ConfigDescriptionProvider} can be implemented and registered as an <i>OSGi</i>
* service to provide {@link ConfigDescription}s. The {@link ConfigDescriptionRegistry} tracks
Expand Down Expand Up @@ -42,6 +44,7 @@ public interface ConfigDescriptionProvider {
* @return config description or null if no config description could be
* found
*/
@Nullable
ConfigDescription getConfigDescription(URI uri, Locale locale);

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Import-Package: javax.servlet,
javax.servlet.http,
org.apache.commons.io,
org.apache.commons.lang,
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.config.core,
org.eclipse.smarthome.core.audio,
org.eclipse.smarthome.core.audio.utils,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Locale;
import java.util.Set;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.core.library.types.PercentType;

/**
Expand All @@ -20,7 +21,7 @@
* @author Harald Kuhn - Initial API
* @author Kelly Davis - Modified to match discussion in #584
* @author Christoph Weitkamp - Added getSupportedStreams() and UnsupportedAudioStreamException
*
*
*/
public interface AudioSink {

Expand Down Expand Up @@ -65,7 +66,7 @@ public interface AudioSink {

/**
* Gets a set containing all supported audio stream formats
*
*
* @return A Set containing all supported audio stream formats
*/
public Set<Class<? extends AudioStream>> getSupportedStreams();
Expand All @@ -84,5 +85,5 @@ public interface AudioSink {
* @param volume a PercentType value between 0 and 100 representing the desired volume
* @throws IOException if the volume can not be set
*/
public void setVolume(PercentType volume) throws IOException;
public void setVolume(@NonNull PercentType volume) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import java.util.Date;

import org.eclipse.jdt.annotation.Nullable;

/**
* This class provides information about an item that is stored in a persistence service.
* It is used to return information about the item to the system
Expand All @@ -34,6 +36,7 @@ public interface PersistenceItemInfo {
*
* @return count of the number of rows of data. May return null if the persistence service doesn't support this.
*/
@Nullable
Integer getCount();

/**
Expand All @@ -42,6 +45,7 @@ public interface PersistenceItemInfo {
* @return the earliest {@link Date} stored in the database. May return null if the persistence service doesn't
* support this.
*/
@Nullable
Date getEarliest();

/**
Expand All @@ -50,5 +54,6 @@ public interface PersistenceItemInfo {
* @return the latest {@link Date} stored in the database. May return null if the persistence service doesn't
* support this.
*/
@Nullable
Date getLatest();
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public ThingHandler registerHandler(Thing thing) {
* @param thing the thing
* @return thing the created handler
*/
protected abstract ThingHandler createHandler(Thing thing);
protected abstract @Nullable ThingHandler createHandler(@NonNull Thing thing);

private void setHandlerContext(ThingHandler thingHandler) {
if (thingHandler instanceof BaseThingHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,21 @@ public interface ThingTypeProvider {
/**
* Provides a collection of thing types
*
* @param locale
* locale (can be null)
*
* @param locale locale (can be null)
* @return the thing types provided by the {@link ThingTypeProvider}
*/
Collection<ThingType> getThingTypes(Locale locale);
Collection<ThingType> getThingTypes(@Nullable Locale locale);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we agree on that we only want to state if a parameter is NonNull and if if can be null we omit the @Nullable annotation?


/**
* Provides a thing type for the given UID or null if no type for the
* given UID exists.
*
* @param locale
* locale (can be null)
* @param thingTypeUID the thing type UID
* @param locale locale (can be null)
* @return thing type for the given UID or null if no type for the given
* UID exists
*/
@Nullable
ThingType getThingType(ThingTypeUID thingTypeUID, Locale locale);
ThingType getThingType(ThingTypeUID thingTypeUID, @Nullable Locale locale);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we agree on that we only want to state if a parameter is NonNull and if if can be null we omit the @Nullable annotation?


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.Locale;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.i18n.TranslationProvider;
import org.eclipse.smarthome.core.thing.type.BridgeType;
import org.eclipse.smarthome.core.thing.type.ChannelDefinition;
Expand Down Expand Up @@ -43,7 +44,7 @@ protected void unsetTranslationProvider(TranslationProvider i18nProvider) {
this.thingTypeI18nUtil = null;
}

public ThingType createLocalizedThingType(Bundle bundle, ThingType thingType, Locale locale) {
public ThingType createLocalizedThingType(Bundle bundle, ThingType thingType, @Nullable Locale locale) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we agree on that we only want to state if a parameter is NonNull and if if can be null we omit the @Nullable annotation?

final String label = this.thingTypeI18nUtil.getLabel(bundle, thingType.getUID(), thingType.getLabel(), locale);
final String description = this.thingTypeI18nUtil.getDescription(bundle, thingType.getUID(),
thingType.getDescription(), locale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.List;
import java.util.Map;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.thing.Bridge;
import org.eclipse.smarthome.core.thing.ThingTypeUID;

Expand Down Expand Up @@ -63,9 +65,10 @@ public BridgeType(String bindingId, String thingTypeId, String label) throws Ill
* @throws IllegalArgumentException if the UID is null or empty,
* or the the meta information is null
*/
public BridgeType(ThingTypeUID uid, List<String> supportedBridgeTypeUIDs, String label, String description,
List<ChannelDefinition> channelDefinitions, List<ChannelGroupDefinition> channelGroupDefinitions,
Map<String, String> properties, URI configDescriptionURI) throws IllegalArgumentException {
public BridgeType(@NonNull ThingTypeUID uid, @Nullable List<String> supportedBridgeTypeUIDs, @NonNull String label,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we agree on that we only want to state if a parameter is NonNull and if if can be null we omit the @Nullable annotation?

@Nullable String description, @Nullable List<ChannelDefinition> channelDefinitions,
@Nullable List<ChannelGroupDefinition> channelGroupDefinitions, @Nullable Map<String, String> properties,
@Nullable URI configDescriptionURI) throws IllegalArgumentException {

this(uid, supportedBridgeTypeUIDs, label, description, true, null, channelDefinitions, channelGroupDefinitions,
properties, configDescriptionURI);
Expand Down Expand Up @@ -100,10 +103,10 @@ public BridgeType(ThingTypeUID uid, List<String> supportedBridgeTypeUIDs, String
* @throws IllegalArgumentException if the UID is null or empty,
* or the the meta information is null
*/
public BridgeType(ThingTypeUID uid, List<String> supportedBridgeTypeUIDs, String label, String description,
boolean listed, List<ChannelDefinition> channelDefinitions,
List<ChannelGroupDefinition> channelGroupDefinitions, Map<String, String> properties,
URI configDescriptionURI) throws IllegalArgumentException {
public BridgeType(@NonNull ThingTypeUID uid, @Nullable List<String> supportedBridgeTypeUIDs, @NonNull String label,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we agree on that we only want to state if a parameter is NonNull and if if can be null we omit the @Nullable annotation?

@Nullable String description, boolean listed, @Nullable List<ChannelDefinition> channelDefinitions,
@Nullable List<ChannelGroupDefinition> channelGroupDefinitions, @Nullable Map<String, String> properties,
@Nullable URI configDescriptionURI) throws IllegalArgumentException {

this(uid, supportedBridgeTypeUIDs, label, description, listed, null, channelDefinitions,
channelGroupDefinitions, properties, configDescriptionURI);
Expand Down Expand Up @@ -140,10 +143,11 @@ public BridgeType(ThingTypeUID uid, List<String> supportedBridgeTypeUIDs, String
* @throws IllegalArgumentException if the UID is null or empty,
* or the the meta information is null
*/
public BridgeType(ThingTypeUID uid, List<String> supportedBridgeTypeUIDs, String label, String description,
boolean listed, String representationProperty, List<ChannelDefinition> channelDefinitions,
List<ChannelGroupDefinition> channelGroupDefinitions, Map<String, String> properties,
URI configDescriptionURI) throws IllegalArgumentException {
public BridgeType(@NonNull ThingTypeUID uid, @Nullable List<String> supportedBridgeTypeUIDs, @NonNull String label,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we agree on that we only want to state if a parameter is NonNull and if if can be null we omit the @Nullable annotation?

@Nullable String description, boolean listed, @Nullable String representationProperty,
@Nullable List<ChannelDefinition> channelDefinitions,
@Nullable List<ChannelGroupDefinition> channelGroupDefinitions, @Nullable Map<String, String> properties,
@Nullable URI configDescriptionURI) throws IllegalArgumentException {

super(uid, supportedBridgeTypeUIDs, label, description, listed, representationProperty, channelDefinitions,
channelGroupDefinitions, properties, configDescriptionURI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.HashMap;
import java.util.Map;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.core.thing.Channel;
import org.eclipse.smarthome.core.thing.Thing;

Expand Down Expand Up @@ -56,16 +58,13 @@ public ChannelDefinition(String id, ChannelTypeUID channelTypeUID) throws Illega
*
* @throws IllegalArgumentException if the ID is null or empty, or the type is null
*/
public ChannelDefinition(String id, ChannelTypeUID channelTypeUID, Map<String, String> properties, String label,
String description) throws IllegalArgumentException {
if ((id == null) || (id.isEmpty())) {
public ChannelDefinition(@NonNull String id, @NonNull ChannelTypeUID channelTypeUID,
@Nullable Map<String, String> properties, @Nullable String label, @Nullable String description)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we agree on that we only want to state if a parameter is NonNull and if if can be null we omit the @Nullable annotation?

throws IllegalArgumentException {
if (id.isEmpty()) {
throw new IllegalArgumentException("The ID must neither be null nor empty!");
}

if (channelTypeUID == null) {
throw new IllegalArgumentException("The channel type must not be null");
}

if (properties != null) {
this.properties = Collections.unmodifiableMap(properties);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void removedService(ServiceReference<P> reference, P service) {
}

@Override
public void added(Provider<E> provider, E element) {
public void added(Provider<E> provider, @NonNull E element) {
Collection<E> elements = elementMap.get(provider);
if (elements != null) {
try {
Expand Down Expand Up @@ -200,7 +200,7 @@ public E get(K key) {
}

@Override
public E add(E element) {
public @NonNull E add(@NonNull E element) {
if (this.managedProvider != null) {
this.managedProvider.add(element);
return element;
Expand Down
Loading