jenkinsci / jenkinsci/java-client-api
NullPointerException after calling triggerJobAndWaitUntilFinished
- Lenguaje dominante
- Java
- Estrellas
- 913
- Forks
- 466
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
When I call `triggerJobAndWaitUntilFinished()` I get an NPE:
```
java.lang.NullPointerException: null
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:878) ~[guava-28.1-jre.jar:na]
at com.google.common.net.PercentEscaper.escape(PercentEscaper.java:145) ~[guava-28.1-jre.jar:na]
at com.offbytwo.jenkins.model.Job$MapEntryToQueryStringPair.apply(Job.java:185) ~[jenkins-client-0.3.8.jar:0.3.8]
at com.offbytwo.jenkins.model.Job$MapEntryToQueryStringPair.apply(Job.java:181) ~[jenkins-client-0.3.8.jar:0.3.8]
at com.google.common.collect.Iterators$6.transform(Iterators.java:783) ~[guava-28.1-jre.jar:na]
at com.google.common.collect.TransformedIterator.next(TransformedIterator.java:47) ~[guava-28.1-jre.jar:na]
at org.apache.commons.lang.StringUtils.join(StringUtils.java:2831) ~[commons-lang-2.3.jar:2.3]
at org.apache.commons.lang.StringUtils.join(StringUtils.java:2878) ~[commons-lang-2.3.jar:2.3]
at com.offbytwo.jenkins.model.Job.build(Job.java:150) ~[jenkins-client-0.3.8.jar:0.3.8]
at com.offbytwo.jenkins.model.Job.build(Job.java:125) ~[jenkins-client-0.3.8.jar:0.3.8]
at com.offbytwo.jenkins.JenkinsTriggerHelper.triggerJobAndWaitUntilFinished(JenkinsTriggerHelper.java:88) ~[jenkins-client-0.3.8.jar:0.3.8]
...
```
The stacktrace was truncated because the other lines only show my code.
In my code I basically do this:
Map params = new HashMap<>();
params.put("identifier", command.getIdentifier());
...
BuildWithDetails details = null;
try {
details = th.triggerJobAndWaitUntilFinished(jp.getJob(), params, true);
} catch (HttpResponseException e) {
log.warn("You were denied by Jenkins. Please check user and password used", e);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (NullPointerException e) {
log.warn("It looks like calling job {} failed. Value of details: {}", jp.getJob(), details, e);
}
I already forced the use of a current version of Guava because by default v17 was chosen. After checking the `params` I found out that in some situations one of the parameters turns `null`. And this causes the library to fail.
Is it possible to have the library return a descriptive error message in such situations ?
But even after I fixed this and made sure only to call the method when no null values are inside the map, the call fails with another NPE:
```
java.lang.NullPointerException: null
at com.offbytwo.jenkins.JenkinsServer.getBuild(JenkinsServer.java:824) ~[jenkins-client-0.3.8.jar:0.3.8]
at com.offbytwo.jenkins.JenkinsTriggerHelper.triggerJobAndWaitUntilFinished(JenkinsTriggerHelper.java:178) ~[jenkins-client-0.3.8.jar:0.3.8]
at com.offbytwo.jenkins.JenkinsTriggerHelper.triggerJobAndWaitUntilFinished(JenkinsTriggerHelper.java:90) ~[jenkins-client-0.3.8.jar:0.3.8]
...
```
I tried to debug this but all I could find out is that here the `queueItem` becomes `null`:

When checking the Jenkins job I can see that it was created (it failed with exit code 6 due to some other reasons, but it was created and ran)
Guía de contribución
Línea de trabajo
Start by reading Job.java around build and MapEntryToQueryStringPair, then follow both overloads of JenkinsTriggerHelper.triggerJobAndWaitUntilFinished and JenkinsServer.getBuild. Reproduce the call with a null parameter and with the queueItem becoming null. Done means the failure cases produce a descriptive result or exception instead of an unexplained NullPointerException.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- java
- Área
- api, backend
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 38/100