nus-yam/ex-repair huggingface dataset:
Program: 83457
Project: 83457
Buggy source:
@Override public <T extends Event>void addListener(Class<T> type,Object object,IEventListener listener,short customPriority){
  Map<Object,List<Entry<IEventListener>>> objectListeners=objectListenerContainersMap.get(type);
  if (objectListeners == null) {
    objectListeners=new HashMap<Object,List<Entry<IEventListener>>>();
    objectListenerContainersMap.put(type,objectListeners);
  }
  List<Entry<IEventListener>> listeners=objectListeners.get(object);
  if (listeners == null) {
    listeners=new Vector<Entry<IEventListener>>();
    objectListeners.put(type,listeners);
  }
  for (int i=0; i < listeners.size(); i++) {
    if (listeners.get(i).getValue() == listener) {
      listeners.remove(i);
      break;
    }
  }
  Entry<IEventListener> entry=new Entry<IEventListener>(customPriority,listener);
  listeners.add(entry);
}

Fixed version (ground truth):
@Override public <T extends Event>void addListener(Class<T> type,Object object,IEventListener listener,short customPriority){
  Map<Object,List<Entry<IEventListener>>> objectListeners=objectListenerContainersMap.get(type);
  if (objectListeners == null) {
    objectListeners=new HashMap<Object,List<Entry<IEventListener>>>();
    objectListenerContainersMap.put(type,objectListeners);
  }
  List<Entry<IEventListener>> listeners=objectListeners.get(object);
  if (listeners == null) {
    listeners=new Vector<Entry<IEventListener>>();
    objectListeners.put(object,listeners);
  }
  for (int i=0; i < listeners.size(); i++) {
    if (listeners.get(i).getValue() == listener) {
      listeners.remove(i);
      break;
    }
  }
  Entry<IEventListener> entry=new Entry<IEventListener>(customPriority,listener);
  listeners.add(entry);
}
Program: 83458
Project: 83458
Buggy source:
Shoebill(){
  globalEventDispatcher=new EventManager();
  sampCallbackManager=new SampCallbackManager();
  managedObjectPool=new SampObjectPool();
  pluginManager=new PluginManager(this,new File("String_Node_Str"),new File("String_Node_Str"));
  sampEventLogger=new SampEventLogger(managedObjectPool);
  sampEventDispatcher=new SampEventDispatcher(managedObjectPool,globalEventDispatcher);
  initialize();
}

Fixed version (ground truth):
Shoebill(){
  instance=this;
  globalEventDispatcher=new EventManager();
  sampCallbackManager=new SampCallbackManager();
  managedObjectPool=new SampObjectPool();
  pluginManager=new PluginManager(this,new File("String_Node_Str"),new File("String_Node_Str"));
  sampEventLogger=new SampEventLogger(managedObjectPool);
  sampEventDispatcher=new SampEventDispatcher(managedObjectPool,globalEventDispatcher);
  initialize();
}
Program: 83459
Project: 83459
Buggy source:
protected Player(int id){
  this.id=id;
  SampNativeFunction.getPlayerPos(id,location);
  SampNativeFunction.getPlayerFacingAngle(id);
  location.interiorId=SampNativeFunction.getPlayerInterior(id);
  location.worldId=SampNativeFunction.getPlayerVirtualWorld(id);
  SampNativeFunction.getPlayerVelocity(id,velocity);
  SampNativeFunction.getPlayerKeys(id,keyState);
  playerAttach=new PlayerAttach(id);
  skill=new PlayerWeaponSkill(id);
  SampObjectPool pool=(SampObjectPool)Shoebill.getInstance().getManagedObjectPool();
  if (pool.getPlayer(id) != null)   throw new UnsupportedOperationException();
  pool.setPlayer(id,this);
}

Fixed version (ground truth):
public Player(int id){
  this.id=id;
  SampNativeFunction.getPlayerPos(id,location);
  SampNativeFunction.getPlayerFacingAngle(id);
  location.interiorId=SampNativeFunction.getPlayerInterior(id);
  location.worldId=SampNativeFunction.getPlayerVirtualWorld(id);
  SampNativeFunction.getPlayerVelocity(id,velocity);
  SampNativeFunction.getPlayerKeys(id,keyState);
  playerAttach=new PlayerAttach(id);
  skill=new PlayerWeaponSkill(id);
  SampObjectPool pool=(SampObjectPool)Shoebill.getInstance().getManagedObjectPool();
  if (pool.getPlayer(id) != null)   throw new UnsupportedOperationException();
  pool.setPlayer(id,this);
}
Program: 83461
Project: 83461
Buggy source:
@Override public <T extends Event>void addListener(Class<T> type,Object object,IEventListener listener,short customPriority){
  Map<Object,List<Entry<IEventListener>>> objectListeners=objectListenerContainersMap.get(type);
  if (objectListeners == null) {
    objectListeners=new HashMap<Object,List<Entry<IEventListener>>>();
    objectListenerContainersMap.put(type,objectListeners);
  }
  List<Entry<IEventListener>> listeners=objectListeners.get(object);
  if (listeners == null) {
    listeners=new Vector<Entry<IEventListener>>();
    objectListeners.put(type,listeners);
  }
  for (int i=0; i < listeners.size(); i++) {
    if (listeners.get(i).getValue() == listener) {
      listeners.remove(i);
      break;
    }
  }
  Entry<IEventListener> entry=new Entry<IEventListener>(customPriority,listener);
  listeners.add(entry);
}

Fixed version (ground truth):
@Override public <T extends Event>void addListener(Class<T> type,Object object,IEventListener listener,short customPriority){
  Map<Object,List<Entry<IEventListener>>> objectListeners=objectListenerContainersMap.get(type);
  if (objectListeners == null) {
    objectListeners=new HashMap<Object,List<Entry<IEventListener>>>();
    objectListenerContainersMap.put(type,objectListeners);
  }
  List<Entry<IEventListener>> listeners=objectListeners.get(object);
  if (listeners == null) {
    listeners=new Vector<Entry<IEventListener>>();
    objectListeners.put(object,listeners);
  }
  for (int i=0; i < listeners.size(); i++) {
    if (listeners.get(i).getValue() == listener) {
      listeners.remove(i);
      break;
    }
  }
  Entry<IEventListener> entry=new Entry<IEventListener>(customPriority,listener);
  listeners.add(entry);
}
Program: 83462
Project: 83462
Buggy source:
private void init(float x,float y,float z,int interior,int world,float angle){
  id=NativeFunction.createVehicle(model,x,y,z,angle,color1,color2,respawnDelay);
  NativeFunction.linkVehicleToInterior(id,interior);
  NativeFunction.setVehicleVirtualWorld(id,world);
  param=new VehicleParam(id);
  component=new VehicleComponent(id);
  damage=new VehicleDamage(id);
}

Fixed version (ground truth):
private void init(float x,float y,float z,int interior,int world,float angle){
  id=NativeFunction.createVehicle(model,x,y,z,angle,color1,color2,respawnDelay);
  NativeFunction.linkVehicleToInterior(id,interior);
  NativeFunction.setVehicleVirtualWorld(id,world);
  param=new VehicleParam(id);
  component=new VehicleComponent(id);
  damage=new VehicleDamage(id);
  GameModeBase.instance.vehiclePool[id]=this;
}
Program: 83463
Project: 83463
Buggy source:
@Override public void whitespace(int n){
  while (n > 8) {
    appendText(WS8);
    n-=8;
  }
  if (n > 0)   appendText(WHITESPACES.get(n));
}

Fixed version (ground truth):
@Override public void whitespace(int n){
  while (n >= 8) {
    appendText(WS8);
    n-=8;
  }
  if (n > 0)   appendText(WHITESPACES.get(n));
}
Program: 83465
Project: 83465
Buggy source:
/** 
 * Method declaration.
 */
public Void visitMethod(MethodTree mt,Void _){
  ExecutableElement e=(ExecutableElement)TreeUtil.getElement(mt);
  if (e != null) {
    if (e.getKind() == ElementKind.CONSTRUCTOR && e.getEnclosingElement().getSimpleName().length() == 0)     return _;
    Tree prev=mt.getReturnType();
    String name;
    if (e.getKind() == ElementKind.CONSTRUCTOR)     name=e.getEnclosingElement().getSimpleName().toString();
 else     name=mt.getName().toString();
    Token token;
    if (prev != null)     token=gen.findTokenAfter(prev,true,name);
 else     token=gen.findTokenAfter(mt,false,name);
    if (token != null)     gen.add(new DeclName(lineMap,token));
    ParsedType pt=getParsedType((TypeElement)e.getEnclosingElement());
    gen.add(new MethodDecl(cu,srcPos,mt,e,pt.findOverriddenMethods(elements,e),pt.findOverridingMethods(elements,e)));
  }
  return super.visitMethod(mt,_);
}

Fixed version (ground truth):
/** 
 * Method declaration.
 */
public Void visitMethod(MethodTree mt,Void _){
  ExecutableElement e=(ExecutableElement)TreeUtil.getElement(mt);
  if (e != null) {
    if (((MethodSymbol)e).isSynthetic())     return _;
    Tree prev=mt.getReturnType();
    String name;
    if (e.getKind() == ElementKind.CONSTRUCTOR)     name=e.getEnclosingElement().getSimpleName().toString();
 else     name=mt.getName().toString();
    Token token;
    if (prev != null)     token=gen.findTokenAfter(prev,true,name);
 else     token=gen.findTokenAfter(mt,false,name);
    if (token != null)     gen.add(new DeclName(lineMap,token));
    ParsedType pt=getParsedType((TypeElement)e.getEnclosingElement());
    gen.add(new MethodDecl(cu,srcPos,mt,e,pt.findOverriddenMethods(elements,e),pt.findOverridingMethods(elements,e)));
  }
  return super.visitMethod(mt,_);
}
Program: 83466
Project: 83466
Buggy source:
/** 
 * Creates a configured   {@link JavacTask}.
 */
protected JavacTask configure(DiagnosticListener<? super JavaFileObject> errorListener) throws IOException {
  JavaCompiler javac=JavacTool.create();
  StandardJavaFileManager fileManager=new TabExpandingFileManager(javac.getStandardFileManager(errorListener,locale,encoding),encoding,tabWidth);
  fileManager.setLocation(StandardLocation.CLASS_PATH,classpath);
  List<String> options=Collections.emptyList();
  Iterable<? extends JavaFileObject> files=fileManager.getJavaFileObjectsFromFiles(sourceFiles);
  CompilationTask task=javac.getTask(null,fileManager,errorListener,options,null,files);
  return (JavacTask)task;
}

Fixed version (ground truth):
/** 
 * Creates a configured   {@link JavacTask}.
 */
protected JavacTask configure(DiagnosticListener<? super JavaFileObject> errorListener) throws IOException {
  JavaCompiler javac=JavacTool.create();
  StandardJavaFileManager fileManager=new TabExpandingFileManager(javac.getStandardFileManager(errorListener,locale,encoding),encoding,tabWidth);
  fileManager.setLocation(StandardLocation.CLASS_PATH,classpath);
  List<String> options=Arrays.asList("String_Node_Str");
  Iterable<? extends JavaFileObject> files=fileManager.getJavaFileObjectsFromFiles(sourceFiles);
  CompilationTask task=javac.getTask(null,fileManager,errorListener,options,null,files);
  return (JavacTask)task;
}
Program: 83467
Project: 83467
Buggy source:
public StringBuilder visitType(TypeElement t,Void _){
  ClassTree ct=trees.getTree(t);
  if (ct == null)   return null;
switch (t.getNestingKind()) {
case ANONYMOUS:
    String binaryName=elements.getBinaryName(t).toString();
  int idx=binaryName.lastIndexOf('$');
String name="String_Node_Str" + binaryName.substring(idx);
return combine(getEnclosingTypeOrPackage(t).accept(this,null)).append(name);
case TOP_LEVEL:
CompilationUnitTree owner=pss.getTreePathByClass().get(ct).getCompilationUnit();
String primaryTypeName=TreeUtil.getPrimaryTypeName(owner);
String simpleName=ct.getSimpleName().toString();
StringBuilder buf=new StringBuilder();
if (!primaryTypeName.equals(simpleName)) {
buf.append("String_Node_Str").append(simpleName);
}
return buf;
case MEMBER:
case LOCAL:
return recurse(t).append('~').append(t.getSimpleName());
default :
throw new IllegalStateException(t.getNestingKind().toString());
}
}

Fixed version (ground truth):
public StringBuilder visitType(TypeElement t,Void _){
  ClassTree ct=trees.getTree(t);
  if (ct == null)   return new StringBuilder();
switch (t.getNestingKind()) {
case ANONYMOUS:
    String binaryName=elements.getBinaryName(t).toString();
  int idx=binaryName.lastIndexOf('$');
String name="String_Node_Str" + binaryName.substring(idx);
return combine(getEnclosingTypeOrPackage(t).accept(this,null)).append(name);
case TOP_LEVEL:
CompilationUnitTree owner=pss.getTreePathByClass().get(ct).getCompilationUnit();
String primaryTypeName=TreeUtil.getPrimaryTypeName(owner);
String simpleName=ct.getSimpleName().toString();
StringBuilder buf=new StringBuilder();
if (!primaryTypeName.equals(simpleName)) {
buf.append("String_Node_Str").append(simpleName);
}
return buf;
case MEMBER:
case LOCAL:
return recurse(t).append('~').append(t.getSimpleName());
default :
throw new IllegalStateException(t.getNestingKind().toString());
}
}
Program: 83468
Project: 83468
Buggy source:
public void doDynamic(StaplerRequest req,StaplerResponse rsp) throws IOException {
  String path=req.getRestOfPath();
  Generator g=generators.get(path);
  if (g == null) {
    rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
    return;
  }
  if (req.checkIfModified(timestamp,rsp,expiration))   return;
  g.doDynamic(req,rsp);
}

Fixed version (ground truth):
public void doDynamic(StaplerRequest req,StaplerResponse rsp) throws IOException {
  String path=req.getRestOfPath();
  if (path.length() > 0)   path=path.substring(1);
  Generator g=generators.get(path);
  if (g == null) {
    rsp.sendError(HttpServletResponse.SC_NOT_FOUND);
    return;
  }
  if (req.checkIfModified(timestamp,rsp,expiration))   return;
  g.doDynamic(req,rsp);
}
Program: 83470
Project: 83470
Buggy source:
/** 
 * Gets the actual   {@link Tree} nodes that refer to {@link Element}s (methods, fields, constructors, constants, and the type itself, but excluding nested types) inside this type. <p> This involves a non-trivial computation, but it does use index so it's faster than scanning the whole source tree.
 */
public Map<Element,Set<TreePath>> findReferers(){
  return RefererFinder.find(this);
}

Fixed version (ground truth):
/** 
 * Gets the actual   {@link Tree} nodes that refer to {@link Element}s (methods, fields, constructors, constants, and the type itself, but excluding nested types) inside this type. <p> This involves a non-trivial computation, but it does use index so it's faster than scanning the whole source tree.
 */
public Map<Element,Set<TreePath>> findReferers(SourcePositions pos){
  return RefererFinder.find(this,pos);
}
Program: 83471
Project: 83471
Buggy source:
private void add(Element e){
  Set<TreePath> trees=result.get(e);
  if (trees == null)   result.put(e,trees=new HashSet<TreePath>());
  trees.add(getCurrentPath());
}

Fixed version (ground truth):
private void add(Element e){
  TreePath p=getCurrentPath();
  long pos=this.pos.getStartPosition(p.getCompilationUnit(),p.getLeaf());
  if (pos == -1)   return;
  Set<TreePath> trees=result.get(e);
  if (trees == null)   result.put(e,trees=new HashSet<TreePath>());
  trees.add(p);
}
Program: 83472
Project: 83472
Buggy source:
/** 
 * @return keys are the fields and methods defined on the given type. values are all the tree nodes where it's actually referenced.
 */
static Map<Element,Set<TreePath>> find(ParsedType t){
  RefererFinder finder=new RefererFinder(t.element);
  for (  CompilationUnitTree cu : t.getReferers())   finder.scan(cu,null);
  return finder.result;
}

Fixed version (ground truth):
/** 
 * @return keys are the fields and methods defined on the given type. values are all the tree nodes where it's actually referenced.
 */
static Map<Element,Set<TreePath>> find(ParsedType t,SourcePositions pos){
  RefererFinder finder=new RefererFinder(t.element,pos);
  for (  CompilationUnitTree cu : t.getReferers())   finder.scan(cu,null);
  return finder.result;
}
Program: 83473
Project: 83473
Buggy source:
private RefererFinder(TypeElement type){
  this.type=type;
}

Fixed version (ground truth):
private RefererFinder(TypeElement type,SourcePositions pos){
  this.type=type;
  this.pos=pos;
}
Program: 83475
Project: 83475
Buggy source:
/** 
 * Method declaration.
 */
public Void visitMethod(MethodTree mt,Void _){
  ExecutableElement e=(ExecutableElement)TreeUtil.getElement(mt);
  if (e != null) {
    if (e.getKind() == ElementKind.CONSTRUCTOR && e.getEnclosingElement().getSimpleName().length() == 0)     return _;
    Tree prev=mt.getReturnType();
    String name=mt.getName().toString();
    Token token;
    if (prev != null)     token=gen.findTokenAfter(prev,true,name);
 else     token=gen.findTokenAfter(mt,false,name);
    if (token != null)     gen.add(new DeclName(lineMap,token));
    ParsedType pt=getParsedType((TypeElement)e.getEnclosingElement());
    gen.add(new MethodDecl(cu,srcPos,mt,e,pt.findOverriddenMethods(elements,e),pt.findOverridingMethods(elements,e)));
  }
  return super.visitMethod(mt,_);
}

Fixed version (ground truth):
/** 
 * Method declaration.
 */
public Void visitMethod(MethodTree mt,Void _){
  ExecutableElement e=(ExecutableElement)TreeUtil.getElement(mt);
  if (e != null) {
    if (e.getKind() == ElementKind.CONSTRUCTOR && e.getEnclosingElement().getSimpleName().length() == 0)     return _;
    Tree prev=mt.getReturnType();
    String name;
    if (e.getKind() == ElementKind.CONSTRUCTOR)     name=e.getEnclosingElement().getSimpleName().toString();
 else     name=mt.getName().toString();
    Token token;
    if (prev != null)     token=gen.findTokenAfter(prev,true,name);
 else     token=gen.findTokenAfter(mt,false,name);
    if (token != null)     gen.add(new DeclName(lineMap,token));
    ParsedType pt=getParsedType((TypeElement)e.getEnclosingElement());
    gen.add(new MethodDecl(cu,srcPos,mt,e,pt.findOverriddenMethods(elements,e),pt.findOverridingMethods(elements,e)));
  }
  return super.visitMethod(mt,_);
}
Program: 83476
Project: 83476
Buggy source:
public long getStartPosition(CompilationUnitTree file,Tree tree){
  long pos=this.pos.getStartPosition(file,tree);
  if (pos == -1 && tree instanceof JCVariableDecl) {
    return ((JCVariableDecl)tree).pos;
  }
  return pos;
}

Fixed version (ground truth):
public long getStartPosition(CompilationUnitTree file,Tree tree){
  long pos=this.pos.getStartPosition(file,tree);
  if (pos == -1 && tree instanceof JCVariableDecl) {
    return ((JCVariableDecl)tree).pos;
  }
  if (pos == -1 && tree instanceof JCMethodDecl) {
    JCMethodDecl mt=(JCMethodDecl)tree;
    if (mt.restype == null)     return mt.pos;
  }
  return pos;
}
Program: 83479
Project: 83479
Buggy source:
/** 
 * Method declaration.
 */
public Void visitMethod(MethodTree mt,Void _){
  ExecutableElement e=(ExecutableElement)TreeUtil.getElement(mt);
  if (e != null) {
    Tree prev=mt.getReturnType();
    String name=mt.getName().toString();
    Token token;
    if (prev != null)     token=gen.findTokenAfter(prev,true,name);
 else     token=gen.findTokenAfter(mt,false,name);
    if (token != null)     gen.add(new Tag.DeclName(lineMap,token));
    ParsedType pt=getParsedType((TypeElement)e.getEnclosingElement());
    gen.add(new Tag.MethodDecl(cu,srcPos,mt,e,pt.findOverriddenMethods(elements,e),pt.findOverridingMethods(elements,e)));
  }
  return super.visitMethod(mt,_);
}

Fixed version (ground truth):
/** 
 * Method declaration.
 */
public Void visitMethod(MethodTree mt,Void _){
  ExecutableElement e=(ExecutableElement)TreeUtil.getElement(mt);
  if (e != null) {
    if (e.getKind() == ElementKind.CONSTRUCTOR && e.getEnclosingElement().getSimpleName().length() == 0)     return _;
    Tree prev=mt.getReturnType();
    String name=mt.getName().toString();
    Token token;
    if (prev != null)     token=gen.findTokenAfter(prev,true,name);
 else     token=gen.findTokenAfter(mt,false,name);
    if (token != null)     gen.add(new Tag.DeclName(lineMap,token));
    ParsedType pt=getParsedType((TypeElement)e.getEnclosingElement());
    gen.add(new Tag.MethodDecl(cu,srcPos,mt,e,pt.findOverriddenMethods(elements,e),pt.findOverridingMethods(elements,e)));
  }
  return super.visitMethod(mt,_);
}
Program: 83480
Project: 83480
Buggy source:
public void write(JsonWriter w){
  w.startObject();
  w.property("String_Node_Str",name);
  w.property("String_Node_Str",baseUrl);
  w.propertyUnquoted("String_Node_Str",getLinker());
  w.property("String_Node_Str",packageNames);
  w.endObject();
}

Fixed version (ground truth):
public void write(JsonWriter w){
  w.property("String_Node_Str",name);
  w.property("String_Node_Str",baseUrl);
  w.propertyUnquoted("String_Node_Str",getLinker());
  w.property("String_Node_Str",packageNames);
}
Program: 83481
Project: 83481
Buggy source:
public void generateClassListJs(PackageElement p,PrintWriter w) throws IOException {
  try {
    w.printf("String_Node_Str",p.getQualifiedName());
    JsonWriter jw=new JsonWriter(w);
    jw.startArray();
    for (    TypeElement t : pss.getClassElements(p)) {
      jw.startObject();
      jw.property("String_Node_Str",t.getSimpleName());
      jw.property("String_Node_Str",getKindString(t.getKind()));
      jw.property("String_Node_Str",t.getQualifiedName().toString().replace('.','/') + "String_Node_Str");
      jw.property("String_Node_Str",getAccessLevel(t));
      jw.endObject();
    }
    jw.endArray();
    w.println("String_Node_Str");
  }
  finally {
    w.close();
  }
}

Fixed version (ground truth):
public void generateClassListJs(PackageElement p,PrintWriter w) throws IOException {
  try {
    w.printf("String_Node_Str",p.getQualifiedName());
    JsonWriter jw=new JsonWriter(w);
    jw.startArray();
    for (    TypeElement t : pss.getClassElements(p)) {
      if (pss.getTrees().getTree(t) == null)       continue;
      jw.startObject();
      jw.property("String_Node_Str",t.getSimpleName());
      jw.property("String_Node_Str",getKindString(t.getKind()));
      jw.property("String_Node_Str",t.getQualifiedName().toString().replace('.','/') + "String_Node_Str");
      jw.property("String_Node_Str",getAccessLevel(t));
      jw.endObject();
    }
    jw.endArray();
    w.println("String_Node_Str");
  }
  finally {
    w.close();
  }
}
Program: 83483
Project: 83483
Buggy source:
/** 
 * Class declaration.
 */
public Void visitClass(ClassTree ct,Void _){
  TypeElement e=(TypeElement)TreeUtil.getElement(ct);
  if (e != null) {
    Token token=gen.findTokenAfter(ct,false,ct.getSimpleName().toString());
    if (token != null)     gen.add(new DeclName(lineMap,token));
    List<ParsedType> descendants=getParsedType(e).descendants;
    gen.add(new Tag.ClassDecl(cu,srcPos,ct,e,descendants));
    if (e.getNestingKind() == NestingKind.ANONYMOUS) {
      scan(ct.getMembers());
      return _;
    }
  }
  return super.visitClass(ct,_);
}

Fixed version (ground truth):
/** 
 * Class declaration.
 */
public Void visitClass(ClassTree ct,Void _){
  TypeElement e=(TypeElement)TreeUtil.getElement(ct);
  if (e != null) {
    Token token;
    if (ct.getModifiers() != null)     token=gen.findTokenAfter(ct.getModifiers(),true,ct.getSimpleName().toString());
 else     token=gen.findTokenAfter(ct,false,ct.getSimpleName().toString());
    if (token != null)     gen.add(new DeclName(lineMap,token));
    List<ParsedType> descendants=getParsedType(e).descendants;
    gen.add(new Tag.ClassDecl(cu,srcPos,ct,e,descendants));
    if (e.getNestingKind() == NestingKind.ANONYMOUS) {
      scan(ct.getMembers());
      return _;
    }
  }
  return super.visitClass(ct,_);
}
Program: 83485
Project: 83485
Buggy source:
protected void writeItem(ExecutableElement e){
  beginArray();
  sep();
  ref((TypeElement)e.getEnclosingElement());
  sep();
  string(e.getSimpleName());
  beginArray();
  for (  VariableElement v : e.getParameters()) {
    sep();
    TypeMirror vt=pss.getTypes().erasure(v.asType());
    TypeElement ve=(TypeElement)pss.getTypes().asElement(vt);
    if (ve != null)     ref(ve);
 else     string(vt.toString());
  }
  endArray();
  writeModifiers(e);
  endArray();
}

Fixed version (ground truth):
protected void writeItem(ExecutableElement e){
  beginArray();
  sep();
  ref((TypeElement)e.getEnclosingElement());
  sep();
  if (e.getKind() == ElementKind.CONSTRUCTOR)   string(e.getEnclosingElement().getSimpleName());
 else   string(e.getSimpleName());
  beginArray();
  for (  VariableElement v : e.getParameters()) {
    sep();
    TypeMirror vt=pss.getTypes().erasure(v.asType());
    TypeElement ve=(TypeElement)pss.getTypes().asElement(vt);
    if (ve != null)     ref(ve);
 else     string(vt.toString());
  }
  endArray();
  writeModifiers(e);
  endArray();
}
Program: 83486
Project: 83486
Buggy source:
/** 
 * Adds the given   {@link TreePath} to the {@link NodePkgInfo} tree rooted at this object.
 */
protected Node add(TreePath t){
  NodePkgInfo leafPkg=super.add(TreeUtil.getPackageName(t.getCompilationUnit()));
  NodeMapOwner leaf=addNode(leafPkg,t);
  return (Node)leaf;
}

Fixed version (ground truth):
/** 
 * Adds the given   {@link TreePath} to the {@link NodePkgInfo} tree rooted at this object.
 */
protected ParentNode add(TreePath t){
  NodePkgInfo leafPkg=super.add(TreeUtil.getPackageName(t.getCompilationUnit()));
  return addNode(leafPkg,t);
}
Program: 83487
Project: 83487
Buggy source:
/** 
 * Adds the given   {@link TreePath} to the {@link Node} treerooted at "root" node, by using the part of the path that falls within the same compilation unit. then return the  {@link Node} wherethe  {@link TreePath} is ultimately stored.
 */
NodeMapOwner addNode(NodeMapOwner root,TreePath t){
  NodeMapOwner p;
  if (t.getParentPath() != null)   p=addNode(root,t.getParentPath());
 else   p=root;
  if (TreeUtil.OUTLINE_WORTHY_TREE.contains(t.getLeaf().getKind())) {
    Element e=TreeUtil.getElement(t.getLeaf());
    if (e != null)     return p.getChildren().getOrCreate(e,t);
  }
  return p;
}

Fixed version (ground truth):
/** 
 * Adds the given   {@link TreePath} to the {@link Node} treerooted at "root" node, by using the part of the path that falls within the same compilation unit. then return the  {@link Node} wherethe  {@link TreePath} is ultimately stored.
 */
ParentNode addNode(ParentNode root,TreePath t){
  ParentNode p;
  if (t.getParentPath() != null)   p=addNode(root,t.getParentPath());
 else   p=root;
  if (TreeUtil.OUTLINE_WORTHY_TREE.contains(t.getLeaf().getKind())) {
    Element e=TreeUtil.getElement(t.getLeaf());
    if (e != null)     return p.getChildren().getOrCreate(e,t);
  }
  return p;
}
Program: 83488
Project: 83488
Buggy source:
public static boolean isType(Element e){
  if (e == null)   return false;
switch (e.getKind()) {
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
    return !e.asType().getKind().isPrimitive();
}
return false;
}

Fixed version (ground truth):
public static boolean isType(Element e){
  if (e == null)   return false;
switch (e.getKind()) {
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
    TypeKind kind=e.asType().getKind();
  return !kind.isPrimitive() && kind != TypeKind.VOID;
}
return false;
}
Program: 83489
Project: 83489
Buggy source:
public String href(Element e){
  StringBuilder buf=visit(e);
  if (buf == null)   return null;
  return buf.toString();
}

Fixed version (ground truth):
public String href(Element e){
  StringBuilder buf=visit(e);
  if (buf == null)   return null;
  if (buf.length() == 0)   return "String_Node_Str";
  return buf.toString();
}
Program: 83490
Project: 83490
Buggy source:
public StringBuilder visitType(TypeElement t,Void _){
  ClassTree ct=trees.getTree(t);
  if (ct == null)   return null;
switch (t.getNestingKind()) {
case ANONYMOUS:
    String binaryName=elements.getBinaryName(t).toString();
  int idx=binaryName.lastIndexOf('$');
String name="String_Node_Str" + binaryName.substring(idx);
return combine(getEnclosingTypeOrPackage(t).accept(this,null)).append(name);
case TOP_LEVEL:
CompilationUnitTree owner=pss.getTreePathByClass().get(ct).getCompilationUnit();
String primaryTypeName=TreeUtil.getPrimaryTypeName(owner);
String simpleName=ct.getSimpleName().toString();
StringBuilder buf;
if (!owner.equals(compUnit)) {
buf=combine(recurse(t)).append(primaryTypeName).append("String_Node_Str");
}
 else {
buf=new StringBuilder();
}
if (!primaryTypeName.equals(simpleName)) {
return buf.append("String_Node_Str").append(simpleName);
}
 else {
return buf.append("String_Node_Str");
}
case MEMBER:
case LOCAL:
return recurse(t).append('~').append(t.getSimpleName());
default :
throw new IllegalStateException(t.getNestingKind().toString());
}
}

Fixed version (ground truth):
public StringBuilder visitType(TypeElement t,Void _){
  ClassTree ct=trees.getTree(t);
  if (ct == null)   return null;
switch (t.getNestingKind()) {
case ANONYMOUS:
    String binaryName=elements.getBinaryName(t).toString();
  int idx=binaryName.lastIndexOf('$');
String name="String_Node_Str" + binaryName.substring(idx);
return combine(getEnclosingTypeOrPackage(t).accept(this,null)).append(name);
case TOP_LEVEL:
CompilationUnitTree owner=pss.getTreePathByClass().get(ct).getCompilationUnit();
String primaryTypeName=TreeUtil.getPrimaryTypeName(owner);
String simpleName=ct.getSimpleName().toString();
StringBuilder buf;
if (!owner.equals(compUnit)) {
buf=combine(recurse(t)).append(primaryTypeName).append("String_Node_Str");
}
 else {
buf=new StringBuilder();
}
if (!primaryTypeName.equals(simpleName)) {
buf.append("String_Node_Str").append(simpleName);
}
return buf;
case MEMBER:
case LOCAL:
return recurse(t).append('~').append(t.getSimpleName());
default :
throw new IllegalStateException(t.getNestingKind().toString());
}
}
Program: 83491
Project: 83491
Buggy source:
public void writeBody(PrintWriter out) throws IOException {
  out.println("String_Node_Str");
  super.writeBody(out);
  out.println("String_Node_Str");
  out.println("String_Node_Str");
  out.println("String_Node_Str");
  out.println("String_Node_Str");
  out.println("String_Node_Str");
  out.println("String_Node_Str" + relativeLinkToTop + "String_Node_Str");
  out.println("String_Node_Str");
}

Fixed version (ground truth):
public void writeBody(PrintWriter out) throws IOException {
  out.print("String_Node_Str");
  super.writeBody(out);
  out.println("String_Node_Str");
  out.println("String_Node_Str");
  out.println("String_Node_Str");
  out.println("String_Node_Str");
  out.println("String_Node_Str");
  out.println("String_Node_Str" + relativeLinkToTop + "String_Node_Str");
  out.println("String_Node_Str");
}
Program: 83492
Project: 83492
Buggy source:
/** 
 * Finds the first identifier token after the given tree. <p> This is used to identify the position of few nodes that are not available from javac.
 * @param t The first token after the end position of this tree node will be returned.
 * @param id If non-null, find the first token that has this identifier.
 * @return nullif no such node is found or a syntax error is detected.
 */
protected final Token findTokenAfter(Tree t,String id){
  long pos=pss.getSourcePositions().getEndPosition(compUnit,t);
  if (pos < 0)   return null;
  JavaLexer lexer=new JavaLexer(new StringReader(sourceFile.substring((int)pos)));
  lexer.setTabSize(pss.getTabWidth());
  try {
    while (true) {
      Token token=lexer.nextToken();
      int type=token.getType();
      if (type == JavaTokenTypes.EOF)       break;
      if (type == JavaTokenTypes.IDENT) {
        if (id != null && !token.getText().equals(id))         continue;
        LineMap lm=compUnit.getLineMap();
        token.setLine(token.getLine() + (int)lm.getLineNumber(pos) - 1);
        token.setColumn(token.getColumn() + (int)lm.getColumnNumber(pos) - 1);
        return token;
      }
    }
  }
 catch (  TokenStreamException e) {
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Finds the first identifier token after the given tree. <p> This is used to identify the position of few nodes that are not available from javac.
 * @param t The first token after the end position of this tree node will be returned.
 * @param findAfterToken true if the search should begin from the end of the given token. false to start from the start of the given token.
 * @param id If non-null, find the first token that has this identifier.
 * @return nullif no such node is found or a syntax error is detected.
 */
protected final Token findTokenAfter(Tree t,boolean findAfterToken,String id){
  long pos;
  if (findAfterToken)   pos=pss.getSourcePositions().getEndPosition(compUnit,t);
 else   pos=pss.getSourcePositions().getStartPosition(compUnit,t);
  if (pos < 0)   return null;
  JavaLexer lexer=new JavaLexer(new StringReader(sourceFile.substring((int)pos)));
  lexer.setTabSize(pss.getTabWidth());
  try {
    while (true) {
      Token token=lexer.nextToken();
      int type=token.getType();
      if (type == JavaTokenTypes.EOF)       break;
      if (type == JavaTokenTypes.IDENT) {
        if (id != null && !token.getText().equals(id))         continue;
        LineMap lm=compUnit.getLineMap();
        token.setLine(token.getLine() + (int)lm.getLineNumber(pos) - 1);
        token.setColumn(token.getColumn() + (int)lm.getColumnNumber(pos) - 1);
        return token;
      }
    }
  }
 catch (  TokenStreamException e) {
  }
  return null;
}
Program: 83493
Project: 83493
Buggy source:
protected final void addDecl(Token t,Element e){
  long sp=lineMap.getPosition(t.getLine(),t.getColumn());
  long ep=sp + t.getText().length();
  String id=buildId(e);
  gen.add(new TagMarker(sp,ep,'#' + id,getCssClass(e,"String_Node_Str"),id,buildUsage(e)));
}

Fixed version (ground truth):
protected final void addDecl(Token t,Element e){
  if (t == null)   return;
  long sp=lineMap.getPosition(t.getLine(),t.getColumn());
  long ep=sp + t.getText().length();
  String id=buildId(e);
  gen.add(new TagMarker(sp,ep,'#' + id,getCssClass(e,"String_Node_Str"),id,buildUsage(e)));
}
Program: 83494
Project: 83494
Buggy source:
/** 
 * Definition of a variable, such as parameter, field, and local variables.
 */
public Void visitVariable(VariableTree vt,Void _){
  Element e=TreeUtil.getElement(vt);
  if (e != null) {
    if (e.getKind() != ElementKind.ENUM_CONSTANT) {
      Token t=gen.findTokenAfter(vt.getType(),vt.getName().toString());
      if (t != null) {
        addDecl(t,e);
      }
    }
 else {
      addDecl(vt,e);
    }
  }
  return super.visitVariable(vt,_);
}

Fixed version (ground truth):
/** 
 * Definition of a variable, such as parameter, field, and local variables.
 */
public Void visitVariable(VariableTree vt,Void _){
  Element e=TreeUtil.getElement(vt);
  if (e != null) {
    if (e.getKind() != ElementKind.ENUM_CONSTANT) {
      addDecl(gen.findTokenAfter(vt.getType(),true,vt.getName().toString()),e);
    }
 else {
      addDecl(vt,e);
    }
  }
  return super.visitVariable(vt,_);
}
Program: 83496
Project: 83496
Buggy source:
/** 
 * Method declaration.
 */
public Void visitMethod(MethodTree mt,Void _){
  ExecutableElement e=(ExecutableElement)TreeUtil.getElement(mt);
  if (e != null) {
    addDecl(mt,e);
    ParsedType pt=getParsedType((TypeElement)e.getEnclosingElement());
    Set<Match> r=pt.findOverriddenMethods(elements,e);
    if (!r.isEmpty()) {
      addBookmark(mt,new OverriddenMethodsBookmark(r,linkResolver));
    }
    r=pt.findOverridingMethods(elements,e);
    if (!r.isEmpty()) {
      addBookmark(mt,new OverridingMethodsBookmark(r,linkResolver));
    }
  }
  return super.visitMethod(mt,_);
}

Fixed version (ground truth):
/** 
 * Method declaration.
 */
public Void visitMethod(MethodTree mt,Void _){
  ExecutableElement e=(ExecutableElement)TreeUtil.getElement(mt);
  if (e != null) {
    Tree prev=mt.getReturnType();
    if (prev != null)     addDecl(gen.findTokenAfter(prev,true,mt.getName().toString()),e);
 else     addDecl(gen.findTokenAfter(mt,false,mt.getName().toString()),e);
    ParsedType pt=getParsedType((TypeElement)e.getEnclosingElement());
    Set<Match> r=pt.findOverriddenMethods(elements,e);
    if (!r.isEmpty()) {
      addBookmark(mt,new OverriddenMethodsBookmark(r,linkResolver));
    }
    r=pt.findOverridingMethods(elements,e);
    if (!r.isEmpty()) {
      addBookmark(mt,new OverridingMethodsBookmark(r,linkResolver));
    }
  }
  return super.visitMethod(mt,_);
}
Program: 83497
Project: 83497
Buggy source:
/** 
 * Class declaration.
 */
public Void visitClass(ClassTree ct,Void _){
  TypeElement e=(TypeElement)TreeUtil.getElement(ct);
  if (e != null) {
    addDecl(ct,e);
    List<ParsedType> descendants=getParsedType(e).descendants;
    if (!descendants.isEmpty()) {
      addBookmark(ct,new SubClassBookmark(descendants,linkResolver));
    }
    if (e.getNestingKind() == NestingKind.ANONYMOUS) {
      scan(ct.getMembers());
      return _;
    }
  }
  return super.visitClass(ct,_);
}

Fixed version (ground truth):
/** 
 * Class declaration.
 */
public Void visitClass(ClassTree ct,Void _){
  TypeElement e=(TypeElement)TreeUtil.getElement(ct);
  if (e != null) {
    addDecl(gen.findTokenAfter(ct,false,ct.getSimpleName().toString()),e);
    List<ParsedType> descendants=getParsedType(e).descendants;
    if (!descendants.isEmpty()) {
      addBookmark(ct,new SubClassBookmark(descendants,linkResolver));
    }
    if (e.getNestingKind() == NestingKind.ANONYMOUS) {
      scan(ct.getMembers());
      return _;
    }
  }
  return super.visitClass(ct,_);
}
Program: 83498
Project: 83498
Buggy source:
public StringBuilder visitPackage(PackageElement p,Void _){
  if (!pss.getPackageElement().contains(p))   return null;
  String[] to=p.getQualifiedName().toString().split("String_Node_Str");
  int i;
  for (i=0; i < Math.min(to.length,pkg.length); i++)   if (!pkg[i].equals(to[i]))   break;
  StringBuilder buf=new StringBuilder();
  for (int j=i; j < pkg.length; j++) {
    buf.append("String_Node_Str");
  }
  for (int j=i; j < to.length; j++) {
    buf.append(to[j]).append('/');
  }
  if (buf.length() == 0)   buf.append("String_Node_Str");
  return buf;
}

Fixed version (ground truth):
public StringBuilder visitPackage(PackageElement p,Void _){
  if (!pss.getPackageElement().contains(p))   return null;
  String[] to;
  if (p.isUnnamed())   to=new String[0];
 else   to=p.getQualifiedName().toString().split("String_Node_Str");
  int i;
  for (i=0; i < Math.min(to.length,pkg.length); i++)   if (!pkg[i].equals(to[i]))   break;
  StringBuilder buf=new StringBuilder();
  for (int j=i; j < pkg.length; j++) {
    buf.append("String_Node_Str");
  }
  for (int j=i; j < to.length; j++) {
    buf.append(to[j]).append('/');
  }
  if (buf.length() == 0)   buf.append("String_Node_Str");
  return buf;
}
Program: 83499
Project: 83499
Buggy source:
/** 
 * Computes the full method name with the FQCN as parameter names.
 */
public static StringBuilder buildMethodName(StringBuilder buf,Types types,ExecutableElement e){
  buf.append(e.getSimpleName()).append('(');
  boolean first=true;
  List<? extends VariableElement> parameters=safeGetParameters(e);
  for (  VariableElement v : parameters) {
    buf.append(types.erasure(v.asType()));
    if (first)     first=false;
 else     buf.append(',');
  }
  return buf.append(')');
}

Fixed version (ground truth):
/** 
 * Computes the full method name with the FQCN as parameter names.
 */
public static StringBuilder buildMethodName(StringBuilder buf,Types types,ExecutableElement e){
  buf.append(e.getSimpleName()).append('(');
  boolean first=true;
  List<? extends VariableElement> parameters=safeGetParameters(e);
  for (  VariableElement v : parameters) {
    if (first)     first=false;
 else     buf.append(',');
    buf.append(types.erasure(v.asType()));
  }
  return buf.append(')');
}
Program: 83500
Project: 83500
Buggy source:
/** 
 * Method invocation of the form "exp.method()"
 */
public Void visitMethodInvocation(MethodInvocationTree mi,Void _){
  ExpressionTree ms=mi.getMethodSelect();
  Element e=TreeUtil.getElement(mi);
  if (e != null) {
    Name methodName=e.getSimpleName();
    long ep=srcPos.getEndPosition(cu,ms);
    gen.add(new LinkMarker(ep - methodName.length(),ep,linkResolver.href(e),getCssClass(e,"String_Node_Str")));
  }
  return super.visitMethodInvocation(mi,_);
}

Fixed version (ground truth):
/** 
 * Method invocation of the form "exp.method()"
 */
public Void visitMethodInvocation(MethodInvocationTree mi,Void _){
  ExpressionTree ms=mi.getMethodSelect();
  Element e=TreeUtil.getElement(mi);
  if (e != null) {
    Name methodName=e.getSimpleName();
    long ep=srcPos.getEndPosition(cu,ms);
    if (ep >= 0) {
      gen.add(new LinkMarker(ep - methodName.length(),ep,linkResolver.href(e),getCssClass(e,"String_Node_Str")));
    }
  }
  return super.visitMethodInvocation(mi,_);
}
Program: 83501
Project: 83501
Buggy source:
/** 
 * Gets all the packages of the analyzed source files. <p> This does not include those packages that are just referenced. 
 * @return can be empty but never null.
 */
public Collection<PackageElement> getPackageElement(){
  return Collections.unmodifiableCollection(packages);
}

Fixed version (ground truth):
/** 
 * Gets all the packages of the analyzed source files. <p> This does not include those packages that are just referenced.
 * @return can be empty but never null.
 */
public Collection<PackageElement> getPackageElement(){
  return Collections.unmodifiableCollection(packages);
}
Program: 83503
Project: 83503
Buggy source:
public OutlineNameVisitor(ParsedSourceSet pss){
  this.javadocErasure=new JavadocErasureVisitor(pss.getTypes());
}

Fixed version (ground truth):
private OutlineNameVisitor(){
}
Program: 83504
Project: 83504
Buggy source:
public String visitExecutable(ExecutableElement e,Void _){
  StringBuilder buf=new StringBuilder();
  if (e.getKind() == ElementKind.CONSTRUCTOR)   buf.append(e.getEnclosingElement().getSimpleName());
 else   buf.append(e.getSimpleName());
  buf.append('(');
  boolean first=true;
  for (  VariableElement p : e.getParameters()) {
    if (first)     first=false;
 else     buf.append(',');
    buf.append(p.asType().accept(ShortNameVisitor.INSTANCE,null));
  }
  buf.append(')');
  if (e.getKind() != ElementKind.CONSTRUCTOR) {
    buf.append(':');
    buf.append(e.getReturnType().accept(javadocErasure,null));
  }
  return buf.toString();
}

Fixed version (ground truth):
public String visitExecutable(ExecutableElement e,Void _){
  StringBuilder buf=new StringBuilder();
  if (e.getKind() == ElementKind.CONSTRUCTOR)   buf.append(e.getEnclosingElement().getSimpleName());
 else   buf.append(e.getSimpleName());
  buf.append('(');
  boolean first=true;
  for (  VariableElement p : e.getParameters()) {
    if (first)     first=false;
 else     buf.append(',');
    buf.append(p.asType().accept(ShortNameVisitor.INSTANCE,null));
  }
  buf.append(')');
  if (e.getKind() != ElementKind.CONSTRUCTOR) {
    buf.append(':');
    buf.append(e.getReturnType().accept(ShortNameVisitor.INSTANCE,null));
  }
  return buf.toString();
}
Program: 83506
Project: 83506
Buggy source:
/** 
 * Adds the given   {@link TreePath} to the {@link Node} treerooted at "this" node, then return the  {@link Node} wherethe  {@link TreePath} is ultimately stored.
 */
protected Node add(TreePath t){
  Node p;
  if (t.getParentPath() != null)   p=add(t.getParentPath());
 else   p=this;
  Element e=TreeUtil.getElement(t.getLeaf());
  if (e != null) {
    if (TreeUtil.OUTLINE_WORTHY.contains(e.getKind())) {
      Node n=p.children.get(e);
      if (n == null)       p.children.put(e,n=createNode(e,t));
      return n;
    }
  }
  return p;
}

Fixed version (ground truth):
/** 
 * Adds the given   {@link TreePath} to the {@link Node} treerooted at "this" node, then return the  {@link Node} wherethe  {@link TreePath} is ultimately stored.
 */
protected Node add(TreePath t){
  Node p;
  if (t.getParentPath() != null)   p=add(t.getParentPath());
 else   p=this;
  if (TreeUtil.OUTLINE_WORTHY_TREE.contains(t.getLeaf().getKind())) {
    Element e=TreeUtil.getElement(t.getLeaf());
    if (e != null) {
      Node n=p.children.get(e);
      if (n == null)       p.children.put(e,n=createNode(e,t));
      return n;
    }
  }
  return p;
}
Program: 83507
Project: 83507
Buggy source:
boolean pre(Tree t){
  Element e=pss.getTrees().getElement(getCurrentPath());
  if (e == null)   return false;
  long endPos=sourcePositions.getEndPosition(cu,t);
  if (endPos < 0)   return false;
  if (TreeUtil.OUTLINE_WORTHY.contains(e.getKind())) {
    jw.startObject();
    writeOutlineNodeProperties(jw,e,cu,t);
    jw.key("String_Node_Str").startArray();
    return true;
  }
  return false;
}

Fixed version (ground truth):
boolean pre(Tree t){
  Element e=pss.getTrees().getElement(getCurrentPath());
  if (e == null)   return false;
  long endPos=sourcePositions.getEndPosition(cu,t);
  if (endPos < 0)   return false;
  if (TreeUtil.OUTLINE_WORTHY_ELEMENT.contains(e.getKind())) {
    jw.startObject();
    writeOutlineNodeProperties(jw,e,cu,t);
    jw.key("String_Node_Str").startArray();
    return true;
  }
  return false;
}
Program: 83508
Project: 83508
Buggy source:
public FrameSetGenerator(ParsedSourceSet pss){
  this.pss=pss;
  this.nameVisitor=new OutlineNameVisitor(pss);
  this.linkResolverFactory=pss.getLinkResolverFactory();
  this.unnamed=pss.getElements().getPackageElement("String_Node_Str");
}

Fixed version (ground truth):
public FrameSetGenerator(ParsedSourceSet pss){
  this.pss=pss;
  this.linkResolverFactory=pss.getLinkResolverFactory();
  this.unnamed=pss.getElements().getPackageElement("String_Node_Str");
}
Program: 83509
Project: 83509
Buggy source:
/** 
 * Writes out <tt>project-usage.js</tt> that lists all classes for which we have usage index.
 */
public void generateProjectUsageJs(PrintWriter w) throws IOException {
  Map<PackageElement,Set<ParsedType>> pkgs=new TreeMap<PackageElement,Set<ParsedType>>(ParsedSourceSet.PACKAGENAME_COMPARATOR);
  for (  ParsedType pt : pss.getParsedTypes()) {
    if (pt.getReferers().length == 0)     continue;
    PackageElement pkg=pss.getElements().getPackageOf(pt.element);
    Set<ParsedType> types=pkgs.get(pkg);
    if (types == null)     pkgs.put(pkg,types=new HashSet<ParsedType>());
    if (!pt.isLocal())     types.add(pt);
  }
  w.println("String_Node_Str");
  JsonWriter js=new JsonWriter(w);
  js.startArray();
  for (  Entry<PackageElement,Set<ParsedType>> pkg : pkgs.entrySet()) {
    js.startObject();
    js.property("String_Node_Str",pkg.getKey().getQualifiedName());
    js.key("String_Node_Str");
    js.startArray();
    String[] names=new String[pkg.getValue().size()];
    int idx=0;
    for (    ParsedType pt : pkg.getValue()) {
      names[idx++]=pt.getPackageLocalName();
    }
    Arrays.sort(names);
    for (    String n : names) {
      js.string(n);
    }
    js.endArray();
    js.endObject();
  }
  js.endArray();
  w.println("String_Node_Str");
  w.close();
}

Fixed version (ground truth):
/** 
 * Writes out <tt>project-usage.js</tt> that lists all classes for which we have usage index.
 */
public void generateProjectUsageJs(PrintWriter w) throws IOException {
  Map<PackageElement,Set<ParsedType>> pkgs=new TreeMap<PackageElement,Set<ParsedType>>(ParsedSourceSet.PACKAGENAME_COMPARATOR);
  for (  ParsedType pt : pss.getParsedTypes()) {
    if (pt.getReferers().length == 0)     continue;
    PackageElement pkg=pss.getElements().getPackageOf(pt.element);
    Set<ParsedType> types=pkgs.get(pkg);
    if (types == null)     pkgs.put(pkg,types=new HashSet<ParsedType>());
    if (!pt.isLocal())     types.add(pt);
  }
  w.println("String_Node_Str");
  JsonWriter js=new JsonWriter(w);
  js.startArray();
  for (  Entry<PackageElement,Set<ParsedType>> pkg : pkgs.entrySet()) {
    js.startObject();
    js.property("String_Node_Str",pkg.getKey().getQualifiedName());
    js.key("String_Node_Str");
    js.startArray();
    String[] names=new String[pkg.getValue().size()];
    int idx=0;
    for (    ParsedType pt : pkg.getValue()) {
      names[idx++]=pt.getPackageLocalName();
    }
    Arrays.sort(names);
    for (    String n : names) {
      js.object(n);
    }
    js.endArray();
    js.endObject();
  }
  js.endArray();
  w.println("String_Node_Str");
  w.close();
}