Skip to content

[JENKINS-57093] Fix NPE in formvalidation if no job property configured #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import hudson.model.ParametersDefinitionProperty;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.parameterizedscheduler.Messages;
Expand Down Expand Up @@ -47,9 +47,9 @@ public String checkSanity(String cronTabSpec, ParametersDefinitionProperty param
if (split.length == 2) {
try {
Map<String, String> parsedParameters = parse(split[1]);
List<String> parameterDefinitionNames = parametersDefinitionProperty.getParameterDefinitionNames();
List<String> parsedKeySet = new ArrayList<>(parsedParameters.keySet());
parsedKeySet.removeAll(parameterDefinitionNames);
List<String> parameterDefinitionNames = parametersDefinitionProperty != null
? parametersDefinitionProperty.getParameterDefinitionNames() : Collections.emptyList();
List<String> parsedKeySet = parsedParameters.keySet().stream().filter(s -> !parameterDefinitionNames.contains(s)).collect(Collectors.toList());
if (!parsedKeySet.isEmpty()) {
return Messages.ParameterizedTimerTrigger_UndefinedParameter(parsedKeySet, parameterDefinitionNames);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.jenkinsci.plugins.parameterizedscheduler;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import hudson.model.ParametersDefinitionProperty;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -153,8 +155,14 @@ public void checkSanity_duplicateParamName() throws Exception {
@Test
public void checkSanity_UnmatchedEquals() throws Exception {
ParameterParser testObject = new ParameterParser();

testObject.checkSanity("* * * * *%name=value;name2=", mockParametersDefinitionProperty);
}

@Test
public void checkSanity_NullParameters() throws Exception {
ParameterParser testObject = new ParameterParser();
assertEquals(Messages.ParameterizedTimerTrigger_UndefinedParameter(Collections.singletonList("name"), Collections.emptyList()),
testObject.checkSanity("* * * * *%name=value", null));
}

}