Skip to content

Commit 199b0f7

Browse files
author
Ravi Nadahar
committed
Fix ActionHandler.execute() nullness annotation
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
1 parent 73c9cbd commit 199b0f7

14 files changed

Lines changed: 31 additions & 30 deletions

File tree

bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/PlayActionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public PlayActionHandler(Action module, AudioManager audioManager) {
6161
}
6262

6363
@Override
64-
public @Nullable Map<String, Object> execute(Map<String, Object> context) {
64+
public @Nullable Map<String, @Nullable Object> execute(Map<String, Object> context) {
6565
try {
6666
audioManager.playFile(sound, sink, volume);
6767
} catch (AudioException e) {

bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/SayActionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public SayActionHandler(Action module, VoiceManager voiceManager) {
5656
}
5757

5858
@Override
59-
public @Nullable Map<String, Object> execute(Map<String, Object> context) {
59+
public @Nullable Map<String, @Nullable Object> execute(Map<String, Object> context) {
6060
voiceManager.say(text, null, sink, volume);
6161
return null;
6262
}

bundles/org.openhab.core.automation.module.media/src/main/java/org/openhab/core/automation/module/media/internal/SynthesizeActionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public SynthesizeActionHandler(Action module, AudioManager audioManager) {
5454
}
5555

5656
@Override
57-
public @Nullable Map<String, Object> execute(Map<String, Object> context) {
57+
public @Nullable Map<String, @Nullable Object> execute(Map<String, Object> context) {
5858
audioManager.playMelody(melody, sink, volume);
5959
return null;
6060
}

bundles/org.openhab.core.automation.module.script.rulesupport/src/main/java/org/openhab/core/automation/module/script/rulesupport/internal/delegates/SimpleActionHandlerDelegate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void dispose() {
4444
}
4545

4646
@Override
47-
public @Nullable Map<String, Object> execute(Map<String, @Nullable Object> inputs) {
47+
public @Nullable Map<String, @Nullable Object> execute(Map<String, @Nullable Object> inputs) {
4848
Set<String> keys = new HashSet<>(inputs.keySet());
4949

5050
Map<String, @Nullable Object> extendedInputs = new HashMap<>(inputs);
@@ -60,7 +60,7 @@ public void dispose() {
6060
}
6161

6262
Object result = actionHandler.execute(module, extendedInputs);
63-
Map<String, Object> resultMap = new HashMap<>();
63+
Map<String, @Nullable Object> resultMap = new HashMap<>();
6464
resultMap.put("result", result);
6565
return resultMap;
6666
}

bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/internal/handler/ScriptActionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public void compile() throws ScriptException {
7171
}
7272

7373
@Override
74-
public @Nullable Map<String, Object> execute(final Map<String, Object> context) {
75-
Map<String, Object> resultMap = new HashMap<>();
74+
public @Nullable Map<String, @Nullable Object> execute(final Map<String, Object> context) {
75+
Map<String, @Nullable Object> resultMap = new HashMap<>();
7676

7777
if (script.isEmpty()) {
7878
return resultMap;

bundles/org.openhab.core.automation.rest/src/main/java/org/openhab/core/automation/rest/internal/ThingActionsResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public Response executeThingAction(@PathParam("thingUID") @Parameter(description
254254
}
255255

256256
try {
257-
Map<String, Object> returnValue = Objects.requireNonNullElse(
257+
Map<String, @Nullable Object> returnValue = Objects.requireNonNullElse(
258258
handler.execute(actionInputsHelper.mapSerializedInputsToActionInputs(actionType, actionInputs)),
259259
Map.of());
260260
moduleHandlerFactory.ungetHandler(action, ruleUID, handler);

bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/handler/ActionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ default void compile() throws Exception {
4848
* @return a map with the {@code outputs} which are the result of the {@link Action}'s execution (may be null).
4949
*/
5050
@Nullable
51-
Map<String, Object> execute(Map<String, Object> context);
51+
Map<String, @Nullable Object> execute(Map<String, Object> context);
5252
}

bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/RuleEngineImpl.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public class RuleEngineImpl implements RuleManager, RegistryChangeListener<Modul
181181
* The context map of a {@link Rule} is cleaned when the execution is completed. The relation is
182182
* {@link Rule}'s UID to Rule context map.
183183
*/
184-
private final Map<String, Map<String, Object>> contextMap = new ConcurrentHashMap<>();
184+
private final Map<String, Map<String, @Nullable Object>> contextMap = new ConcurrentHashMap<>();
185185

186186
/**
187187
* This field holds reference to {@link ModuleTypeRegistry}. The {@link RuleEngineImpl} needs it to auto-map
@@ -1089,9 +1089,9 @@ protected void runRule(String ruleUID, TriggerHandlerCallbackImpl.TriggerData td
10891089
}
10901090

10911091
@Override
1092-
public Map<String, Object> runNow(String ruleUID, boolean considerConditions,
1092+
public Map<String, @Nullable Object> runNow(String ruleUID, boolean considerConditions,
10931093
@Nullable Map<String, Object> context) {
1094-
Map<String, Object> returnContext = new HashMap<>();
1094+
Map<String, @Nullable Object> returnContext = new HashMap<>();
10951095
final WrappedRule rule = getManagedRule(ruleUID);
10961096
if (rule == null) {
10971097
logger.warn("Failed to execute rule '{}': Invalid Rule UID", ruleUID);
@@ -1129,7 +1129,7 @@ public Map<String, Object> runNow(String ruleUID, boolean considerConditions,
11291129
}
11301130

11311131
@Override
1132-
public Map<String, Object> runNow(String ruleUID) {
1132+
public Map<String, @Nullable Object> runNow(String ruleUID) {
11331133
return runNow(ruleUID, false, null);
11341134
}
11351135

@@ -1139,7 +1139,7 @@ public Map<String, Object> runNow(String ruleUID) {
11391139
* @param ruleUID the UID of the rule whose context must be cleared.
11401140
*/
11411141
protected void clearContext(String ruleUID) {
1142-
Map<String, Object> context = contextMap.get(ruleUID);
1142+
Map<String, @Nullable Object> context = contextMap.get(ruleUID);
11431143
if (context != null) {
11441144
context.clear();
11451145
}
@@ -1163,7 +1163,7 @@ private void setTriggerOutputs(String ruleUID, TriggerData td) {
11631163
* @param outputs new output values.
11641164
*/
11651165
private void updateContext(String ruleUID, String moduleUID, @Nullable Map<String, ?> outputs) {
1166-
Map<String, Object> context = getContext(ruleUID, null);
1166+
Map<String, @Nullable Object> context = getContext(ruleUID, null);
11671167
if (outputs != null) {
11681168
for (Map.Entry<String, ?> entry : outputs.entrySet()) {
11691169
String key = moduleUID + OUTPUT_SEPARATOR + entry.getKey();
@@ -1175,8 +1175,8 @@ private void updateContext(String ruleUID, String moduleUID, @Nullable Map<Strin
11751175
/**
11761176
* @return copy of current context in rule engine
11771177
*/
1178-
private Map<String, Object> getContext(String ruleUID, @Nullable Set<Connection> connections) {
1179-
Map<String, Object> context = contextMap.computeIfAbsent(ruleUID, k -> new HashMap<>());
1178+
private Map<String, @Nullable Object> getContext(String ruleUID, @Nullable Set<Connection> connections) {
1179+
Map<String, @Nullable Object> context = contextMap.computeIfAbsent(ruleUID, k -> new HashMap<>());
11801180
if (context == null) {
11811181
throw new IllegalStateException("context cannot be null at that point - please report a bug.");
11821182
}
@@ -1257,7 +1257,7 @@ private boolean calculateConditions(WrappedRule rule) {
12571257
}
12581258
final Condition condition = wrappedCondition.unwrap();
12591259
ConditionHandler tHandler = wrappedCondition.getModuleHandler();
1260-
Map<String, Object> context = getContext(ruleUID, wrappedCondition.getConnections());
1260+
Map<String, @Nullable Object> context = getContext(ruleUID, wrappedCondition.getConnections());
12611261
if (tHandler != null && !tHandler.isSatisfied(Collections.unmodifiableMap(context))) {
12621262
logger.debug("The condition '{}' of rule '{}' is unsatisfied.", condition.getId(), ruleUID);
12631263
return false;
@@ -1312,9 +1312,9 @@ private void executeActions(WrappedRule rule, boolean stopOnFirstFail) {
13121312
final Action action = wrappedAction.unwrap();
13131313
ActionHandler aHandler = wrappedAction.getModuleHandler();
13141314
if (aHandler != null) {
1315-
Map<String, Object> context = getContext(ruleUID, wrappedAction.getConnections());
1315+
Map<String, @Nullable Object> context = getContext(ruleUID, wrappedAction.getConnections());
13161316
try {
1317-
Map<String, ?> outputs = aHandler.execute(Collections.unmodifiableMap(context));
1317+
Map<String, @Nullable ?> outputs = aHandler.execute(Collections.unmodifiableMap(context));
13181318
if (outputs != null) {
13191319
context = getContext(ruleUID, null);
13201320
updateContext(ruleUID, action.getId(), outputs);

bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/composite/CompositeActionHandler.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,17 @@ public CompositeActionHandler(Action action, CompositeActionType mt,
6464
* @see org.openhab.core.automation.handler.ActionHandler#execute(java.util.Map)
6565
*/
6666
@Override
67-
public @Nullable Map<String, Object> execute(Map<String, Object> context) {
68-
final Map<String, Object> result = new HashMap<>();
67+
public @Nullable Map<String, @Nullable Object> execute(Map<String, Object> context) {
68+
final Map<String, @Nullable Object> result = new HashMap<>();
6969
final List<Action> children = getChildren();
7070
final Map<String, Object> compositeContext = getCompositeContext(context);
7171
for (Action child : children) {
7272
ActionHandler childHandler = moduleHandlerMap.get(child);
7373
Map<String, Object> childContext = Collections.unmodifiableMap(getChildContext(child, compositeContext));
74-
Map<String, Object> childResults = childHandler == null ? null : childHandler.execute(childContext);
74+
Map<String, @Nullable Object> childResults = childHandler == null ? null
75+
: childHandler.execute(childContext);
7576
if (childResults != null) {
76-
for (Entry<String, Object> childResult : childResults.entrySet()) {
77+
for (Entry<String, @Nullable Object> childResult : childResults.entrySet()) {
7778
String childOuputName = child.getId() + "." + childResult.getKey();
7879
Output output = compositeOutputs.get(childOuputName);
7980
if (output != null) {

bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/AnnotationActionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public AnnotationActionHandler(Action module, ActionType mt, Method method, Obje
7070
}
7171

7272
@Override
73-
public @Nullable Map<String, Object> execute(Map<String, Object> context) {
74-
Map<String, Object> output = new HashMap<>();
73+
public @Nullable Map<String, @Nullable Object> execute(Map<String, Object> context) {
74+
Map<String, @Nullable Object> output = new HashMap<>();
7575

7676
Annotation[][] annotations = method.getParameterAnnotations();
7777
List<@Nullable Object> args = new ArrayList<>();

0 commit comments

Comments
 (0)