jenkinsci / jenkinsci/java-client-api

NullPointerException after calling triggerJobAndWaitUntilFinished

Ouverte
#440 4 commentaires 5 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Java
Étoiles
913
Forks
466
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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`:

![image](https://user-images.githubusercontent.com/16045549/69827711-d4631600-1218-11ea-91ff-6189013ee671.png)

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)

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par lire Job.java autour de build et de MapEntryToQueryStringPair, puis suivez les deux surcharges de JenkinsTriggerHelper.triggerJobAndWaitUntilFinished et de JenkinsServer.getBuild. Reproduisez l’appel avec un paramètre null et lorsque queueItem devient null. C’est terminé lorsque les cas d’échec produisent un résultat descriptif ou une exception au lieu d’une NullPointerException inexpliquée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
java
Domaine
api, backend
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
38/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.