[infrastructure] move infered nullness warnings to error and update EEA (#8949)

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
This commit is contained in:
J-N-K
2020-11-12 21:07:11 +01:00
committed by GitHub
parent 0856a0b3f2
commit ba4c96d99d
155 changed files with 644 additions and 632 deletions

View File

@@ -204,7 +204,7 @@ public class NeeoApi implements AutoCloseable {
try (HttpRequest req = new HttpRequest()) {
final HttpResponse res = req.sendGetCommand(sysInfo);
if (res.getHttpCode() == HttpStatus.OK_200) {
return GSON.fromJson(res.getContent(), NeeoSystemInfo.class);
return Objects.requireNonNull(GSON.fromJson(res.getContent(), NeeoSystemInfo.class));
} else {
throw res.createException();
}

View File

@@ -155,9 +155,12 @@ public class NeeoUtil {
* @param s The UTF-8 encoded String to be decoded
* @return the decoded String
*/
public static String decodeURIComponent(String s) {
String result = null;
public static String decodeURIComponent(@Nullable String s) {
if (s == null) {
return "";
}
String result = null;
try {
result = URLDecoder.decode(s, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {

View File

@@ -130,11 +130,14 @@ class OpenHabToDeviceConverter {
if (StringUtils.equalsIgnoreCase(NeeoConstants.NEEOBINDING_BINDING_ID, thing.getUID().getBindingId())) {
final Map<String, String> properties = thing.getProperties();
/** The following properties have matches in org.openhab.binding.neeo.NeeoDeviceHandler.java */
final String neeoType = StringUtils.isEmpty(properties.get("Type")) ? NeeoDeviceType.ACCESSOIRE.toString()
: properties.get("Type");
final String manufacturer = StringUtils.isEmpty(properties.get("Manufacturer")) ? "openHAB"
: properties.get("Manufacturer");
String neeoType = properties.get("Type");
if (neeoType == null || neeoType.isEmpty()) {
neeoType = NeeoDeviceType.ACCESSOIRE.toString();
}
String manufacturer = properties.get("Manufacturer");
if (manufacturer == null || manufacturer.isEmpty()) {
manufacturer = "openHAB";
}
final Integer standbyDelay = parseInteger(properties.getOrDefault("Standby Command Delay", "0"));
final Integer switchDelay = parseInteger(properties.getOrDefault("Source Switch Delay", "0"));
final Integer shutDownDelay = parseInteger(properties.getOrDefault("Shutdown Delay", "0"));

View File

@@ -110,7 +110,7 @@ public class TokenSearch {
final Map<@NonNull String, String> properties = thing.getProperties();
final String vendor = properties.get(Thing.PROPERTY_VENDOR);
if (StringUtils.isNotEmpty(vendor)) {
if (vendor != null && !vendor.isEmpty()) {
score += search(vendor, needles);
}

View File

@@ -36,12 +36,8 @@ import com.google.gson.JsonSerializer;
public class ChannelUIDSerializer implements JsonSerializer<ChannelUID>, JsonDeserializer<ChannelUID> {
@Override
public ChannelUID deserialize(@Nullable JsonElement elm, @Nullable Type type,
@Nullable JsonDeserializationContext context) throws JsonParseException {
Objects.requireNonNull(elm, "elm cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(context, "context cannot be null");
public @Nullable ChannelUID deserialize(JsonElement elm, Type type, JsonDeserializationContext context)
throws JsonParseException {
if (elm.isJsonNull()) {
throw new JsonParseException("Not a valid ChannelUID: (null)");
}

View File

@@ -13,7 +13,6 @@
package org.openhab.io.neeo.internal.serialization;
import java.lang.reflect.Type;
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -36,12 +35,8 @@ import com.google.gson.JsonSerializer;
@NonNullByDefault
public class ItemSubTypeSerializer implements JsonSerializer<ItemSubType>, JsonDeserializer<ItemSubType> {
@Override
public ItemSubType deserialize(@Nullable JsonElement elm, @Nullable Type type,
@Nullable JsonDeserializationContext jsonContext) throws JsonParseException {
Objects.requireNonNull(elm, "elm cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public @Nullable ItemSubType deserialize(JsonElement elm, Type type, JsonDeserializationContext jsonContext)
throws JsonParseException {
if (elm.isJsonNull()) {
throw new JsonParseException("ItemSubType could not be parsed from null");
}
@@ -50,11 +45,7 @@ public class ItemSubTypeSerializer implements JsonSerializer<ItemSubType>, JsonD
}
@Override
public JsonElement serialize(ItemSubType ist, @Nullable Type type, @Nullable JsonSerializationContext jsonContext) {
Objects.requireNonNull(ist, "ist cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public JsonElement serialize(ItemSubType ist, Type type, JsonSerializationContext jsonContext) {
return new JsonPrimitive(ist.toString());
}
}

View File

@@ -13,7 +13,6 @@
package org.openhab.io.neeo.internal.serialization;
import java.lang.reflect.Type;
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -36,12 +35,8 @@ import com.google.gson.JsonSerializer;
@NonNullByDefault
public class ListUiActionSerializer implements JsonSerializer<ListUiAction>, JsonDeserializer<ListUiAction> {
@Override
public ListUiAction deserialize(@Nullable JsonElement elm, @Nullable Type type,
@Nullable JsonDeserializationContext jsonContext) throws JsonParseException {
Objects.requireNonNull(elm, "elm cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public @Nullable ListUiAction deserialize(JsonElement elm, Type type, JsonDeserializationContext jsonContext)
throws JsonParseException {
if (elm.isJsonNull()) {
throw new JsonParseException("ListUiAction could not be parsed from null");
}
@@ -50,12 +45,7 @@ public class ListUiActionSerializer implements JsonSerializer<ListUiAction>, Jso
}
@Override
public JsonElement serialize(ListUiAction ist, @Nullable Type type,
@Nullable JsonSerializationContext jsonContext) {
Objects.requireNonNull(ist, "ist cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public JsonElement serialize(ListUiAction ist, Type type, JsonSerializationContext jsonContext) {
return new JsonPrimitive(ist.toString());
}
}

View File

@@ -15,7 +15,6 @@ package org.openhab.io.neeo.internal.serialization;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -54,12 +53,7 @@ public class NeeoBrainDeviceSerializer implements JsonSerializer<NeeoDevice> {
private final Logger logger = LoggerFactory.getLogger(NeeoBrainDeviceSerializer.class);
@Override
public JsonElement serialize(NeeoDevice device, @Nullable Type deviceType,
@Nullable JsonSerializationContext jsonContext) {
Objects.requireNonNull(device, "device cannot be null");
Objects.requireNonNull(deviceType, "deviceType cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public JsonElement serialize(NeeoDevice device, Type deviceType, JsonSerializationContext jsonContext) {
final JsonObject jsonObject = new JsonObject();
final String adapterName = device.getUid().getNeeoUID();

View File

@@ -13,7 +13,6 @@
package org.openhab.io.neeo.internal.serialization;
import java.lang.reflect.Type;
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -37,12 +36,8 @@ import com.google.gson.JsonSerializer;
public class NeeoCapabilityTypeSerializer
implements JsonSerializer<NeeoCapabilityType>, JsonDeserializer<NeeoCapabilityType> {
@Override
public NeeoCapabilityType deserialize(@Nullable JsonElement elm, @Nullable Type type,
@Nullable JsonDeserializationContext jsonContext) throws JsonParseException {
Objects.requireNonNull(elm, "elm cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public @Nullable NeeoCapabilityType deserialize(JsonElement elm, Type type, JsonDeserializationContext jsonContext)
throws JsonParseException {
if (elm.isJsonNull()) {
throw new JsonParseException("NeeoCapabilityType could not be parsed from null");
}
@@ -51,12 +46,7 @@ public class NeeoCapabilityTypeSerializer
}
@Override
public JsonElement serialize(NeeoCapabilityType nct, @Nullable Type type,
@Nullable JsonSerializationContext jsonContext) {
Objects.requireNonNull(nct, "nct cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public JsonElement serialize(NeeoCapabilityType nct, Type type, JsonSerializationContext jsonContext) {
return new JsonPrimitive(nct.toString());
}
}

View File

@@ -13,7 +13,6 @@
package org.openhab.io.neeo.internal.serialization;
import java.lang.reflect.Type;
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -37,12 +36,8 @@ import com.google.gson.JsonSerializer;
public class NeeoDeviceChannelKindSerializer
implements JsonSerializer<NeeoDeviceChannelKind>, JsonDeserializer<NeeoDeviceChannelKind> {
@Override
public NeeoDeviceChannelKind deserialize(@Nullable JsonElement elm, @Nullable Type type,
@Nullable JsonDeserializationContext jsonContext) throws JsonParseException {
Objects.requireNonNull(elm, "elm cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public @Nullable NeeoDeviceChannelKind deserialize(JsonElement elm, Type type,
JsonDeserializationContext jsonContext) throws JsonParseException {
if (elm.isJsonNull()) {
throw new JsonParseException("NeeoDeviceChannelKind could not be parsed from null");
}
@@ -51,12 +46,7 @@ public class NeeoDeviceChannelKindSerializer
}
@Override
public JsonElement serialize(NeeoDeviceChannelKind ndck, @Nullable Type type,
@Nullable JsonSerializationContext jsonContext) {
Objects.requireNonNull(ndck, "ndck cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public JsonElement serialize(NeeoDeviceChannelKind ndck, Type type, JsonSerializationContext jsonContext) {
return new JsonPrimitive(ndck.toString());
}
}

View File

@@ -15,7 +15,6 @@ package org.openhab.io.neeo.internal.serialization;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -77,12 +76,7 @@ public class NeeoDeviceChannelSerializer
}
@Override
public JsonElement serialize(NeeoDeviceChannel chnl, @Nullable Type type,
@Nullable JsonSerializationContext jsonContext) {
Objects.requireNonNull(chnl, "chnl cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public JsonElement serialize(NeeoDeviceChannel chnl, Type type, JsonSerializationContext jsonContext) {
final JsonObject jo = new JsonObject();
jo.add("kind", jsonContext.serialize(chnl.getKind()));
@@ -169,12 +163,8 @@ public class NeeoDeviceChannelSerializer
}
@Override
public NeeoDeviceChannel deserialize(@Nullable JsonElement elm, @Nullable Type type,
@Nullable JsonDeserializationContext context) throws JsonParseException {
Objects.requireNonNull(elm, "elm cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(context, "context cannot be null");
public @Nullable NeeoDeviceChannel deserialize(JsonElement elm, Type type, JsonDeserializationContext context)
throws JsonParseException {
if (!(elm instanceof JsonObject)) {
throw new JsonParseException("Element not an instance of JsonObject: " + elm);
}

View File

@@ -84,12 +84,8 @@ public class NeeoDeviceSerializer implements JsonSerializer<NeeoDevice>, JsonDes
}
@Override
public NeeoDevice deserialize(@Nullable JsonElement elm, @Nullable Type type,
@Nullable JsonDeserializationContext jsonContext) throws JsonParseException {
Objects.requireNonNull(elm, "elm cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public @Nullable NeeoDevice deserialize(JsonElement elm, Type type, JsonDeserializationContext jsonContext)
throws JsonParseException {
if (!(elm instanceof JsonObject)) {
throw new JsonParseException("Element not an instance of JsonObject: " + elm);
}

View File

@@ -13,7 +13,6 @@
package org.openhab.io.neeo.internal.serialization;
import java.lang.reflect.Type;
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -37,12 +36,8 @@ import com.google.gson.JsonSerializer;
public class NeeoDeviceTypeSerializer implements JsonSerializer<NeeoDeviceType>, JsonDeserializer<NeeoDeviceType> {
@Override
public NeeoDeviceType deserialize(@Nullable JsonElement elm, @Nullable Type type,
@Nullable JsonDeserializationContext jsonContext) throws JsonParseException {
Objects.requireNonNull(elm, "elm cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public @Nullable NeeoDeviceType deserialize(JsonElement elm, Type type, JsonDeserializationContext jsonContext)
throws JsonParseException {
if (elm.isJsonNull()) {
throw new JsonParseException("NeeoDeviceType could not be parsed from null");
}
@@ -51,12 +46,7 @@ public class NeeoDeviceTypeSerializer implements JsonSerializer<NeeoDeviceType>,
}
@Override
public JsonElement serialize(NeeoDeviceType ndt, @Nullable Type type,
@Nullable JsonSerializationContext jsonContext) {
Objects.requireNonNull(ndt, "ndt cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public JsonElement serialize(NeeoDeviceType ndt, Type type, JsonSerializationContext jsonContext) {
return new JsonPrimitive(ndt.toString());
}
}

View File

@@ -13,7 +13,6 @@
package org.openhab.io.neeo.internal.serialization;
import java.lang.reflect.Type;
import java.util.Objects;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -36,12 +35,8 @@ import com.google.gson.JsonSerializer;
public class NeeoThingUIDSerializer implements JsonSerializer<NeeoThingUID>, JsonDeserializer<NeeoThingUID> {
@Override
public NeeoThingUID deserialize(@Nullable JsonElement elm, @Nullable Type type,
@Nullable JsonDeserializationContext jsonContext) throws JsonParseException {
Objects.requireNonNull(elm, "elm cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public @Nullable NeeoThingUID deserialize(JsonElement elm, Type type, JsonDeserializationContext jsonContext)
throws JsonParseException {
if (elm.isJsonNull()) {
throw new JsonParseException("Not a valid ChannelUID: (null)");
}
@@ -54,12 +49,7 @@ public class NeeoThingUIDSerializer implements JsonSerializer<NeeoThingUID>, Jso
}
@Override
public JsonElement serialize(NeeoThingUID uid, @Nullable Type type,
@Nullable JsonSerializationContext jsonContext) {
Objects.requireNonNull(uid, "uid cannot be null");
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(jsonContext, "jsonContext cannot be null");
public JsonElement serialize(NeeoThingUID uid, Type type, JsonSerializationContext jsonContext) {
return new JsonPrimitive(uid.getAsString());
}
}

View File

@@ -96,33 +96,40 @@ public class BrainDashboardService extends DefaultServletService {
NeeoUtil.write(resp, gson.toJson(status));
} else if (StringUtils.equalsIgnoreCase(paths[0], "blinkled")) {
final String brainId = req.getParameter("brainid");
final NeeoBrainServlet servlet = service.getServlet(brainId);
if (servlet == null) {
NeeoUtil.write(resp, gson.toJson(new ReturnStatus("Unknown BraidID: " + brainId)));
if (brainId == null) {
NeeoUtil.write(resp, gson.toJson(new ReturnStatus("BrainID is null")));
} else {
try {
servlet.getBrainApi().blinkLed();
NeeoUtil.write(resp, gson.toJson(new ReturnStatus(true)));
} catch (IOException e) {
NeeoUtil.write(resp,
gson.toJson(new ReturnStatus("Exception occurred blinking LED: " + e.getMessage())));
final NeeoBrainServlet servlet = service.getServlet(brainId);
if (servlet == null) {
NeeoUtil.write(resp, gson.toJson(new ReturnStatus("Unknown BrainID: " + brainId)));
} else {
try {
servlet.getBrainApi().blinkLed();
NeeoUtil.write(resp, gson.toJson(new ReturnStatus(true)));
} catch (IOException e) {
NeeoUtil.write(resp, gson
.toJson(new ReturnStatus("Exception occurred blinking LED: " + e.getMessage())));
}
}
}
} else if (StringUtils.equalsIgnoreCase(paths[0], "getlog")) {
final String brainId = req.getParameter("brainid");
final NeeoBrainServlet servlet = service.getServlet(brainId);
if (servlet == null) {
NeeoUtil.write(resp, gson.toJson(new ReturnStatus("Unknown BraidID: " + brainId)));
if (brainId == null) {
NeeoUtil.write(resp, gson.toJson(new ReturnStatus("BrainID is null")));
} else {
try {
final String log = servlet.getBrainApi().getLog();
NeeoUtil.write(resp, gson.toJson(new ReturnStatus(true, log)));
} catch (IOException e) {
NeeoUtil.write(resp,
gson.toJson(new ReturnStatus("Exception occurred getting log: " + e.getMessage())));
final NeeoBrainServlet servlet = service.getServlet(brainId);
if (servlet == null) {
NeeoUtil.write(resp, gson.toJson(new ReturnStatus("Unknown BraidID: " + brainId)));
} else {
try {
final String log = servlet.getBrainApi().getLog();
NeeoUtil.write(resp, gson.toJson(new ReturnStatus(true, log)));
} catch (IOException e) {
NeeoUtil.write(resp,
gson.toJson(new ReturnStatus("Exception occurred getting log: " + e.getMessage())));
}
}
}
} else {
logger.debug("Unknown get path: {}", StringUtils.join(paths, ','));
}

View File

@@ -109,7 +109,10 @@ public class NeeoBrainSearchService extends DefaultServletService {
final String path = StringUtils.lowerCase(paths[1]);
if (StringUtils.equalsIgnoreCase(path, "search")) {
doSearch(req.getQueryString(), resp);
String queryString = req.getQueryString();
if (queryString != null) {
doSearch(queryString, resp);
}
} else if (StringUtils.equalsIgnoreCase(path, "adapterdefinition") && paths.length >= 3) {
doAdapterDefinition(paths[2], resp);
} else {