Fix build and improve exception handling (#10726)

The PercentType and QuantityType can also throw an IllegalArgumentException.

Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
Wouter Born 2021-05-20 19:15:23 +02:00 committed by GitHub
parent b049d3d13b
commit a032118213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 9 additions and 11 deletions

View File

@ -92,7 +92,7 @@ public class DimmerItemConverter extends AbstractTransformingItemConverter {
value = PercentType.ZERO.toBigDecimal();
}
newState = new PercentType(value);
} catch (NumberFormatException e) {
} catch (IllegalArgumentException e) {
// ignore
}
}

View File

@ -14,8 +14,6 @@ package org.openhab.binding.http.internal.converter;
import java.util.function.Consumer;
import javax.measure.format.MeasurementParseException;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.http.internal.config.HttpChannelConfig;
@ -62,7 +60,7 @@ public class NumberItemConverter extends AbstractTransformingItemConverter {
return new QuantityType<>(trimmedValue);
}
}
} catch (IllegalArgumentException | MeasurementParseException e) {
} catch (IllegalArgumentException e) {
// finally failed
}
}

View File

@ -457,7 +457,7 @@ public class IAqualinkHandler extends BaseThingHandler {
default:
return StringType.valueOf(value);
}
} catch (NumberFormatException e) {
} catch (IllegalArgumentException e) {
return UnDefType.UNDEF;
}
}

View File

@ -46,8 +46,8 @@ import org.slf4j.LoggerFactory;
@NonNullByDefault
public class CommandTag {
private static final List<Class<? extends Command>> otherCommandTypes = Arrays.asList(DecimalType.class,
QuantityType.class, OnOffType.class, OpenClosedType.class, UpDownType.class, HSBType.class,
private static final List<Class<? extends Command>> otherCommandTypes = Arrays.asList(HSBType.class,
DecimalType.class, QuantityType.class, OnOffType.class, OpenClosedType.class, UpDownType.class,
PlayPauseType.class, RewindFastforwardType.class, StringType.class);
private static final List<Class<? extends Command>> percentCommandType = Arrays.asList(PercentType.class);

View File

@ -159,8 +159,8 @@ public class WLedHandler extends BaseThingHandler {
updateState(CHANNEL_SECONDARY_WHITE,
new PercentType(secondaryWhite.divide(BIG_DECIMAL_2_55, RoundingMode.HALF_UP)));
}
} catch (NumberFormatException e) {
logger.warn("NumberFormatException when parsing the WLED colour and white fields:{}", e.getMessage());
} catch (IllegalArgumentException e) {
logger.warn("IllegalArgumentException when parsing the WLED colour and white fields:{}", e.getMessage());
}
}

View File

@ -250,7 +250,7 @@ public class NeeoItemValueConverter {
default:
break;
}
} catch (NumberFormatException e) {
} catch (IllegalArgumentException e) {
// do nothing - let it go to the other cases
}
}

View File

@ -122,7 +122,7 @@ public class ScaleTransformationService extends AbstractFileTransformationServic
try {
final QuantityType<?> quantity = new QuantityType<>(source);
return formatResult(data, source, quantity.toBigDecimal());
} catch (NumberFormatException e2) {
} catch (IllegalArgumentException e2) {
String nonNumeric = data.get(null);
if (nonNumeric != null) {
return nonNumeric;