Skip to content

Commit cb6cda4

Browse files
committed
Disallow negative tolerance value in save&restore
1 parent 4304070 commit cb6cda4

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/configuration/ConfigurationController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,13 @@ public String toString(Double value) {
309309
@Override
310310
public Double fromString(String string) {
311311
try {
312-
return Double.parseDouble(string);
312+
Double value = Double.parseDouble(string);
313+
if(value < 0){
314+
// Tolerance must be >= 0.
315+
// Tolerance must be >= 0.
316+
return null;
317+
}
318+
return value;
313319
} catch (Exception e) {
314320
// No logging needed: user has entered text that cannot be parsed as double.
315321
return null;

services/save-and-restore/src/main/java/org/phoebus/service/saveandrestore/web/controllers/ConfigurationController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ else if(configPv.getTolerance() != null){
7171
if(configPv.getPvCompareMode() == null){
7272
throw new IllegalArgumentException("PV item \"" + configPv.getPvName() + "\" specifies tolerance but no comparison mode");
7373
}
74-
//...but is zero, which does not make sense.
75-
else if(configPv.getTolerance() == 0){
74+
//...but is less than zero, which does not make sense as comparison considers tolerance as upper and lower limit.
75+
else if(configPv.getTolerance() < 0 ){
7676
throw new IllegalArgumentException("PV item \"" + configPv.getPvName() + "\" specifies zero tolerance");
7777
}
7878
}

services/save-and-restore/src/test/java/org/phoebus/service/saveandrestore/web/controllers/ConfigurationControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public void testCreateInvalidConfiguration() throws Exception {
196196

197197
configurationData.setPvList(List.of(
198198
ConfigPv.builder().pvName("fooo").readbackPvName("bar").pvCompareMode(PvCompareMode.RELATIVE)
199-
.tolerance(0.0).build()));
199+
.tolerance(-0.1).build()));
200200

201201
configuration.setConfigurationData(configurationData);
202202

0 commit comments

Comments
 (0)