Skip to content

Commit

Permalink
[scale] fix NPE in transformation (openhab#8124)
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes DerOetzi Ott <[email protected]>t>
Signed-off-by: MPH80 <[email protected]>
  • Loading branch information
DerOetzi authored and MPH80 committed Aug 3, 2020
1 parent e3157ce commit 03c32b2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
[38..45]=avoid exertion
[45..54]=dangerous
[54..100]=heat stroke imminent
NaN=unknown
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private String formatResult(Map<Range, String> data, String source, final BigDec

private String getScaleResult(Map<Range, String> data, String source, final BigDecimal value)
throws TransformationException {
return data.entrySet().stream().filter(entry -> entry.getKey().contains(value)).findFirst()
return data.entrySet().stream().filter(entry -> entry.getKey() != null && entry.getKey().contains(value)).findFirst()
.map(Map.Entry::getValue)
.orElseThrow(() -> new TransformationException("No matching range for '" + source + "'"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,12 @@ public void testTransformAndFormat() throws TransformationException {
String transformedResponse = processor.transform(existingscale, source);
Assert.assertEquals("Correcte (992) !", transformedResponse);
}

@Test
public void testValueExceedsRange() throws TransformationException {
String existingscale = "scale/humidex.scale";
String source = "200";
String transformedResponse = processor.transform(existingscale, source);
Assert.assertEquals("", transformedResponse);
}
}

0 comments on commit 03c32b2

Please sign in to comment.