Program: 54413
Project: 54413
Buggy source:
static String generateConstantOrMessageClass(TreeLogger logger,GeneratorContext context,GwtLocale locale,JClassType targetClass) throws UnableToCompleteException {
  TypeOracle oracle=context.getTypeOracle();
  JClassType constantsClass;
  JClassType messagesClass;
  JClassType constantsWithLookupClass;
  boolean seenError=false;
  try {
    constantsClass=oracle.getType(LocalizableGenerator.CONSTANTS_NAME);
    constantsWithLookupClass=oracle.getType(LocalizableGenerator.CONSTANTS_WITH_LOOKUP_NAME);
    messagesClass=oracle.getType(LocalizableGenerator.MESSAGES_NAME);
  }
 catch (  NotFoundException e) {
    throw error(logger,e);
  }
  String name=targetClass.getName();
  String packageName=targetClass.getPackage().getName();
  boolean assignableToConstants=constantsClass.isAssignableFrom(targetClass);
  boolean assignableToMessages=messagesClass.isAssignableFrom(targetClass);
  if (!assignableToConstants && !assignableToMessages) {
    return null;
  }
  if (assignableToConstants && assignableToMessages) {
    throw error(logger,name + "String_Node_Str");
  }
  if (targetClass.isInterface() == null) {
    throw error(logger,name + "String_Node_Str");
  }
  ResourceList resourceList=null;
  try {
    resourceList=ResourceFactory.getBundle(logger,targetClass,locale,assignableToConstants,context.getResourcesOracle().getResourceMap());
  }
 catch (  MissingResourceException e) {
    throw error(logger,"String_Node_Str" + "String_Node_Str" + packageName + "String_Node_Str"+ ResourceFactory.getResourceName(targetClass)+ "String_Node_Str");
  }
catch (  IllegalArgumentException e) {
    throw error(logger,e.getMessage());
  }
  GwtLocale generatedLocale=resourceList.findLeastDerivedLocale(locale);
  String localeSuffix=String.valueOf(ResourceFactory.LOCALE_SEPARATOR);
  localeSuffix+=generatedLocale.getAsString();
  String resourceName=targetClass.getName().replace('.','_');
  String className=resourceName + localeSuffix;
  PrintWriter pw=context.tryCreate(logger,packageName,className);
  if (pw != null) {
    ClassSourceFileComposerFactory factory=new ClassSourceFileComposerFactory(packageName,className);
    factory.addImplementedInterface(targetClass.getQualifiedSourceName());
    SourceWriter writer=factory.createSourceWriter(context,pw);
    if (constantsWithLookupClass.isAssignableFrom(targetClass)) {
      ConstantsWithLookupImplCreator c=new ConstantsWithLookupImplCreator(logger,writer,targetClass,resourceList,context.getTypeOracle());
      c.emitClass(logger,generatedLocale);
    }
 else     if (constantsClass.isAssignableFrom(targetClass)) {
      ConstantsImplCreator c=new ConstantsImplCreator(logger,writer,targetClass,resourceList,context.getTypeOracle());
      c.emitClass(logger,generatedLocale);
    }
 else {
      MessagesImplCreator messages=new MessagesImplCreator(logger,writer,targetClass,resourceList,context.getTypeOracle());
      messages.emitClass(logger,generatedLocale);
    }
    context.commit(logger,pw);
  }
  Generate generate=getClassAnnotation(targetClass,Generate.class);
  if (generate != null) {
    String path=generate.fileName();
    if (Generate.DEFAULT.equals(path)) {
      path=targetClass.getPackage().getName() + "String_Node_Str" + targetClass.getName().replace('.','_');
    }
 else     if (path.endsWith(File.pathSeparator)) {
      path=path + targetClass.getName().replace('.','_');
    }
    String[] genLocales=generate.locales();
    boolean found=false;
    if (genLocales.length != 0) {
      for (      String genLocale : genLocales) {
        if (GwtLocale.DEFAULT_LOCALE.equals(genLocale)) {
          try {
            SelectionProperty localeProp=context.getPropertyOracle().getSelectionProperty(logger,"String_Node_Str");
            String defaultLocale=localeProp.getFallbackValue();
            if (defaultLocale.length() > 0) {
              genLocale=defaultLocale;
            }
          }
 catch (          BadPropertyValueException e) {
            throw error(logger,"String_Node_Str");
          }
        }
        if (genLocale.equals(locale.toString())) {
          found=true;
          break;
        }
      }
    }
 else {
      found=true;
    }
    if (found) {
      for (      String genClassName : generate.format()) {
        MessageCatalogFormat msgWriter=null;
        try {
          Class<? extends MessageCatalogFormat> msgFormatClass=Class.forName(genClassName,false,MessageCatalogFormat.class.getClassLoader()).asSubclass(MessageCatalogFormat.class);
          msgWriter=msgFormatClass.newInstance();
        }
 catch (        InstantiationException e) {
          logger.log(TreeLogger.ERROR,"String_Node_Str" + genClassName,e);
          seenError=true;
          continue;
        }
catch (        IllegalAccessException e) {
          logger.log(TreeLogger.ERROR,"String_Node_Str" + genClassName + "String_Node_Str",e);
          seenError=true;
          continue;
        }
catch (        ClassNotFoundException e) {
          logger.log(TreeLogger.ERROR,"String_Node_Str" + genClassName + "String_Node_Str");
          seenError=true;
          continue;
        }
        String genPath=path;
        if (genLocales.length != 1) {
          genPath+='_' + locale.toString();
        }
        genPath+=msgWriter.getExtension();
        OutputStream outStr=context.tryCreateResource(logger,genPath);
        if (outStr != null) {
          TreeLogger branch=logger.branch(TreeLogger.INFO,"String_Node_Str" + genPath + "String_Node_Str"+ className+ "String_Node_Str"+ locale,null);
          PrintWriter out=null;
          try {
            out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(outStr,"String_Node_Str")),false);
          }
 catch (          UnsupportedEncodingException e) {
            throw error(logger,e.getMessage());
          }
          try {
            msgWriter.write(branch,locale.toString(),resourceList,out,targetClass);
            out.flush();
            context.commitResource(logger,outStr).setPrivate(true);
          }
 catch (          UnableToCompleteException e) {
            seenError=true;
          }
        }
      }
    }
  }
  if (seenError) {
    throw new UnableToCompleteException();
  }
  return packageName + "String_Node_Str" + className;
}

Fixed version (ground truth):
static String generateConstantOrMessageClass(TreeLogger logger,GeneratorContext context,GwtLocale locale,JClassType targetClass) throws UnableToCompleteException {
  TypeOracle oracle=context.getTypeOracle();
  JClassType constantsClass;
  JClassType messagesClass;
  JClassType constantsWithLookupClass;
  boolean seenError=false;
  try {
    constantsClass=oracle.getType(LocalizableGenerator.CONSTANTS_NAME);
    constantsWithLookupClass=oracle.getType(LocalizableGenerator.CONSTANTS_WITH_LOOKUP_NAME);
    messagesClass=oracle.getType(LocalizableGenerator.MESSAGES_NAME);
  }
 catch (  NotFoundException e) {
    throw error(logger,e);
  }
  String name=targetClass.getName();
  String packageName=targetClass.getPackage().getName();
  boolean assignableToConstants=constantsClass.isAssignableFrom(targetClass);
  boolean assignableToMessages=messagesClass.isAssignableFrom(targetClass);
  if (!assignableToConstants && !assignableToMessages) {
    return null;
  }
  if (assignableToConstants && assignableToMessages) {
    throw error(logger,name + "String_Node_Str");
  }
  if (targetClass.isInterface() == null) {
    throw error(logger,name + "String_Node_Str");
  }
  ResourceList resourceList=null;
  try {
    resourceList=ResourceFactory.getBundle(logger,targetClass,locale,assignableToConstants,context.getResourcesOracle().getResourceMap());
  }
 catch (  MissingResourceException e) {
    throw error(logger,"String_Node_Str" + "String_Node_Str" + packageName + "String_Node_Str"+ ResourceFactory.getResourceName(targetClass)+ "String_Node_Str");
  }
catch (  IllegalArgumentException e) {
    throw error(logger,e.getMessage());
  }
  GwtLocale generatedLocale=resourceList.findLeastDerivedLocale(logger,locale);
  String localeSuffix=String.valueOf(ResourceFactory.LOCALE_SEPARATOR);
  localeSuffix+=generatedLocale.getAsString();
  String resourceName=targetClass.getName().replace('.','_');
  String className=resourceName + localeSuffix;
  PrintWriter pw=context.tryCreate(logger,packageName,className);
  if (pw != null) {
    ClassSourceFileComposerFactory factory=new ClassSourceFileComposerFactory(packageName,className);
    factory.addImplementedInterface(targetClass.getQualifiedSourceName());
    SourceWriter writer=factory.createSourceWriter(context,pw);
    if (constantsWithLookupClass.isAssignableFrom(targetClass)) {
      ConstantsWithLookupImplCreator c=new ConstantsWithLookupImplCreator(logger,writer,targetClass,resourceList,context.getTypeOracle());
      c.emitClass(logger,generatedLocale);
    }
 else     if (constantsClass.isAssignableFrom(targetClass)) {
      ConstantsImplCreator c=new ConstantsImplCreator(logger,writer,targetClass,resourceList,context.getTypeOracle());
      c.emitClass(logger,generatedLocale);
    }
 else {
      MessagesImplCreator messages=new MessagesImplCreator(logger,writer,targetClass,resourceList,context.getTypeOracle());
      messages.emitClass(logger,generatedLocale);
    }
    context.commit(logger,pw);
  }
  Generate generate=getClassAnnotation(targetClass,Generate.class);
  if (generate != null) {
    String path=generate.fileName();
    if (Generate.DEFAULT.equals(path)) {
      path=targetClass.getPackage().getName() + "String_Node_Str" + targetClass.getName().replace('.','_');
    }
 else     if (path.endsWith(File.pathSeparator)) {
      path=path + targetClass.getName().replace('.','_');
    }
    String[] genLocales=generate.locales();
    boolean found=false;
    if (genLocales.length != 0) {
      for (      String genLocale : genLocales) {
        if (GwtLocale.DEFAULT_LOCALE.equals(genLocale)) {
          try {
            SelectionProperty localeProp=context.getPropertyOracle().getSelectionProperty(logger,"String_Node_Str");
            String defaultLocale=localeProp.getFallbackValue();
            if (defaultLocale.length() > 0) {
              genLocale=defaultLocale;
            }
          }
 catch (          BadPropertyValueException e) {
            throw error(logger,"String_Node_Str");
          }
        }
        if (genLocale.equals(locale.toString())) {
          found=true;
          break;
        }
      }
    }
 else {
      found=true;
    }
    if (found) {
      for (      String genClassName : generate.format()) {
        MessageCatalogFormat msgWriter=null;
        try {
          Class<? extends MessageCatalogFormat> msgFormatClass=Class.forName(genClassName,false,MessageCatalogFormat.class.getClassLoader()).asSubclass(MessageCatalogFormat.class);
          msgWriter=msgFormatClass.newInstance();
        }
 catch (        InstantiationException e) {
          logger.log(TreeLogger.ERROR,"String_Node_Str" + genClassName,e);
          seenError=true;
          continue;
        }
catch (        IllegalAccessException e) {
          logger.log(TreeLogger.ERROR,"String_Node_Str" + genClassName + "String_Node_Str",e);
          seenError=true;
          continue;
        }
catch (        ClassNotFoundException e) {
          logger.log(TreeLogger.ERROR,"String_Node_Str" + genClassName + "String_Node_Str");
          seenError=true;
          continue;
        }
        String genPath=path;
        if (genLocales.length != 1) {
          genPath+='_' + locale.toString();
        }
        genPath+=msgWriter.getExtension();
        OutputStream outStr=context.tryCreateResource(logger,genPath);
        if (outStr != null) {
          TreeLogger branch=logger.branch(TreeLogger.INFO,"String_Node_Str" + genPath + "String_Node_Str"+ className+ "String_Node_Str"+ locale,null);
          PrintWriter out=null;
          try {
            out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(outStr,"String_Node_Str")),false);
          }
 catch (          UnsupportedEncodingException e) {
            throw error(logger,e.getMessage());
          }
          try {
            msgWriter.write(branch,locale.toString(),resourceList,out,targetClass);
            out.flush();
            context.commitResource(logger,outStr).setPrivate(true);
          }
 catch (          UnableToCompleteException e) {
            seenError=true;
          }
        }
      }
    }
  }
  if (seenError) {
    throw new UnableToCompleteException();
  }
  return packageName + "String_Node_Str" + className;
}