jenkinsci/jenkins — pull request #928 by olivierdagenais (2013-08-29 20:24:46+00:00)
Title: Fix random HTTP 404 when viewing build details

I found this defect when I noticed API calls (such as `/job/doStuff/17/api/xml`) failing "randomly" with HTTP 404. The thing is, you then open a browser to `/job/doStuff` and API calls would start working again. And it would only happen to some jobs and not others, but not always the same jobs.

Attaching a debugger to the running instance where this happened, I eventually was able to trace the defect to the `search()` method of the `AbstractLazyLoadRunMap` class, where it was able to obtain a "ceiling" entry that had a `BuildReference` with a null `referent`, which then hit all the right conditions for the method to return `null` even though the requested build number indeed existed. A `SoftReference` helps explain why this would occur "randomly" and then suddenly start working again after visiting the job's page, which would [re-]load all the builds.

I was also able to craft a unit test that reproduces this condition exactly. See the `searchExactWhenIndexedButSoftReferenceExpired()` method.

From what I can tell, this corner case has been missing since commit cf85b72036769549a2221a4c81789552d953006e

Let me know if there's anything you would like me to change/improve.