Program: 28602
Project: 28602
Buggy source:
/** 
 * Get's the substitutable custom tokens.
 * @return {@link Map} of substitutable tokens, or empty Mapif no custom token found.
 * @throws DomainException If error occurred in retrieving thecustom tokens.
 */
public Map<String,String> getSubstitutableTokens() throws DomainException {
  CustomizationTokensProvider provider=CustomizationTokensProviderFactory.createCustomizationTokensProvider();
  Map<String,String> generatedTokens=new HashMap<String,String>();
  String lineSeparator=System.getProperty("String_Node_Str");
  int noOfTokens=0;
  try {
    List<ConfigCustomizationToken> customTokens=provider.getPresentConfigCustomizationTokens();
    if (!customTokens.isEmpty()) {
      StringBuffer generatedSysTags=new StringBuffer();
      Set<Integer> usedPorts=new HashSet<Integer>();
      Properties domainProps=_domainConfig.getDomainProperties();
      String portBase=(String)_domainConfig.get(DomainConfig.K_PORTBASE);
      Map<String,String> filePaths=new HashMap<String,String>(3,1);
      filePaths.put(SystemPropertyConstants.INSTALL_ROOT_PROPERTY,System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
      filePaths.put(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY,System.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY));
      filePaths.put(SystemPropertyConstants.JAVA_ROOT_PROPERTY,System.getProperty(SystemPropertyConstants.JAVA_ROOT_PROPERTY));
      noOfTokens=customTokens.size();
      for (      ConfigCustomizationToken token : customTokens) {
        String name=token.getName();
        if (isNullOrEmpty(name) || isNullOrEmpty(token.getValue()) || isNullOrEmpty(token.getDescription())) {
          throw new IllegalArgumentException(_strings.get("String_Node_Str",name,token.getValue(),token.getDescription()));
        }
switch (token.getCustomizationType()) {
case PORT:
          Integer port=null;
        if (domainProps.containsKey(name)) {
          port=Integer.valueOf(domainProps.getProperty(token.getName()));
          if (!NetUtils.isPortFree(port)) {
            throw new DomainException(_strings.get("String_Node_Str",port));
          }
        }
 else {
          if (portBase != null && token.getTokenTypeDetails() instanceof PortTypeDetails) {
            PortTypeDetails portTypeDetails=(PortTypeDetails)token.getTokenTypeDetails();
            port=Integer.valueOf(domainProps.getProperty(token.getName())) + Integer.valueOf(portTypeDetails.getBaseOffset());
            if (!generatedTokens.containsKey(PORTBASE_PLACE_HOLDER)) {
              generatedTokens.put(PORTBASE_PLACE_HOLDER,SystemPropertyTagBuilder.buildSystemTag(PORTBASE_PLACE_HOLDER,portBase));
            }
          }
 else {
            port=Integer.valueOf(token.getValue());
          }
          while (!NetUtils.isPortFree(port) && !usedPorts.contains(port++))           ;
        }
      usedPorts.add(port);
    generatedSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token,port.toString()));
  break;
case FILE:
String path=token.getValue();
for (Map.Entry<String,String> entry : filePaths.entrySet()) {
if (path.contains(entry.getKey())) {
  path=path.replace(entry.getKey(),entry.getValue());
  break;
}
}
if (token.getTokenTypeDetails() instanceof FileTypeDetails) {
FileTypeDetails details=(FileTypeDetails)token.getTokenTypeDetails();
File file=new File(path);
switch (details.getExistCondition()) {
case MUST_EXIST:
if (!file.exists()) {
  throw new DomainException(_strings.get("String_Node_Str",file.getAbsolutePath()));
}
break;
case MUST_NOT_EXIST:
if (file.exists()) {
throw new DomainException(_strings.get("String_Node_Str",file.getAbsolutePath()));
}
break;
case NO_OP:
break;
}
}
generatedSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token,path));
break;
case STRING:
generatedSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token));
break;
}
if (--noOfTokens > 0) {
generatedSysTags.append(lineSeparator);
}
}
String tags=generatedSysTags.toString();
if (!isNullOrEmpty(tags)) {
generatedTokens.put(CUSTOM_TOKEN_PLACE_HOLDER,tags);
}
}
List<ConfigCustomizationToken> defaultTokens=provider.getPresentDefaultConfigCustomizationTokens();
if (!defaultTokens.isEmpty()) {
StringBuffer defaultSysTags=new StringBuffer();
noOfTokens=defaultTokens.size();
for (ConfigCustomizationToken token : defaultTokens) {
defaultSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token));
if (--noOfTokens > 0) {
defaultSysTags.append(lineSeparator);
}
}
generatedTokens.put(DEFAULT_TOKEN_PLACE_HOLDER,defaultSysTags.toString());
}
}
 catch (DomainException de) {
throw de;
}
catch (Exception ex) {
throw new DomainException(ex);
}
return generatedTokens;
}

Fixed version (ground truth):
/** 
 * Get's the substitutable custom tokens.
 * @return {@link Map} of substitutable tokens, or empty Mapif no custom token found.
 * @throws DomainException If error occurred in retrieving thecustom tokens.
 */
public Map<String,String> getSubstitutableTokens() throws DomainException {
  CustomizationTokensProvider provider=CustomizationTokensProviderFactory.createCustomizationTokensProvider();
  Map<String,String> generatedTokens=new HashMap<String,String>();
  String lineSeparator=System.getProperty("String_Node_Str");
  int noOfTokens=0;
  try {
    List<ConfigCustomizationToken> customTokens=provider.getPresentConfigCustomizationTokens();
    if (!customTokens.isEmpty()) {
      StringBuffer generatedSysTags=new StringBuffer();
      Set<Integer> usedPorts=new HashSet<Integer>();
      Properties domainProps=_domainConfig.getDomainProperties();
      String portBase=(String)_domainConfig.get(DomainConfig.K_PORTBASE);
      Map<String,String> filePaths=new HashMap<String,String>(3,1);
      filePaths.put(SystemPropertyConstants.INSTALL_ROOT_PROPERTY,System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
      filePaths.put(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY,System.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY));
      filePaths.put(SystemPropertyConstants.JAVA_ROOT_PROPERTY,System.getProperty(SystemPropertyConstants.JAVA_ROOT_PROPERTY));
      noOfTokens=customTokens.size();
      for (      ConfigCustomizationToken token : customTokens) {
        String name=token.getName();
        if (isNullOrEmpty(name) || isNullOrEmpty(token.getValue()) || isNullOrEmpty(token.getDescription())) {
          throw new IllegalArgumentException(_strings.get("String_Node_Str",name,token.getValue(),token.getDescription()));
        }
switch (token.getCustomizationType()) {
case PORT:
          Integer port=null;
        if (domainProps.containsKey(name)) {
          port=Integer.valueOf(domainProps.getProperty(token.getName()));
          if (!NetUtils.isPortFree(port)) {
            throw new DomainException(_strings.get("String_Node_Str",port));
          }
        }
 else {
          if (portBase != null && token.getTokenTypeDetails() instanceof PortTypeDetails) {
            PortTypeDetails portTypeDetails=(PortTypeDetails)token.getTokenTypeDetails();
            port=Integer.valueOf(portBase) + Integer.valueOf(portTypeDetails.getBaseOffset());
            if (!generatedTokens.containsKey(PORTBASE_PLACE_HOLDER)) {
              generatedTokens.put(PORTBASE_PLACE_HOLDER,SystemPropertyTagBuilder.buildSystemTag(PORTBASE_PLACE_HOLDER,portBase));
            }
          }
 else {
            port=Integer.valueOf(token.getValue());
          }
          while (!NetUtils.isPortFree(port) && !usedPorts.contains(port++))           ;
        }
      usedPorts.add(port);
    generatedSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token,port.toString()));
  break;
case FILE:
String path=token.getValue();
for (Map.Entry<String,String> entry : filePaths.entrySet()) {
if (path.contains(entry.getKey())) {
  path=path.replace(entry.getKey(),entry.getValue());
  break;
}
}
if (token.getTokenTypeDetails() instanceof FileTypeDetails) {
FileTypeDetails details=(FileTypeDetails)token.getTokenTypeDetails();
File file=new File(path);
switch (details.getExistCondition()) {
case MUST_EXIST:
if (!file.exists()) {
  throw new DomainException(_strings.get("String_Node_Str",file.getAbsolutePath()));
}
break;
case MUST_NOT_EXIST:
if (file.exists()) {
throw new DomainException(_strings.get("String_Node_Str",file.getAbsolutePath()));
}
break;
case NO_OP:
break;
}
}
generatedSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token,path));
break;
case STRING:
generatedSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token));
break;
}
if (--noOfTokens > 0) {
generatedSysTags.append(lineSeparator);
}
}
String tags=generatedSysTags.toString();
if (!isNullOrEmpty(tags)) {
generatedTokens.put(CUSTOM_TOKEN_PLACE_HOLDER,tags);
}
}
List<ConfigCustomizationToken> defaultTokens=provider.getPresentDefaultConfigCustomizationTokens();
if (!defaultTokens.isEmpty()) {
StringBuffer defaultSysTags=new StringBuffer();
noOfTokens=defaultTokens.size();
for (ConfigCustomizationToken token : defaultTokens) {
defaultSysTags.append(SystemPropertyTagBuilder.buildSystemTag(token));
if (--noOfTokens > 0) {
defaultSysTags.append(lineSeparator);
}
}
generatedTokens.put(DEFAULT_TOKEN_PLACE_HOLDER,defaultSysTags.toString());
}
}
 catch (DomainException de) {
throw de;
}
catch (Exception ex) {
throw new DomainException(ex);
}
return generatedTokens;
}