Buggy code:
public class TestSolrXmlPersistence extends SolrTestCaseJ4 { private final File solrHomeDirectory = new File ( TEMP_DIR , this . getClass ( ) . getName ( ) ) ; @ BeforeClass public static void beforeClass ( ) throws Exception { } @ Rule public TestRule solrTestRules = RuleChain . outerRule ( new SystemPropertiesRestoreRule ( ) ) ; private CoreContainer init ( String solrXmlString , String ... subDirs ) throws Exception { } @ Test public void testSystemVars ( ) throws Exception { } @ Test public void testReload ( ) throws Exception { } private void doReloadTest ( String which ) throws Exception { } @ Test public void testRename ( ) throws Exception { } private void doTestRename ( String which ) throws Exception { } @ Test public void testSwap ( ) throws Exception { } private void doTestSwap ( String from , String to ) throws Exception { } @ Test public void testMinimalXml ( ) throws Exception { } @ Test public void testUnloadCreate ( ) throws Exception { } private void doTestUnloadCreate ( String which ) throws Exception { } private void persistContainedInOrig ( CoreContainer cc , File persistXml ) throws IOException , ParserConfigurationException , SAXException { } private void origContainedInPersist ( CoreContainer cc , File persistXml ) throws IOException , ParserConfigurationException , SAXException { } @ Test public void testCreateAndManipulateCores ( ) throws Exception { CoreContainer cc = init ( TestSolrXmlPersistence . SOLR_XML_LOTS_SYSVARS , "SystemVars1" , "SystemVars2" , "new_one" , "new_two" ) ; try { final CoreAdminHandler admin = new CoreAdminHandler ( cc ) ; String instPathOne = new File ( solrHomeDirectory , "new_one" ) . getAbsolutePath ( ) ; SolrQueryResponse resp = new SolrQueryResponse ( ) ; admin . handleRequestBody ( req ( ACTION , CREATE . toString ( ) , INSTANCE_DIR , instPathOne , NAME , "new_one" ) , resp ) ; assertNull ( "Exception<seq2seq4repair_space>on<seq2seq4repair_space>create" , resp . getException ( ) ) ; admin . handleRequestBody ( req ( ACTION , CREATE . toString ( ) , NAME , "new_two" ) , resp ) ; assertNull ( "Exception<seq2seq4repair_space>on<seq2seq4repair_space>create" , resp . getException ( ) ) ; File persistXml1 = new File ( solrHomeDirectory , "create_man_1.xml" ) ; origContainedInPersist ( cc , persistXml1 ) ; String [ ] expressions = new String [ 2 ] ; String instHome = new File ( solrHomeDirectory , "new_one" ) . getAbsolutePath ( ) ; expressions [ 0 ] = ( "//solr//cores//core[@name='new_one'<seq2seq4repair_space>and<seq2seq4repair_space>@instanceDir='" + instHome ) + "']" ; <START_BUG> expressions [ 1 ] = "//solr//cores//core[@name='new_two'<seq2seq4repair_space>and<seq2seq4repair_space>@instanceDir='new_two//']" ; <END_BUG> assertXmlFile ( persistXml1 , expressions ) ; resp = new SolrQueryResponse ( ) ; admin . handleRequestBody ( req ( ACTION , SWAP . toString ( ) , CORE , "new_one" , OTHER , "SystemVars2" ) , resp ) ; assertNull ( "Exception<seq2seq4repair_space>on<seq2seq4repair_space>swap" , resp . getException ( ) ) ; File persistXml2 = new File ( solrHomeDirectory , "create_man_2.xml" ) ; cc . persistFile ( persistXml2 ) ; String [ ] persistList = getAllNodes ( persistXml2 ) ; expressions = new String [ persistList . length ] ; for ( int idx = 0 ; idx < ( persistList . length ) ; ++ idx ) { String fromName = "@name='new_one'" ; String toName = "@name='SystemVars2'" ; if ( persistList [ idx ] . contains ( fromName ) ) { expressions [ idx ] = persistList [ idx ] . replace ( fromName , toName ) ; } else { expressions [ idx ] = persistList [ idx ] . replace ( toName , fromName ) ; } } assertXmlFile ( persistXml1 , expressions ) ; admin . handleRequestBody ( req ( ACTION , RENAME . toString ( ) , CORE , "new_two" , OTHER , "RenamedCore" ) , resp ) ; assertNull ( "Exception<seq2seq4repair_space>on<seq2seq4repair_space>rename" , resp . getException ( ) ) ; File persistXml3 = new File ( solrHomeDirectory , "create_man_3.xml" ) ; cc . persistFile ( persistXml3 ) ; persistList = getAllNodes ( persistXml3 ) ; expressions = new String [ persistList . length ] ; for ( int idx = 0 ; idx < ( persistList . length ) ; ++ idx ) { expressions [ idx ] = persistList [ idx ] . replaceAll ( "RenamedCore" , "new_two" ) ; } assertXmlFile ( persistXml2 , expressions ) ; persistList = getAllNodes ( persistXml2 ) ; expressions = new String [ persistList . length ] ; for ( int idx = 0 ; idx < ( persistList . length ) ; ++ idx ) { expressions [ idx ] = persistList [ idx ] . replace ( "@name='new_two'" , "@name='RenamedCore'" ) ; } assertXmlFile ( persistXml3 , expressions ) ; } finally { cc . shutdown ( ) ; if ( solrHomeDirectory . exists ( ) ) { FileUtils . deleteDirectory ( solrHomeDirectory ) ; } } } @ Test public void testCreatePersistCore ( ) throws Exception { } private String [ ] getAllNodes ( File xmlFile ) throws IOException , ParserConfigurationException , SAXException { } private static List < String > qualified = new ArrayList < String > ( ) { } ; private static List < String > addText = new ArrayList < String > ( ) { } ; private void gatherNodes ( Node node , List < String > expressions , String path ) { } private static String SOLR_XML_LOTS_SYSVARS = "<solr<seq2seq4repair_space>persistent=\"${solr.xml.persist:false}\"<seq2seq4repair_space>coreLoadThreads=\"12\"<seq2seq4repair_space>sharedLib=\"${something:.}\"<seq2seq4repair_space>>\n" + ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( "<seq2seq4repair_space><logging<seq2seq4repair_space>class=\"${logclass:log4j.class}\"<seq2seq4repair_space>enabled=\"{logenable:true}\">\n" + "<seq2seq4repair_space><watcher<seq2seq4repair_space>size=\"{watchSize:13}\"<seq2seq4repair_space>threshold=\"${logThresh:54}\"<seq2seq4repair_space>//>\n" ) + "<seq2seq4repair_space><//logging>\n" ) + "<seq2seq4repair_space><shardHandlerFactory<seq2seq4repair_space>name=\"${shhandler:shardHandlerFactory}\"<seq2seq4repair_space>class=\"${handlefac:HttpShardHandlerFactory}\">\n" ) + "<seq2seq4repair_space><int<seq2seq4repair_space>name=\"socketTimeout\">${socketTimeout:120000}<//int><seq2seq4repair_space>\n" ) + "<seq2seq4repair_space><int<seq2seq4repair_space>name=\"connTimeout\">${connTimeout:15000}<//int><seq2seq4repair_space>\n" ) + "<seq2seq4repair_space><//shardHandlerFactory><seq2seq4repair_space>\n" ) + "<seq2seq4repair_space><cores<seq2seq4repair_space>adminPath=\"//admin//cores\"<seq2seq4repair_space>defaultCoreName=\"SystemVars1\"<seq2seq4repair_space>host=\"127.0.0.1\"<seq2seq4repair_space>\n" ) + "<seq2seq4repair_space>hostPort=\"${hostPort:8983}\"<seq2seq4repair_space>hostContext=\"${hostContext:solr}\"<seq2seq4repair_space>\n" ) + "<seq2seq4repair_space>zkClientTimeout=\"${solr.zkclienttimeout:30000}\"<seq2seq4repair_space>\n" ) + "<seq2seq4repair_space>shareSchema=\"${shareSchema:false}\"<seq2seq4repair_space>distribUpdateConnTimeout=\"${distribUpdateConnTimeout:15000}\"<seq2seq4repair_space>\n" ) + "<seq2seq4repair_space>distribUpdateSoTimeout=\"${distribUpdateSoTimeout:120000}\"<seq2seq4repair_space>\n" ) + "<seq2seq4repair_space>leaderVoteWait=\"${leadVoteWait:32}\"<seq2seq4repair_space>managementPath=\"${manpath://var//lib//path}\"<seq2seq4repair_space>transientCacheSize=\"${tranSize:128}\"><seq2seq4repair_space>\n" ) + "<seq2seq4repair_space><core<seq2seq4repair_space>name=\"SystemVars1\"<seq2seq4repair_space>instanceDir=\"SystemVars1\"<seq2seq4repair_space>shard=\"${shard:32}\"<seq2seq4repair_space>\n" ) + "<seq2seq4repair_space>collection=\"${collection:collection1}\"<seq2seq4repair_space>config=\"${solrconfig:solrconfig.xml}\"<seq2seq4repair_space>\n" ) + "<seq2seq4repair_space>schema=\"${schema:schema.xml}\"<seq2seq4repair_space>ulogDir=\"${ulog:.//}\"<seq2seq4repair_space>roles=\"${myrole:boss}\"<seq2seq4repair_space>\n" ) + "<seq2seq4repair_space>dataDir=\"${data:.//}\"<seq2seq4repair_space>loadOnStartup=\"${onStart:true}\"<seq2seq4repair_space>transient=\"${tran:true}\"<seq2seq4repair_space>\n" ) + "<seq2seq4repair_space>coreNodeName=\"${coreNode:utterlyridiculous}\"<seq2seq4repair_space>\n" ) + "<seq2seq4repair_space>>\n" ) + "<seq2seq4repair_space><//core>\n" ) + "<seq2seq4repair_space><core<seq2seq4repair_space>name=\"SystemVars2\"<seq2seq4repair_space>instanceDir=\"SystemVars2\"<seq2seq4repair_space>shard=\"${shard:32}\"<seq2seq4repair_space>\n" ) + "<seq2seq4repair_space>collection=\"${collection:collection2}\"<seq2seq4repair_space>config=\"${solrconfig:solrconfig.xml}\"<seq2seq4repair_space>\n" ) + "<seq2seq4repair_space>coreNodeName=\"${coreNodeName:}\"<seq2seq4repair_space>schema=\"${schema:schema.xml}\">\n" ) + "<seq2seq4repair_space><property<seq2seq4repair_space>name=\"collection\"<seq2seq4repair_space>value=\"{collection:collection2}\"//>\n" ) + "<seq2seq4repair_space><property<seq2seq4repair_space>name=\"schema\"<seq2seq4repair_space>value=\"${schema:schema.xml}\"//>\n"

Fix:
expressions [ 1 ] = ( "//solr//cores//core[@name='new_two'<seq2seq4repair_space>and<seq2seq4repair_space>@instanceDir='new_two" + ( File . separator ) ) + "']" ;