Skip to content
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

Conversation

MarkEWaite
Copy link
Contributor

@MarkEWaite MarkEWaite commented May 6, 2017

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

[JENKINS-44087] detected a null pointer exception in the git parameters
plugin when it was used before the first run of a job.
@MarkEWaite MarkEWaite requested a review from a user May 6, 2017 12:35
@MarkEWaite MarkEWaite changed the title Only track project credentials if last build exists [JENKINS-44087] Only track project credentials if last build exists May 6, 2017
@ghost
Copy link

ghost commented May 6, 2017

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.

Copy link
Member

@jglick jglick left a 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) {
Copy link
Member

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);
Copy link
Member

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.

@jglick
Copy link
Member

jglick commented May 9, 2017

Seems like this should have been easily reproduced in a functional test, no?

@MarkEWaite
Copy link
Contributor Author

@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?

@jglick
Copy link
Member

jglick commented May 9, 2017

Just general advice. At least my own practice is to start with trying to reproduce such bugs with a JenkinsRule test. Once you get a little practice and some infrastructure in place, it is as fast or faster than reproducing manually. And certainly it is better to have regular JUnit tests in the repository like every other plugin (run on PR builds, by plugin-compat-tester, etc. etc.) than a separate testing system. (Though there are always going to be some weird cases which cannot be reproduced properly even using DockerFixture.)

@MarkEWaite
Copy link
Contributor Author

MarkEWaite commented May 9, 2017

I like your advice very much. My general pattern has been

  1. Duplicate the bug interactively so that I can see what the user sees, and confirm that I've understood the problem in the user context
  2. Investigate the code to understand what is happening in that area
  3. Write tests (unit tests first preference, JenkinsRule second) which show the problem
  4. Fix the problem, confirm the tests pass
  5. Interactively confirm the fixed code works as expected and doesn't surprise in other areas

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.

@MarkEWaite MarkEWaite merged commit 9daa4dd into jenkinsci:master May 20, 2017
@MarkEWaite MarkEWaite deleted the master-JENKINS-44087-NPE-before-first-build branch May 20, 2017 00:45
@MarkEWaite MarkEWaite added the bugfix Fixes a bug - used by Release Drafter label Jul 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes a bug - used by Release Drafter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants