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:
parent
b049d3d13b
commit
a032118213
|
@ -92,7 +92,7 @@ public class DimmerItemConverter extends AbstractTransformingItemConverter {
|
||||||
value = PercentType.ZERO.toBigDecimal();
|
value = PercentType.ZERO.toBigDecimal();
|
||||||
}
|
}
|
||||||
newState = new PercentType(value);
|
newState = new PercentType(value);
|
||||||
} catch (NumberFormatException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,6 @@ package org.openhab.binding.http.internal.converter;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import javax.measure.format.MeasurementParseException;
|
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.openhab.binding.http.internal.config.HttpChannelConfig;
|
import org.openhab.binding.http.internal.config.HttpChannelConfig;
|
||||||
|
@ -62,7 +60,7 @@ public class NumberItemConverter extends AbstractTransformingItemConverter {
|
||||||
return new QuantityType<>(trimmedValue);
|
return new QuantityType<>(trimmedValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException | MeasurementParseException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// finally failed
|
// finally failed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -457,7 +457,7 @@ public class IAqualinkHandler extends BaseThingHandler {
|
||||||
default:
|
default:
|
||||||
return StringType.valueOf(value);
|
return StringType.valueOf(value);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return UnDefType.UNDEF;
|
return UnDefType.UNDEF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,8 @@ import org.slf4j.LoggerFactory;
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class CommandTag {
|
public class CommandTag {
|
||||||
|
|
||||||
private static final List<Class<? extends Command>> otherCommandTypes = Arrays.asList(DecimalType.class,
|
private static final List<Class<? extends Command>> otherCommandTypes = Arrays.asList(HSBType.class,
|
||||||
QuantityType.class, OnOffType.class, OpenClosedType.class, UpDownType.class, HSBType.class,
|
DecimalType.class, QuantityType.class, OnOffType.class, OpenClosedType.class, UpDownType.class,
|
||||||
PlayPauseType.class, RewindFastforwardType.class, StringType.class);
|
PlayPauseType.class, RewindFastforwardType.class, StringType.class);
|
||||||
|
|
||||||
private static final List<Class<? extends Command>> percentCommandType = Arrays.asList(PercentType.class);
|
private static final List<Class<? extends Command>> percentCommandType = Arrays.asList(PercentType.class);
|
||||||
|
|
|
@ -159,8 +159,8 @@ public class WLedHandler extends BaseThingHandler {
|
||||||
updateState(CHANNEL_SECONDARY_WHITE,
|
updateState(CHANNEL_SECONDARY_WHITE,
|
||||||
new PercentType(secondaryWhite.divide(BIG_DECIMAL_2_55, RoundingMode.HALF_UP)));
|
new PercentType(secondaryWhite.divide(BIG_DECIMAL_2_55, RoundingMode.HALF_UP)));
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
logger.warn("NumberFormatException when parsing the WLED colour and white fields:{}", e.getMessage());
|
logger.warn("IllegalArgumentException when parsing the WLED colour and white fields:{}", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -250,7 +250,7 @@ public class NeeoItemValueConverter {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// do nothing - let it go to the other cases
|
// do nothing - let it go to the other cases
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ public class ScaleTransformationService extends AbstractFileTransformationServic
|
||||||
try {
|
try {
|
||||||
final QuantityType<?> quantity = new QuantityType<>(source);
|
final QuantityType<?> quantity = new QuantityType<>(source);
|
||||||
return formatResult(data, source, quantity.toBigDecimal());
|
return formatResult(data, source, quantity.toBigDecimal());
|
||||||
} catch (NumberFormatException e2) {
|
} catch (IllegalArgumentException e2) {
|
||||||
String nonNumeric = data.get(null);
|
String nonNumeric = data.get(null);
|
||||||
if (nonNumeric != null) {
|
if (nonNumeric != null) {
|
||||||
return nonNumeric;
|
return nonNumeric;
|
||||||
|
|
Loading…
Reference in New Issue