Program: 39642
Project: 39642
Buggy source:
private void process(RoundEnvironment roundEnv,Set<Element> elts,Map<String,PackageMetaData> packageMetaDatas) throws Exception {
  Filer filer=processingEnv.getFiler();
  NodeTypeBuilder visitor=new NodeTypeBuilder();
  SetMap<String,ClassTypeInfo> packageToClassTypes=new SetMap<String,ClassTypeInfo>();
  for (  Element elt : elts) {
    TypeElement typeElt=(TypeElement)elt;
    ClassTypeInfo cti=(ClassTypeInfo)domain.resolve(typeElt);
    for (    String packageName : PackageNameIterator.with(cti.getPackageName())) {
      PackageMetaData packageMetaData=packageMetaDatas.get(packageName);
      if (packageMetaData != null) {
        Set<ClassTypeInfo> set=packageToClassTypes.get(packageName);
        set.add(cti);
        break;
      }
    }
    processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE,"String_Node_Str" + cti.getName());
    visitor.addType(cti);
    try {
      JavaFileObject jfo=filer.createSourceFile(typeElt.getQualifiedName() + "String_Node_Str",typeElt);
      PrintWriter out=new PrintWriter(jfo.openWriter());
      StringBuilder builder=new StringBuilder();
      writeClass(roundEnv,builder,cti);
      out.write(builder.toString());
      out.close();
    }
 catch (    IOException e) {
      throw new RuntimeException(e);
    }
  }
  visitor.generate();
  for (  String packageName : packageToClassTypes.keySet()) {
    env.getMessager().printMessage(Diagnostic.Kind.NOTE,"String_Node_Str" + packageName);
    List<NodeType> nodeTypes=new ArrayList<NodeType>();
    Map<String,String> mappings=Collections.emptyMap();
    for (    ClassTypeInfo cti : packageToClassTypes.get(packageName)) {
      PackageMetaData packageMetaData=packageMetaDatas.get(packageName);
      if (packageMetaData.namespacePrefix.length() > 0 || packageMetaData.namespaceURI.length() > 0) {
        mappings=Collections.singletonMap(packageMetaData.namespacePrefix,packageMetaData.namespaceURI);
      }
      nodeTypes.add(visitor.getNodeType(cti));
    }
    FileObject cndFile=filer.createResource(StandardLocation.SOURCE_OUTPUT,packageName,"String_Node_Str");
    NodeTypeSerializer cndSerializer=new CNDNodeTypeSerializer(nodeTypes,mappings);
    Writer cndWriter=cndFile.openWriter();
    cndSerializer.writeTo(cndWriter);
    cndWriter.close();
    FileObject xmlFile=filer.createResource(StandardLocation.SOURCE_OUTPUT,packageName,"String_Node_Str");
    NodeTypeSerializer xmlSerializer=new XMLNodeTypeSerializer(nodeTypes,mappings);
    Writer xmlWriter=xmlFile.openWriter();
    xmlSerializer.writeTo(xmlWriter);
    xmlWriter.close();
  }
}

Fixed version (ground truth):
private void process(RoundEnvironment roundEnv,Set<Element> elts,Map<String,PackageMetaData> packageMetaDatas) throws Exception {
  Filer filer=processingEnv.getFiler();
  NodeTypeBuilder visitor=new NodeTypeBuilder();
  SetMap<String,ClassTypeInfo> packageToClassTypes=new SetMap<String,ClassTypeInfo>();
  for (  Element elt : elts) {
    TypeElement typeElt=(TypeElement)elt;
    ClassTypeInfo cti=(ClassTypeInfo)domain.resolve(typeElt);
    TreeMap<Integer,PackageMetaData> packageSorter=new TreeMap<Integer,PackageMetaData>();
    for (    PackageMetaData packageMetaData : packageMetaDatas.values()) {
      int dist=packageMetaData.distance(cti);
      if (dist >= 0) {
        packageSorter.put(dist,packageMetaData);
      }
    }
    if (packageSorter.size() > 0) {
      PackageMetaData packageMetaData=packageSorter.values().iterator().next();
      Set<ClassTypeInfo> set=packageToClassTypes.get(packageMetaData.packageName);
      set.add(cti);
    }
    processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE,"String_Node_Str" + cti.getName());
    visitor.addType(cti);
    try {
      JavaFileObject jfo=filer.createSourceFile(typeElt.getQualifiedName() + "String_Node_Str",typeElt);
      PrintWriter out=new PrintWriter(jfo.openWriter());
      StringBuilder builder=new StringBuilder();
      writeClass(roundEnv,builder,cti);
      out.write(builder.toString());
      out.close();
    }
 catch (    IOException e) {
      throw new RuntimeException(e);
    }
  }
  visitor.generate();
  for (  String packageName : packageToClassTypes.keySet()) {
    env.getMessager().printMessage(Diagnostic.Kind.NOTE,"String_Node_Str" + packageName);
    List<NodeType> nodeTypes=new ArrayList<NodeType>();
    Map<String,String> mappings=Collections.emptyMap();
    for (    ClassTypeInfo cti : packageToClassTypes.get(packageName)) {
      PackageMetaData packageMetaData=packageMetaDatas.get(packageName);
      if (packageMetaData.namespacePrefix.length() > 0 || packageMetaData.namespaceURI.length() > 0) {
        mappings=Collections.singletonMap(packageMetaData.namespacePrefix,packageMetaData.namespaceURI);
      }
      nodeTypes.add(visitor.getNodeType(cti));
    }
    FileObject cndFile=filer.createResource(StandardLocation.SOURCE_OUTPUT,packageName,"String_Node_Str");
    NodeTypeSerializer cndSerializer=new CNDNodeTypeSerializer(nodeTypes,mappings);
    Writer cndWriter=cndFile.openWriter();
    cndSerializer.writeTo(cndWriter);
    cndWriter.close();
    FileObject xmlFile=filer.createResource(StandardLocation.SOURCE_OUTPUT,packageName,"String_Node_Str");
    NodeTypeSerializer xmlSerializer=new XMLNodeTypeSerializer(nodeTypes,mappings);
    Writer xmlWriter=xmlFile.openWriter();
    xmlSerializer.writeTo(xmlWriter);
    xmlWriter.close();
  }
}