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

Commit

Permalink
Fix some warnings (#5925)
Browse files Browse the repository at this point in the history
Also configure HTML validation to ignore unknown elements and attributes
which exists due to the fact that Eclipse doesn't know the ng-* etc. tags.

Relates to #5853

Signed-off-by: Stefan Triller <stefan.triller@telekom.de>
  • Loading branch information
triller-telekom authored and htreu committed Jul 17, 2018
1 parent a5dae8b commit 5af9415
Show file tree
Hide file tree
Showing 38 changed files with 82 additions and 104 deletions.
Expand Up @@ -23,3 +23,4 @@ Import-Package:
org.slf4j
Bundle-ActivationPolicy: lazy
Service-Component: OSGI-INF/*.xml
Automatic-Module-Name: org.eclipse.smarthome.auth.oauth2client.test
Expand Up @@ -113,7 +113,6 @@ public OAuthClientService testGetClient(String handle) throws OAuthException {
}

@Override
@SuppressWarnings("null")
public AccessTokenResponse testGetAccessTokenByResourceOwnerPasswordCredentials()
throws OAuthException, IOException, OAuthResponseException {
logger.debug("test getOAuthTokenByResourceOwnerPasswordCredentials");
Expand All @@ -132,7 +131,6 @@ public AccessTokenResponse testGetAccessTokenByResourceOwnerPasswordCredentials(
}

@Override
@SuppressWarnings("null")
public AccessTokenResponse testGetAccessTokenByAuthorizationCode(String code)
throws OAuthException, IOException, OAuthResponseException {
return oauthClientService.getAccessTokenResponseByAuthorizationCode(code, REDIRECT_URI);
Expand Down Expand Up @@ -167,7 +165,6 @@ public void close() {
}

@Override
@SuppressWarnings("null")
public void delete(String handle) {
logger.debug("Delete handle: {}", handle);
oauthFactory.deleteServiceAndAccessToken(handle);
Expand Down
Expand Up @@ -54,7 +54,6 @@ public void setOauthFactory(OAuthFactory oauthFactory) {
super.oauthFactory = oauthFactory;
}

@SuppressWarnings("null")
public void unsetOauthFactory(OAuthFactory oauthFactory) {
if (super.oauthFactory == oauthFactory) {
if (handle != null) {
Expand Down
Expand Up @@ -54,7 +54,6 @@ public void setOauthFactory(OAuthFactory oauthFactory) {
this.oauthFactory = oauthFactory;
}

@SuppressWarnings("null")
public void unsetOauthFactory(OAuthFactory oauthFactory) {
if (super.oauthFactory == oauthFactory) {
if (handle != null) {
Expand Down
Expand Up @@ -27,4 +27,5 @@ Import-Package: com.google.gson,
org.osgi.service.packageadmin,
org.osgi.util.tracker,
org.slf4j
Automatic-Module-Name: org.eclipse.smarthome.auth.oauth2client

Expand Up @@ -296,7 +296,7 @@ public AccessTokenResponse getAccessTokenByClientCredentials(@Nullable String sc
throw new OAuthException("Missing client ID");
}

@SuppressWarnings("null") // depends on usage, cannot guarantee every parameter is not null at the beginning
// depending on usage, cannot guarantee every parameter is not null at the beginning
AccessTokenResponse accessTokenResponse = connector.grantTypeClientCredentials(tokenUrl, clientId,
persistedParams.clientSecret, scope, Boolean.TRUE.equals(persistedParams.supportsBasicAuth));

Expand Down
Expand Up @@ -3,8 +3,5 @@ output.. = target/test-classes/
bin.includes = META-INF/,\
.,\
NOTICE,\
src/test/resources/fragment-tb1.jar,\
src/test/resources/fragment-tb2.jar,\
src/test/resources/host-tb1.jar,\
src/test/resources/host-tb2.jar,\
src/test/resources/*,\
ESH-INF/
@@ -0,0 +1,19 @@
This content is produced and maintained by the Eclipse SmartHome project.

* Project home: https://eclipse.org/smarthome/

== Declared Project Licenses

This program and the accompanying materials are made available under the terms
of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/.

== Source Code

https://github.com/eclipse/smarthome

== Copyright Holders

See the NOTICE file distributed with the source code at
https://github.com/eclipse/smarthome/blob/master/NOTICE
for detailed information regarding copyright ownership.
@@ -0,0 +1,7 @@
output.. = target/classes/
bin.includes = META-INF/,\
.,\
NOTICE,\
ESH-INF/
source.. = src/test/java/

Expand Up @@ -47,8 +47,6 @@
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.UnDefType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This is a default scope provider for stuff that is of general interest in an ESH-based solution.
Expand All @@ -60,8 +58,6 @@
*/
public class DefaultScriptScopeProvider implements ScriptExtensionProvider {

private final Logger logger = LoggerFactory.getLogger(DefaultScriptScopeProvider.class);

private Map<String, Object> elements;

private ItemRegistry itemRegistry;
Expand Down
Expand Up @@ -35,8 +35,8 @@ public WelcomeHomeActionHandler(Action module) {

@Override
public Map<String, Object> execute(Map<String, Object> context) {
String device = getDevice(module.getConfiguration());
String result = getResult(module.getConfiguration());
getDevice(module.getConfiguration());
getResult(module.getConfiguration());
return null;
}

Expand Down
Expand Up @@ -18,9 +18,8 @@
import java.math.BigDecimal;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Arrays;
import java.util.Collections;

import org.eclipse.smarthome.config.core.ConfigDescriptionParameter.Type;
import org.junit.Test;
Expand All @@ -31,35 +30,30 @@
*
*/
public class ConfigUtilTest {
private Map<String, Object> m(String a, Object b) {
Map<String, Object> m = new HashMap<>();
m.put(a, b);
return m;
}

private static class L<T> extends ArrayList<T> {
L(T... args) {
for (T arg : args) {
add(arg);
}
}
};

@Test
public void firstDesciptionWinsForNormalization() throws URISyntaxException {
ConfigDescription configDescriptionInteger = new ConfigDescription(new URI("thing:fooThing"),
new L<>(new ConfigDescriptionParameter("foo", Type.INTEGER)));
Arrays.asList(new ConfigDescriptionParameter("foo", Type.INTEGER)));

ConfigDescription configDescriptionString = new ConfigDescription(new URI("thingType:fooThing"),
new L<>(new ConfigDescriptionParameter("foo", Type.TEXT)));
Arrays.asList(new ConfigDescriptionParameter("foo", Type.TEXT)));

assertThat(ConfigUtil.normalizeTypes(m("foo", "1"), new L<>(configDescriptionInteger)).get("foo"),
assertThat(
ConfigUtil.normalizeTypes(Collections.singletonMap("foo", "1"), Arrays.asList(configDescriptionInteger))
.get("foo"),
is(instanceOf(BigDecimal.class)));
assertThat(
ConfigUtil.normalizeTypes(Collections.singletonMap("foo", "1"), Arrays.asList(configDescriptionString))
.get("foo"),
is(instanceOf(String.class)));
assertThat(
ConfigUtil.normalizeTypes(Collections.singletonMap("foo", "1"),
Arrays.asList(configDescriptionInteger, configDescriptionString)).get("foo"),
is(instanceOf(BigDecimal.class)));
assertThat(ConfigUtil.normalizeTypes(m("foo", "1"), new L<>(configDescriptionString)).get("foo"),
assertThat(
ConfigUtil.normalizeTypes(Collections.singletonMap("foo", "1"),
Arrays.asList(configDescriptionString, configDescriptionInteger)).get("foo"),
is(instanceOf(String.class)));
assertThat(ConfigUtil.normalizeTypes(m("foo", "1"), new L<>(configDescriptionInteger, configDescriptionString))
.get("foo"), is(instanceOf(BigDecimal.class)));
assertThat(ConfigUtil.normalizeTypes(m("foo", "1"), new L<>(configDescriptionString, configDescriptionInteger))
.get("foo"), is(instanceOf(String.class)));
}
}
Expand Up @@ -47,7 +47,6 @@ public class InboxPredicatesTest {

private static final ThingUID THING_UID11 = new ThingUID(BINDING_ID1, THING_ID1);
private static final ThingUID THING_UID12 = new ThingUID(BINDING_ID1, THING_ID2);
private static final ThingUID THING_UID21 = new ThingUID(BINDING_ID2, THING_ID1);
private static final ThingUID THING_UID22 = new ThingUID(BINDING_ID2, THING_ID2);

private static final String PROP1 = "prop1";
Expand All @@ -58,7 +57,6 @@ public class InboxPredicatesTest {
private final static ThingTypeUID THING_TYPE_UID11 = new ThingTypeUID(BINDING_ID1, THING_TYPE_ID1);
private final static ThingTypeUID THING_TYPE_UID12 = new ThingTypeUID(BINDING_ID1, THING_TYPE_ID2);
private final static ThingTypeUID THING_TYPE_UID21 = new ThingTypeUID(BINDING_ID2, THING_TYPE_ID1);
private final static ThingTypeUID THING_TYPE_UID22 = new ThingTypeUID(BINDING_ID2, THING_TYPE_ID2);

private final static Map<String, Object> PROPS1 = new ImmutableMap.Builder<String, Object>().put(PROP1, PROP_VAL1)
.put(PROP2, PROP_VAL2).build();
Expand Down
Expand Up @@ -134,7 +134,6 @@ public int hashCode() {
return result;
}

@SuppressWarnings("null")
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
Expand Down
Expand Up @@ -43,7 +43,7 @@ public void testFetchValue() throws InterruptedException, ExecutionException {
assertNull(t.getLastKnownValue());

// Define a supplier which returns a future that is immediately completed.
@SuppressWarnings({ "unchecked", "null" })
@SuppressWarnings({ "unchecked" })
Supplier<CompletableFuture<Double>> s = mock(Supplier.class);
when(s.get()).thenReturn(CompletableFuture.completedFuture(10.0));

Expand Down
Expand Up @@ -74,14 +74,6 @@ public void getAsPercentFromHSB() {
assertEquals(origin.getBrightness().toBigDecimal(), result);
}

@Test
public void getAsPercentFromDummy() {
DummyType origin = new DummyType();
final DimmerItem item = createDimmerItem(origin);
final BigDecimal result = getState(item, PercentType.class);
assertEquals(origin.getBrightness().toBigDecimal(), result);
}

@Test
public void testUndefType() {
DimmerItem item = new DimmerItem("test");
Expand All @@ -94,8 +86,4 @@ public void testAcceptedStates() {
StateUtil.testAcceptedStates(item);
}

private class DummyType extends HSBType {

}

}
Expand Up @@ -35,7 +35,6 @@
* @author Henning Treu - initial contribution
*
*/
@SuppressWarnings("null")
public class ThingTypeBuilderTest {

private static final String CONF_URI = "conf:uri";
Expand Down
Expand Up @@ -15,8 +15,6 @@
import java.io.File;
import java.net.URL;

import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.xml.internal.ChannelTypeXmlResult;
import org.eclipse.smarthome.core.thing.xml.internal.ThingDescriptionList;
import org.eclipse.smarthome.core.thing.xml.internal.ThingDescriptionReader;
import org.junit.Test;
Expand All @@ -38,11 +36,5 @@ public void test() throws Exception {

ThingDescriptionReader reader = new ThingDescriptionReader();
ThingDescriptionList thingList = (ThingDescriptionList) reader.readFromXML(channelsURL);

thingList.stream().forEach(it -> {
if (it instanceof ChannelTypeXmlResult) {
ChannelType channelType = ((ChannelTypeXmlResult) it).toChannelType();
}
});
}
}
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.smarthome.config.xml.util.NodeValue;
import org.eclipse.smarthome.core.thing.type.ChannelKind;
import org.eclipse.smarthome.core.thing.type.ChannelType;
import org.eclipse.smarthome.core.thing.type.ChannelTypeBuilder;
import org.eclipse.smarthome.core.thing.type.ChannelTypeUID;
import org.eclipse.smarthome.core.types.EventDescription;
import org.eclipse.smarthome.core.types.StateDescription;
Expand Down Expand Up @@ -155,8 +156,18 @@ protected ChannelTypeXmlResult unmarshalType(HierarchicalStreamReader reader, Un
kind = "state";
}

ChannelType channelType = new ChannelType(channelTypeUID, advanced, itemType, ChannelKind.parse(kind), label,
description, category, tags, stateDescription, eventDescription, (URI) configDescriptionObjects[0]);
ChannelKind cKind = ChannelKind.parse(kind);
URI configDescriptionURI = (URI) configDescriptionObjects[0];
ChannelType channelType = null;
if (cKind == ChannelKind.STATE) {
channelType = ChannelTypeBuilder.state(channelTypeUID, label, itemType).isAdvanced(advanced)
.withDescription(description).withCategory(category).withTags(tags)
.withConfigDescriptionURI(configDescriptionURI).withStateDescription(stateDescription).build();
} else if (cKind == ChannelKind.TRIGGER) {
channelType = ChannelTypeBuilder.trigger(channelTypeUID, label).isAdvanced(advanced)
.withDescription(description).withCategory(category).withTags(tags)
.withConfigDescriptionURI(configDescriptionURI).withEventDescription(eventDescription).build();
}

ChannelTypeXmlResult channelTypeXmlResult = new ChannelTypeXmlResult(channelType,
(ConfigDescription) configDescriptionObjects[1], system);
Expand Down
Expand Up @@ -82,7 +82,9 @@ public T withTag(String tag) {

@Override
public T withTags(Collection<String> tags) {
this.tags.addAll(tags);
if (tags != null) {
this.tags.addAll(tags);
}
return (T) this;
}

Expand Down
Expand Up @@ -72,7 +72,6 @@ public ThingType(String bindingId, String thingTypeId, String label) throws Ille
* @throws IllegalArgumentException if the UID is null or empty, or the the meta information is null
*/
@Deprecated
@SuppressWarnings("null")
public ThingType(ThingTypeUID uid, List<String> supportedBridgeTypeUIDs, String label, String description,
List<ChannelDefinition> channelDefinitions, List<ChannelGroupDefinition> channelGroupDefinitions,
Map<String, String> properties, URI configDescriptionURI) throws IllegalArgumentException {
Expand All @@ -89,7 +88,6 @@ public ThingType(ThingTypeUID uid, List<String> supportedBridgeTypeUIDs, String
* @throws IllegalArgumentException if the UID is null or empty, or the the meta information is null
*/
@Deprecated
@SuppressWarnings("null")
public ThingType(ThingTypeUID uid, List<String> supportedBridgeTypeUIDs, String label, String description,
String category, boolean listed, List<ChannelDefinition> channelDefinitions,
List<ChannelGroupDefinition> channelGroupDefinitions, @Nullable Map<String, String> properties,
Expand Down
Expand Up @@ -4,5 +4,5 @@
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/test/java"/>
<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.smarthome.core.voice"/>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="output" path="target/test-classes"/>
</classpath>
Expand Up @@ -57,7 +57,6 @@ public ExpiringCacheAsync(long expiry) throws IllegalArgumentException {
* `getValue().thenAccept(value->useYourValueHere(value));`. If you need the value synchronously you can use
* `getValue().get()`.
*/
@SuppressWarnings("null")
public CompletableFuture<V> getValue(Supplier<CompletableFuture<V>> requestNewValueFuture) {
if (isExpired()) {
return refreshValue(requestNewValueFuture);
Expand Down Expand Up @@ -103,7 +102,6 @@ public synchronized CompletableFuture<V> refreshValue(Supplier<CompletableFuture
if (currentNewValueRequest == null) {
throw new IllegalArgumentException("We expect a CompletableFuture for refreshValue() to work!");
}
@SuppressWarnings("null")
CompletableFuture<V> t = currentNewValueRequest.thenApply(newValue -> {
// No request is ongoing anymore, update the value and expire time
this.currentNewValueRequest = null;
Expand Down
Expand Up @@ -22,4 +22,3 @@ Import-Package:
org.mockito,
org.mockito.invocation,
org.mockito.stubbing
Automatic-Module-Name: org.eclipse.smarthome.io.transport.mqtt.test
Expand Up @@ -15,7 +15,6 @@
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection;
import org.eclipse.smarthome.io.transport.mqtt.MqttBrokerConnection;
import org.eclipse.smarthome.io.transport.mqtt.MqttConnectionObserver;

/**
Expand All @@ -41,7 +40,7 @@ public void setBrokerConnection(MqttBrokerConnection mqttBrokerConnectionImpl) {
* Return the brokerConnection object that this reconnect policy is assigned to.
*/
public @Nullable MqttBrokerConnection getBrokerConnection() {
return (MqttBrokerConnection) brokerConnection;
return brokerConnection;
}

/**
Expand Down
Expand Up @@ -45,7 +45,6 @@ public class AstroHandlerFactory extends BaseThingHandlerFactory {
.concat(SunHandler.SUPPORTED_THING_TYPES.stream(), MoonHandler.SUPPORTED_THING_TYPES.stream())
.collect(Collectors.toSet());
private static final Map<String, AstroThingHandler> ASTRO_THING_HANDLERS = new HashMap<>();
private TimeZoneProvider timeZoneProvider;

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
Expand Down
Expand Up @@ -44,7 +44,6 @@
import org.eclipse.smarthome.core.thing.ThingStatusDetail;
import org.eclipse.smarthome.core.thing.binding.BaseBridgeHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandler;
import org.eclipse.smarthome.core.thing.binding.ThingHandlerCallback;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.RefreshType;
import org.osgi.framework.ServiceRegistration;
Expand Down

0 comments on commit 5af9415

Please sign in to comment.