[infrastructure] add external null-annotations (#8848)

Signed-off-by: Jan N. Klug <jan.n.klug@rub.de>
This commit is contained in:
J-N-K
2020-10-31 00:29:03 +01:00
committed by GitHub
parent 47d05055db
commit bd664ff0c8
162 changed files with 933 additions and 575 deletions

View File

@@ -197,7 +197,8 @@ public class SmartherApiConnector {
}
}
} catch (ExecutionException e) {
future.completeExceptionally(e.getCause());
Throwable cause = e.getCause();
future.completeExceptionally(cause != null ? cause : e);
} catch (SmartherGatewayException e) {
future.completeExceptionally(e);
} catch (RuntimeException | TimeoutException e) {

View File

@@ -243,9 +243,12 @@ public class Enums {
public static <E extends Enum<E> & TypeWithIntProperty> E lookup(Class<E> en, int value)
throws SmartherIllegalPropertyValueException {
for (E constant : en.getEnumConstants()) {
if (constant.getValue() == value) {
return constant;
E[] constants = en.getEnumConstants();
if (constants != null) {
for (E constant : constants) {
if (constant.getValue() == value) {
return constant;
}
}
}
throw new SmartherIllegalPropertyValueException(en.getSimpleName(), String.valueOf(value));
@@ -257,9 +260,12 @@ public class Enums {
public static <E extends Enum<E> & TypeWithStringProperty> E lookup(Class<E> en, String value)
throws SmartherIllegalPropertyValueException {
for (E constant : en.getEnumConstants()) {
if (constant.getValue().equals(value)) {
return constant;
E[] constants = en.getEnumConstants();
if (constants != null) {
for (E constant : constants) {
if (constant.getValue().equals(value)) {
return constant;
}
}
}
throw new SmartherIllegalPropertyValueException(en.getSimpleName(), value);

View File

@@ -13,6 +13,7 @@
package org.openhab.binding.bticinosmarther.internal.api.exception;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* Signals that a generic OAuth2 authorization issue with API gateway has occurred.
@@ -30,7 +31,7 @@ public class SmartherAuthorizationException extends SmartherGatewayException {
* @param message
* the error message returned from the API gateway
*/
public SmartherAuthorizationException(String message) {
public SmartherAuthorizationException(@Nullable String message) {
super(message);
}
@@ -42,7 +43,7 @@ public class SmartherAuthorizationException extends SmartherGatewayException {
* @param cause
* the cause (a null value is permitted, and indicates that the cause is nonexistent or unknown)
*/
public SmartherAuthorizationException(String message, Throwable cause) {
public SmartherAuthorizationException(@Nullable String message, @Nullable Throwable cause) {
super(message, cause);
}
}

View File

@@ -15,6 +15,7 @@ package org.openhab.binding.bticinosmarther.internal.api.exception;
import java.io.IOException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* Signals that a generic communication issue with API gateway has occurred.
@@ -32,7 +33,7 @@ public class SmartherGatewayException extends IOException {
* @param message
* the error message returned from the API gateway
*/
public SmartherGatewayException(String message) {
public SmartherGatewayException(@Nullable String message) {
super(message);
}
@@ -44,7 +45,7 @@ public class SmartherGatewayException extends IOException {
* @param cause
* the cause (a null value is permitted, and indicates that the cause is nonexistent or unknown)
*/
public SmartherGatewayException(String message, Throwable cause) {
public SmartherGatewayException(@Nullable String message, @Nullable Throwable cause) {
super(message, cause);
}
@@ -57,7 +58,7 @@ public class SmartherGatewayException extends IOException {
* @param cause
* the cause (a null value is permitted, and indicates that the cause is nonexistent or unknown)
*/
public SmartherGatewayException(Throwable cause) {
public SmartherGatewayException(@Nullable Throwable cause) {
super(cause);
}
}

View File

@@ -13,6 +13,7 @@
package org.openhab.binding.bticinosmarther.internal.api.exception;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* Signals that an "invalid response" messaging issue with API gateway has occurred.
@@ -30,7 +31,7 @@ public class SmartherInvalidResponseException extends SmartherGatewayException {
* @param message
* the error message returned from the API gateway
*/
public SmartherInvalidResponseException(String message) {
public SmartherInvalidResponseException(@Nullable String message) {
super(message);
}
}

View File

@@ -17,6 +17,7 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
@@ -45,6 +46,9 @@ public final class DateUtil {
* if the string cannot be parsed to a local date
*/
public static LocalDate parseDate(@Nullable String str, String pattern) {
if (str == null) {
throw new DateTimeParseException("date string is null", "<null>", 0);
}
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(pattern);
return LocalDate.parse(str, dtf);
}
@@ -63,6 +67,9 @@ public final class DateUtil {
* if the string cannot be parsed to a local date and time
*/
public static LocalDateTime parseLocalTime(@Nullable String str, String pattern) {
if (str == null) {
throw new DateTimeParseException("time string is null", "<null>", 0);
}
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(pattern);
return LocalDateTime.parse(str, dtf);
}
@@ -81,6 +88,9 @@ public final class DateUtil {
* if the string cannot be parsed to a date and time with timezone
*/
public static ZonedDateTime parseZonedTime(@Nullable String str, String pattern) {
if (str == null) {
throw new DateTimeParseException("zoned string is null", "<null>", 0);
}
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(pattern);
return ZonedDateTime.parse(str, dtf);
}