Skip to content

Commit

Permalink
Fixed NPE when commands not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
retrodaredevil committed Aug 10, 2020
1 parent 1106743 commit 6be0aac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package me.retrodaredevil.solarthing.config.options;

import com.fasterxml.jackson.annotation.JsonProperty;
import me.retrodaredevil.solarthing.annotations.NotNull;
import me.retrodaredevil.solarthing.annotations.Nullable;
import me.retrodaredevil.solarthing.commands.CommandInfo;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public interface CommandOption {
List<Command> getDeclaredCommands();
@Nullable List<Command> getDeclaredCommandsNullable();
default @NotNull List<Command> getDeclaredCommands() {
List<Command> commands = getDeclaredCommandsNullable();
if (commands == null) {
return Collections.emptyList();
}
return commands;
}

default Map<String, File> getCommandFileMap() {
Map<String, File> commandFileMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MateProgramOptions extends PacketHandlingOptionBase implements IOBu


@Override
public List<Command> getDeclaredCommands() {
public @Nullable List<Command> getDeclaredCommandsNullable() {
return commands;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import me.retrodaredevil.solarthing.annotations.Nullable;

import java.io.File;
import java.util.List;
Expand All @@ -25,7 +26,7 @@ public class RoverProgramOptions extends RequestProgramOptionsBase implements Ro
private List<Command> commands;

@Override
public List<Command> getDeclaredCommands() {
public @Nullable List<Command> getDeclaredCommandsNullable() {
return commands;
}

Expand Down

0 comments on commit 6be0aac

Please sign in to comment.