Skip to content

Commit 34e6bce

Browse files
committed
fix: NPE in issue steve-community#38
reason: SendLocalListTask tries to set operation name in the constructor of the super class, where a call to getRequest method of SendLocalListTask is made. but, in order to create the request, ocppTagService field has to be set, which did not happen yet, since we are in the constructor of the super class. therefore, a NPE occurs. use a different strategy like parsing the name of the task object. this implies that we always have to use reasonable task names that reflect the operation name.
1 parent 29d63e1 commit 34e6bce

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/main/java/de/rwth/idsg/steve/ocpp/CommunicationTask.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ public CommunicationTask(OcppVersion ocppVersion, S params) {
7373
}
7474

7575
callbackList.add(defaultCallback());
76-
77-
// FIXME: dirty, because creating a request only to parse its class name
78-
operationName = StringUtils.getOperationName(getRequest());
76+
operationName = StringUtils.getOperationName(this);
7977
}
8078

8179
public void addCallback(OcppCallback<RESPONSE> cb) {

src/main/java/de/rwth/idsg/steve/utils/StringUtils.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.rwth.idsg.steve.utils;
22

3+
import de.rwth.idsg.steve.ocpp.CommunicationTask;
34
import de.rwth.idsg.steve.ocpp.RequestType;
45

56
/**
@@ -29,4 +30,17 @@ public static String getOperationName(RequestType requestType) {
2930

3031
return s;
3132
}
33+
34+
public static String getOperationName(CommunicationTask task) {
35+
String s = task.getClass().getSimpleName();
36+
37+
if (s.endsWith("Task")) {
38+
s = s.substring(0, s.length() - 4);
39+
}
40+
41+
// http://stackoverflow.com/a/4886141
42+
s = s.replaceAll("(\\p{Ll})(\\p{Lu})", "$1 $2");
43+
44+
return s;
45+
}
3246
}

0 commit comments

Comments
 (0)