Skip to content

Commit

Permalink
dcache-bulk: guard against erroneous argument names
Browse files Browse the repository at this point in the history
Motivation:

Giving the `PIN` activity an argument it does
not recognize will provoke an NPE, e.g.,

```
20 Sep 2023 11:28:10 [pool-11-thread-1] [] Uncaught exception in thread pool-11-thread-1java.lang.NullPointerException: null
	at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1838)
	at java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
	at java.base/java.lang.Double.parseDouble(Double.java:543)
	at org.dcache.services.bulk.activity.plugin.pin.PinActivity.configure(PinActivity.java:138)
...
```

Modification:

Check for undefined lifetime property.

Result:

No more NPE/stack trace.

Target: master
Request: 9.1
Request: 9.0
Request: 8.2
Requires-notes: yes
Patch: https://rb.dcache.org/r/14108/
Acked-by: Lea
  • Loading branch information
alrossi committed Sep 27, 2023
1 parent bf9bb6c commit afe112e
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public ListenableFuture<Message> perform(String rid, long tid, FsPath target,
@Override
protected void configure(Map<String, String> arguments) {
TimeUnit defaultUnit = TimeUnit.valueOf(lifetimeUnitDefault());

Long defaultValue = Long.parseLong(lifetimeDefault());

if (arguments == null) {
Expand All @@ -135,11 +136,17 @@ protected void configure(Map<String, String> arguments) {
String expire = arguments.get(LIFETIME);
String unit = arguments.get(LIFETIME_UNIT);

Long value = (long) (Double.parseDouble(expire));

lifetimeInMillis = expire == null ? defaultUnit.toMillis(defaultValue)
: unit == null ? defaultUnit.toMillis(value)
: TimeUnit.valueOf(unit).toMillis(value);
/*
* Guard against erroneous argument names ...
*/
if (expire == null) {
lifetimeInMillis = unit == null ? defaultUnit.toMillis(defaultValue):
TimeUnit.valueOf(unit).toMillis(defaultValue);
} else {
Long value = (long) (Double.parseDouble(expire));
lifetimeInMillis = unit == null ? defaultUnit.toMillis(value)
: TimeUnit.valueOf(unit).toMillis(value);
}
}

id = arguments == null ? null : arguments.get(PIN_REQUEST_ID);
Expand Down

0 comments on commit afe112e

Please sign in to comment.