Skip to content

Commit 2371e45

Browse files
SAY-5mymarche
authored andcommitted
fix: avoid NPE when displayExpression is null
1 parent d12ed3e commit 2371e45

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/main/java/io/jenkins/plugins/restlistparam/RestListParameterDefinition.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public RestListParameterDefinition(final String name,
7777
this.valueExpression = valueExpression;
7878
this.credentialId = credentialId != null && !credentialId.trim().isEmpty() ? credentialId : "";
7979
if (mimeType == MimeType.APPLICATION_JSON) {
80-
this.displayExpression = !displayExpression.isBlank() ? displayExpression : "$";
80+
this.displayExpression = displayExpression != null && !displayExpression.isBlank() ? displayExpression : "$";
8181
}
8282
this.defaultValue = defaultValue != null && !defaultValue.trim().isEmpty() ? defaultValue : "";
8383
this.valueOrder = valueOrder != null ? valueOrder : ValueOrder.NONE;
@@ -107,7 +107,7 @@ private RestListParameterDefinition(final String name,
107107
this.valueExpression = valueExpression;
108108
this.credentialId = credentialId != null && !credentialId.trim().isEmpty() ? credentialId : "";
109109
if (mimeType == MimeType.APPLICATION_JSON) {
110-
this.displayExpression = !displayExpression.isBlank() ? displayExpression : "$";
110+
this.displayExpression = displayExpression != null && !displayExpression.isBlank() ? displayExpression : "$";
111111
}
112112
this.defaultValue = defaultValue != null && !defaultValue.trim().isEmpty() ? defaultValue : "";
113113
this.valueOrder = valueOrder != null ? valueOrder : ValueOrder.NONE;
@@ -139,7 +139,7 @@ public String getFilter() {
139139

140140
public String getDisplayExpression() {
141141
if (mimeType == MimeType.APPLICATION_JSON) {
142-
return !displayExpression.isBlank() ? displayExpression : "$";
142+
return displayExpression != null && !displayExpression.isBlank() ? displayExpression : "$";
143143
}
144144
return "";
145145
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.jenkins.plugins.restlistparam;
2+
3+
import io.jenkins.plugins.restlistparam.model.MimeType;
4+
import org.junit.jupiter.api.Test;
5+
import org.jvnet.hudson.test.JenkinsRule;
6+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
@WithJenkins
11+
class RestListParameterDefinitionTest {
12+
13+
@Test
14+
void nullDisplayExpressionDefaultsToRoot(JenkinsRule r) {
15+
RestListParameterDefinition def = new RestListParameterDefinition(
16+
"PARAM", "desc", "https://example.com/api", null, MimeType.APPLICATION_JSON, "$.tags", null);
17+
assertEquals("$", def.getDisplayExpression());
18+
}
19+
20+
@Test
21+
void blankDisplayExpressionDefaultsToRoot(JenkinsRule r) {
22+
RestListParameterDefinition def = new RestListParameterDefinition(
23+
"PARAM", "desc", "https://example.com/api", null, MimeType.APPLICATION_JSON, "$.tags", " ");
24+
assertEquals("$", def.getDisplayExpression());
25+
}
26+
}

0 commit comments

Comments
 (0)