hudson/hudson — pull request #355 by mcculls (2012-05-24 18:48:17+00:00)
Title: Avoid accidental unlink of cascading parent when security is enabled

1. Create new job C using admin account and cascade from an existing job P
2. Save C and give configure (and read) permission to user who cannot see P
3. Login as that user and try to update C, for example by adding a build step

You get following exception:

java.lang.NullPointerException
hudson.util.CascadingUtil.unlinkProjectFromCascadingParents(CascadingUtil.java:310)
hudson.model.Job.clearCascadingProject(Job.java:1820)
hudson.model.Job.setCascadingProjectName(Job.java:1769)
hudson.model.Job.submit(Job.java:1433)

This is because when jelly rendered the project configuration it called getCascadingParents, which returned a list that did not contain the current parent because it was not visible to the current user.

The solution contains two fixes - one avoids NPEs when the current parent is unavailable, the other uses a hidden entry to keep the current parent when there are no visible alternatives. Note getCascadingParents is also modified to return an empty list for the specific situation where the project has a valid parent, but it is not visible to the current user. In this scenario it does not make sense to give the user an option to change or remove the parent, as they would not be able to change it back. Instead we assume that they should be unaware of the actual parent, and therefore return the empty list which then triggers the hidden entry.