-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[JENKINS-44087] Only track project credentials if last build exists #496
[JENKINS-44087] Only track project credentials if last build exists #496
Conversation
[JENKINS-44087] detected a null pointer exception in the git parameters plugin when it was used before the first run of a job.
This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amends #490 IIUC.
@@ -764,7 +764,9 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run<?, | |||
StandardUsernameCredentials credentials = CredentialsMatchers.firstOrNull(urlCredentials, idMatcher); | |||
if (credentials != null) { | |||
c.addCredentials(url, credentials); | |||
CredentialsProvider.track(project.getLastBuild(), credentials); | |||
if (project != null && project.getLastBuild() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If project
can really be null, should the parameter not be marked @CheckForNull
?
@@ -764,7 +764,9 @@ public GitClient createClient(TaskListener listener, EnvVars environment, Run<?, | |||
StandardUsernameCredentials credentials = CredentialsMatchers.firstOrNull(urlCredentials, idMatcher); | |||
if (credentials != null) { | |||
c.addCredentials(url, credentials); | |||
CredentialsProvider.track(project.getLastBuild(), credentials); | |||
if (project != null && project.getLastBuild() != null) { | |||
CredentialsProvider.track(project.getLastBuild(), credentials); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny race condition risk (the one remaining build could be deleted between these two lines). Safer to assign the lastBuild
to a local variable and check that for null.
Seems like this should have been easily reproduced in a functional test, no? |
@jglick I was definitely able to reproduce it in an interactive test, and have included that test in my jenkins-bugs-private repository so that it is regularly executed. I should also be able to reproduce it with a test in Java, but didn't want to take the time to write the Java test. Do you feel strongly that it needs a test in code, not just the verification test in my high level test harness? |
Just general advice. At least my own practice is to start with trying to reproduce such bugs with a |
I like your advice very much. My general pattern has been
In this case, I skipped step 3 due to the simplicity of the code change. I'll make my best effort to create a test that shows the problem, then can confirm that the code change fixes it. When I've skipped step 1 in the past, I've found that I wasted time in areas of the code that weren't relevant to the bug report. |
Git parameters plugin etected a null pointer exception when it was used before the first run of a job.
JENKINS-44087 describes the testing that has been performed. I've checked it interactively, Boguslaw has checked it interactively.
@reviewbybees