Source:
<code>public static void checkEnvironmentWithStorageExpansion( ServerConfiguration conf, RegistrationManager rm, List<File> journalDirectories, List<File> allLedgerDirs) throws BookieException { try { String instanceId = rm.getClusterInstanceId(); Cookie.Builder builder = Cookie.generateCookie(conf); if (null != instanceId) { builder.setInstanceId(instanceId); } Cookie masterCookie = builder.build(); boolean allowExpansion = conf.getAllowStorageExpansion(); List<BookieSocketAddress> possibleBookieIds = possibleBookieIds(conf); final Versioned<Cookie> rmCookie = readAndVerifyCookieFromRegistrationManager( masterCookie, rm, possibleBookieIds, allowExpansion); List<File> missedCookieDirs = new ArrayList<>(); List<Cookie> existingCookies = Lists.newArrayList(); if (null != rmCookie) { existingCookies .add(rmCookie.getValue()); } Pair<List<File>, List<Cookie>> journalResult = verifyAndGetMissingDirs(masterCookie, allowExpansion, journalDirectories); missedCookieDirs.addAll(journalResult.getLeft()); existingCookies.addAll(journalResult.getRight()); Pair<List<File>, List<Cookie>> ledgerResult = verifyAndGetMissingDirs(masterCookie, allowExpansion, allLedgerDirs); missedCookieDirs.addAll(ledgerResult.getLeft()); existingCookies.addAll(ledgerResult.getRight()); if (!missedCookieDirs.isEmpty()) { if (rmCookie == null) { verifyDirsForNewEnvironment(missedCookieDirs); stampNewCookie(conf, masterCookie, rm, Version.NEW, journalDirectories, allLedgerDirs); } else if (allowExpansion) { <START> Set<File> knownDirs = knownDirs(existingCookies); <END> verifyDirsForStorageExpansion(missedCookieDirs, knownDirs); stampNewCookie(conf, masterCookie, rm, rmCookie.getVersion(), journalDirectories, allLedgerDirs); } else { LOG.error("There are directories without a cookie," + " and this is neither a new environment," + " nor is storage expansion enabled. " + "Empty directories are {}", missedCookieDirs); throw new InvalidCookieException(); } } } catch (IOException ioe) { LOG.error("Error accessing cookie on disks", ioe); throw new BookieException.InvalidCookieException(ioe); } }</code><technical_language>Consider changing method name getExistingDirs getKnownDirs</technical_language>

Target:
public static void checkEnvironmentWithStorageExpansion( ServerConfiguration conf, RegistrationManager rm, List<File> journalDirectories, List<File> allLedgerDirs) throws BookieException { try { String instanceId = rm.getClusterInstanceId(); Cookie.Builder builder = Cookie.generateCookie(conf); if (null != instanceId) { builder.setInstanceId(instanceId); } Cookie masterCookie = builder.build(); boolean allowExpansion = conf.getAllowStorageExpansion(); List<BookieSocketAddress> possibleBookieIds = possibleBookieIds(conf); final Versioned<Cookie> rmCookie = readAndVerifyCookieFromRegistrationManager( masterCookie, rm, possibleBookieIds, allowExpansion); List<File> missedCookieDirs = new ArrayList<>(); List<Cookie> existingCookies = Lists.newArrayList(); if (null != rmCookie) { existingCookies.add(rmCookie.getValue()); } Pair<List<File>, List<Cookie>> journalResult = verifyAndGetMissingDirs(masterCookie, allowExpansion, journalDirectories); missedCookieDirs.addAll(journalResult.getLeft()); existingCookies.addAll(journalResult.getRight()); Pair<List<File>, List<Cookie>> ledgerResult = verifyAndGetMissingDirs(masterCookie, allowExpansion, allLedgerDirs); missedCookieDirs.addAll(ledgerResult.getLeft()); existingCookies.addAll(ledgerResult.getRight()); if (!missedCookieDirs.isEmpty()) { if (rmCookie == null) { verifyDirsForNewEnvironment(missedCookieDirs); stampNewCookie(conf, masterCookie, rm, Version.NEW, journalDirectories, allLedgerDirs); } else if (allowExpansion) { Set<File> knownDirs = getKnownDirs(existingCookies); verifyDirsForStorageExpansion(missedCookieDirs, knownDirs); stampNewCookie(conf, masterCookie, rm, rmCookie.getVersion(), journalDirectories, allLedgerDirs); } else { LOG.error("There are directories without a cookie," + " and this is neither a new environment," + " nor is storage expansion enabled. " + "Empty directories are {}", missedCookieDirs); throw new InvalidCookieException(); } } } catch (IOException ioe) { LOG.error("Error accessing cookie on disks", ioe); throw new BookieException.InvalidCookieException(ioe); } }