Buggy code:
sources . addBefore ( "b" , new MockPropertySource ( "a" ) ) ; sources . addAfter ( "b" , new MockPropertySource ( "c" ) ) ; assertThat ( sources . size ( ) , equalTo ( 5 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "a" ) ) , is ( 0 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "b" ) ) , is ( 1 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "c" ) ) , is ( 2 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "d" ) ) , is ( 3 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "f" ) ) , is ( 4 ) ) ; sources . addBefore ( "f" , new MockPropertySource ( "e" ) ) ; sources . addAfter ( "f" , new MockPropertySource ( "g" ) ) ; assertThat ( sources . size ( ) , equalTo ( 7 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "a" ) ) , is ( 0 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "b" ) ) , is ( 1 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "c" ) ) , is ( 2 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "d" ) ) , is ( 3 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "e" ) ) , is ( 4 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "f" ) ) , is ( 5 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "g" ) ) , is ( 6 ) ) ; sources . addLast ( new MockPropertySource ( "a" ) ) ; assertThat ( sources . size ( ) , equalTo ( 7 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "b" ) ) , is ( 0 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "c" ) ) , is ( 1 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "d" ) ) , is ( 2 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "e" ) ) , is ( 3 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "f" ) ) , is ( 4 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "g" ) ) , is ( 5 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "a" ) ) , is ( 6 ) ) ; sources . addFirst ( new MockPropertySource ( "a" ) ) ; assertThat ( sources . size ( ) , equalTo ( 7 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "a" ) ) , is ( 0 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "b" ) ) , is ( 1 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "c" ) ) , is ( 2 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "d" ) ) , is ( 3 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "e" ) ) , is ( 4 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "f" ) ) , is ( 5 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "g" ) ) , is ( 6 ) ) ; assertEquals ( sources . remove ( "a" ) , PropertySource . named ( "a" ) ) ; assertThat ( sources . size ( ) , equalTo ( 6 ) ) ; assertThat ( sources . contains ( "a" ) , is ( false ) ) ; <START_BUG> assertEquals ( sources . remove ( "a" ) , null ) ; <END_BUG> assertThat ( sources . size ( ) , equalTo ( 6 ) ) ; String bogusPS = "bogus" ; try { sources . addAfter ( bogusPS , new MockPropertySource ( "h" ) ) ; fail ( "expected<seq2seq4repair_space>non-existent<seq2seq4repair_space>PropertySource<seq2seq4repair_space>exception" ) ; } catch ( IllegalArgumentException ex ) { assertTrue ( ex . getMessage ( ) . contains ( "does<seq2seq4repair_space>not<seq2seq4repair_space>exist" ) ) ; } sources . addFirst ( new MockPropertySource ( "a" ) ) ; assertThat ( sources . size ( ) , equalTo ( 7 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "a" ) ) , is ( 0 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "b" ) ) , is ( 1 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "c" ) ) , is ( 2 ) ) ; sources . replace ( "a" , new MockPropertySource ( "a-replaced" ) ) ; assertThat ( sources . size ( ) , equalTo ( 7 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "a-replaced" ) ) , is ( 0 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "b" ) ) , is ( 1 ) ) ; assertThat ( sources . precedenceOf ( PropertySource . named ( "c" ) ) , is ( 2 ) ) ; sources . replace ( "a-replaced" , new MockPropertySource ( "a" ) ) ; try { sources . replace ( bogusPS , new MockPropertySource ( "bogus-replaced" ) ) ; fail ( "expected<seq2seq4repair_space>non-existent<seq2seq4repair_space>PropertySource<seq2seq4repair_space>exception" ) ;

Fix:
assertNull ( sources . remove ( "a" ) ) ;