2424
2525package jenkins .model .lazy ;
2626
27- import static java .util .logging .Level .FINER ;
2827
2928import edu .umd .cs .findbugs .annotations .CheckForNull ;
3029import edu .umd .cs .findbugs .annotations .NonNull ;
4645import java .nio .file .Files ;
4746import java .util .ArrayList ;
4847import java .util .List ;
49- import java .util .Objects ;
5048import java .util .TreeMap ;
5149import java .util .logging .Level ;
5250import java .util .logging .Logger ;
@@ -194,7 +192,6 @@ public final synchronized RunT newBuild() throws IOException {
194192 return newBuild ();
195193 }
196194 builds .put (lastBuild );
197- lastBuild .getPreviousBuild (); // JENKINS-20662: create connection to previous build
198195 return lastBuild ;
199196 } catch (InvocationTargetException e ) {
200197 LOGGER .log (Level .WARNING , String .format ("A new build could not be created in job %s" , asJob ().getFullName ()), e );
@@ -334,32 +331,6 @@ public interface LazyLoadingRun<JobT extends Job<JobT, RunT> & Queue.Task & Lazy
334331 */
335332 public abstract static class RunMixIn <JobT extends Job <JobT , RunT > & Queue .Task & LazyBuildMixIn .LazyLoadingJob <JobT , RunT >, RunT extends Run <JobT , RunT > & LazyLoadingRun <JobT , RunT >> {
336333
337- /**
338- * Pointers to form bi-directional link between adjacent runs using
339- * {@link LazyBuildMixIn}.
340- *
341- * <p>
342- * Some {@link Run}s do lazy-loading, so we don't use
343- * {@link #previousBuildR} and {@link #nextBuildR}, and instead use these
344- * fields and point to {@link #selfReference} (or {@link #none}) of
345- * adjacent builds.
346- */
347- private volatile BuildReference <RunT > previousBuildR , nextBuildR ;
348-
349- /**
350- * Used in {@link #previousBuildR} and {@link #nextBuildR} to indicate
351- * that we know there is no next/previous build (as opposed to {@code null},
352- * which is used to indicate we haven't determined if there is a next/previous
353- * build.)
354- */
355- @ SuppressWarnings ({"unchecked" , "rawtypes" })
356- private static final BuildReference NONE = new BuildReference ("NONE" , null );
357-
358- @ SuppressWarnings ("unchecked" )
359- private BuildReference <RunT > none () {
360- return NONE ;
361- }
362-
363334 private BuildReference <RunT > selfReference ;
364335
365336 protected RunMixIn () {}
@@ -380,19 +351,6 @@ public final synchronized BuildReference<RunT> createReference() {
380351 * To implement {@link Run#dropLinks}.
381352 */
382353 public final void dropLinks () {
383- if (nextBuildR != null ) {
384- RunT nb = nextBuildR .get ();
385- if (nb != null ) {
386- nb .getRunMixIn ().previousBuildR = previousBuildR ;
387- }
388- }
389- if (previousBuildR != null ) {
390- RunT pb = previousBuildR .get ();
391- if (pb != null ) {
392- pb .getRunMixIn ().nextBuildR = nextBuildR ;
393- }
394- }
395-
396354 // make this build object unreachable by other Runs
397355 createReference ().clear ();
398356 }
@@ -401,69 +359,14 @@ public final void dropLinks() {
401359 * To implement {@link Run#getPreviousBuild}.
402360 */
403361 public final RunT getPreviousBuild () {
404- while (true ) {
405- BuildReference <RunT > r = previousBuildR ; // capture the value once
406-
407- if (r == null ) {
408- // having two neighbors pointing to each other is important to make RunMap.removeValue work
409- JobT _parent = Objects .requireNonNull (asRun ().getParent (), "no parent for " + asRun ().number );
410- RunT pb = _parent .getLazyBuildMixIn ()._getRuns ().search (asRun ().number - 1 , AbstractLazyLoadRunMap .Direction .DESC );
411- if (pb != null ) {
412- pb .getRunMixIn ().nextBuildR = createReference (); // establish bi-di link
413- this .previousBuildR = pb .getRunMixIn ().createReference ();
414- LOGGER .log (FINER , "Linked {0}<->{1} in getPreviousBuild()" , new Object []{this , pb });
415- return pb ;
416- } else {
417- this .previousBuildR = none ();
418- return null ;
419- }
420- }
421- if (r == none ()) {
422- return null ;
423- }
424-
425- RunT referent = r .get ();
426- if (referent != null ) {
427- return referent ;
428- }
429-
430- // the reference points to a GC-ed object, drop the reference and do it again
431- this .previousBuildR = null ;
432- }
362+ return asRun ().getParent ().getLazyBuildMixIn ()._getRuns ().search (asRun ().number - 1 , AbstractLazyLoadRunMap .Direction .DESC );
433363 }
434364
435365 /**
436366 * To implement {@link Run#getNextBuild}.
437367 */
438368 public final RunT getNextBuild () {
439- while (true ) {
440- BuildReference <RunT > r = nextBuildR ; // capture the value once
441-
442- if (r == null ) {
443- // having two neighbors pointing to each other is important to make RunMap.removeValue work
444- RunT nb = asRun ().getParent ().getLazyBuildMixIn ()._getRuns ().search (asRun ().number + 1 , AbstractLazyLoadRunMap .Direction .ASC );
445- if (nb != null ) {
446- nb .getRunMixIn ().previousBuildR = createReference (); // establish bi-di link
447- this .nextBuildR = nb .getRunMixIn ().createReference ();
448- LOGGER .log (FINER , "Linked {0}<->{1} in getNextBuild()" , new Object []{this , nb });
449- return nb ;
450- } else {
451- this .nextBuildR = none ();
452- return null ;
453- }
454- }
455- if (r == none ()) {
456- return null ;
457- }
458-
459- RunT referent = r .get ();
460- if (referent != null ) {
461- return referent ;
462- }
463-
464- // the reference points to a GC-ed object, drop the reference and do it again
465- this .nextBuildR = null ;
466- }
369+ return asRun ().getParent ().getLazyBuildMixIn ()._getRuns ().search (asRun ().number + 1 , AbstractLazyLoadRunMap .Direction .ASC );
467370 }
468371
469372 }
0 commit comments