refactor: 添加对参数的非空检查.

添加非空检查以在执行操作前将其拦截.
This commit is contained in:
LamGC 2021-08-20 00:33:12 +08:00
parent e54a9513df
commit 8bd55ca2e4
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D

View File

@ -6,6 +6,7 @@ import net.lamgc.oracle.sentry.script.groovy.trigger.TriggerName;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -51,6 +52,7 @@ public class GroovyTriggerProvider {
* @throws NoSuchElementException 当指定的 Trigger 名称没有对应 Trigger 时抛出该异常. * @throws NoSuchElementException 当指定的 Trigger 名称没有对应 Trigger 时抛出该异常.
*/ */
public GroovyTrigger getTriggerByName(String triggerName) { public GroovyTrigger getTriggerByName(String triggerName) {
Objects.requireNonNull(triggerName);
if (!triggerProviderMap.containsKey(triggerName.toLowerCase())) { if (!triggerProviderMap.containsKey(triggerName.toLowerCase())) {
throw new NoSuchElementException("The specified trigger could not be found: " + triggerName); throw new NoSuchElementException("The specified trigger could not be found: " + triggerName);
} }