Source:
<code>void cleanCachesIfFlagSet( String root ) throws IOException { logger.info( "Checking to see if " + CLEAN_KARAF_CACHE + " is enabled" ); final Properties customProperties = getCustomProperties( root ); String cleanCache = customProperties.getProperty( CLEAN_KARAF_CACHE, "false" ); if ( "true".equals( cleanCache ) ) { logger.info( CLEAN_KARAF_CACHE + " is enabled. Karaf data directories will be deleted" ); File cacheParent = new File( root + "/caches" ); File[] clientCacheFolders = cacheParent.listFiles( directoryFilter ); for ( File clientCacheFolder : clientCacheFolders ) { File[] cacheDirs = clientCacheFolder.listFiles( directoryFilter ); for ( File cacheDir : cacheDirs ) { File lockFile = new File( cacheDir, ".lock" ); FileOutputStream fileOutputStream = new FileOutputStream( lockFile ); try { FileLock fileLock = fileOutputStream.getChannel().tryLock(); fileLock.release(); IOUtils.closeQuietly( fileOutputStream ); FileUtils.deleteDirectory( cacheDir ); } catch ( Exception ignored ) { } finally { IOUtils.closeQuietly( fileOutputStream ); } } } customProperties.setProperty( CLEAN_KARAF_CACHE, "false" ); FileOutputStream out = null; try { final String customLocation = root + "/etc/custom.properties"; out = new FileOutputStream( customLocation ); logger.info( "Setting " + CLEAN_KARAF_CACHE + " back to false as this is a one-time action" ); customProperties.store( out, "Turning of one-time cache clean setting" ); } finally { <START> this.karafCustomProperties = customProperties; <END> if ( out != null ) { IOUtils.closeQuietly( out ); } } } }</code><technical_language>needed getCustomProperties() returns exact reference... customProperties.setProperty( CLEAN_KARAF_CACHE, "false" ) changed this.karafCustomProperties. this.karafCustomProperties everywhere, ensuring instantiated top of startup() method. needed (there is code path /etc/custom.properties read), startup() is responsible for setting tearing down</technical_language>

Target:
void cleanCachesIfFlagSet( String root ) throws IOException { logger.info( "Checking to see if " + CLEAN_KARAF_CACHE + " is enabled" ); String cleanCache = this.karafCustomProperties.getProperty( CLEAN_KARAF_CACHE, "false" ); if ( "true".equals( cleanCache ) ) { logger.info( CLEAN_KARAF_CACHE + " is enabled. Karaf data directories will be deleted" ); File cacheParent = new File( root + "/caches" ); File[] clientCacheFolders = cacheParent.listFiles( directoryFilter ); for ( File clientCacheFolder : clientCacheFolders ) { File[] cacheDirs = clientCacheFolder.listFiles( directoryFilter ); for ( File cacheDir : cacheDirs ) { File lockFile = new File( cacheDir, ".lock" ); FileOutputStream fileOutputStream = new FileOutputStream( lockFile ); try { FileLock fileLock = fileOutputStream.getChannel().tryLock(); fileLock.release(); IOUtils.closeQuietly( fileOutputStream ); FileUtils.deleteDirectory( cacheDir ); } catch ( Exception ignored ) { } finally { IOUtils.closeQuietly( fileOutputStream ); } } } this.karafCustomProperties.setProperty( CLEAN_KARAF_CACHE, "false" ); FileOutputStream out = null; try { final String customLocation = root + "/etc/custom.properties"; out = new FileOutputStream( customLocation ); logger.info( "Setting " + CLEAN_KARAF_CACHE + " back to false as this is a one-time action" ); this.karafCustomProperties.store( out, "Turning of one-time cache clean setting" ); } finally { if ( out != null ) { IOUtils.closeQuietly( out ); } } } }