Program: 60477
Project: 60477
Buggy source:
public Module with(final Iterable<? extends Module> overrides){
  return new AbstractModule(){
    @Override public void configure(){
      final List<Element> elements=Elements.getElements(baseModules);
      final List<Element> overrideElements=Elements.getElements(overrides);
      final Set<Key<?>> overriddenKeys=Sets.newHashSet();
      final Set<Class<? extends Annotation>> overridesScopeAnnotations=Sets.newHashSet();
      new ModuleWriter(binder()){
        @Override public <T>Void visit(        Binding<T> binding){
          overriddenKeys.add(binding.getKey());
          return super.visit(binding);
        }
        @Override public Void visit(        ScopeBinding scopeBinding){
          overridesScopeAnnotations.add(scopeBinding.getAnnotationType());
          return super.visit(scopeBinding);
        }
        @Override public Void visit(        PrivateElements privateElements){
          overriddenKeys.addAll(privateElements.getExposedKeys());
          return super.visit(privateElements);
        }
      }
.writeAll(overrideElements);
      final Map<Scope,Object> scopeInstancesInUse=Maps.newHashMap();
      final List<ScopeBinding> scopeBindings=Lists.newArrayList();
      new ModuleWriter(binder()){
        @Override public <T>Void visit(        Binding<T> binding){
          if (!overriddenKeys.remove(binding.getKey())) {
            super.visit(binding);
            Scope scope=getScopeInstanceOrNull(binding);
            if (scope != null) {
              scopeInstancesInUse.put(scope,binding.getSource());
            }
          }
          return null;
        }
        void rewrite(        Binder binder,        PrivateElements privateElements,        Set<Key<?>> keysToSkip){
          PrivateBinder privateBinder=binder.withSource(privateElements.getSource()).newPrivateBinder();
          Set<Key<?>> skippedExposes=Sets.newHashSet();
          for (          Key<?> key : privateElements.getExposedKeys()) {
            if (keysToSkip.remove(key)) {
              skippedExposes.add(key);
            }
 else {
              privateBinder.withSource(privateElements.getExposedSource(key)).expose(key);
            }
          }
          for (          Element element : privateElements.getElements()) {
            if (element instanceof Binding && skippedExposes.remove(((Binding)element).getKey())) {
              continue;
            }
            if (element instanceof PrivateElements) {
              rewrite(privateBinder,(PrivateElements)element,skippedExposes);
              continue;
            }
            element.applyTo(privateBinder);
          }
        }
        @Override public Void visit(        PrivateElements privateElements){
          rewrite(binder,privateElements,overriddenKeys);
          return null;
        }
        @Override public Void visit(        ScopeBinding scopeBinding){
          scopeBindings.add(scopeBinding);
          return null;
        }
      }
.writeAll(elements);
      new ModuleWriter(binder()){
        @Override public Void visit(        ScopeBinding scopeBinding){
          if (!overridesScopeAnnotations.remove(scopeBinding.getAnnotationType())) {
            super.visit(scopeBinding);
          }
 else {
            Object source=scopeInstancesInUse.get(scopeBinding.getScope());
            if (source != null) {
              binder().withSource(source).addError("String_Node_Str",scopeBinding.getAnnotationType().getSimpleName());
            }
          }
          return null;
        }
      }
.writeAll(scopeBindings);
    }
    private Scope getScopeInstanceOrNull(    Binding<?> binding){
      return binding.acceptScopingVisitor(new DefaultBindingScopingVisitor<Scope>(){
        public Scope visitScope(        Scope scope){
          return scope;
        }
      }
);
    }
  }
;
}

Fixed version (ground truth):
public Module with(final Iterable<? extends Module> overrides){
  return new AbstractModule(){
    @Override public void configure(){
      final LinkedHashSet<Element> elements=new LinkedHashSet<Element>(Elements.getElements(baseModules));
      final List<Element> overrideElements=Elements.getElements(overrides);
      final Set<Key<?>> overriddenKeys=Sets.newHashSet();
      final Set<Class<? extends Annotation>> overridesScopeAnnotations=Sets.newHashSet();
      new ModuleWriter(binder()){
        @Override public <T>Void visit(        Binding<T> binding){
          overriddenKeys.add(binding.getKey());
          return super.visit(binding);
        }
        @Override public Void visit(        ScopeBinding scopeBinding){
          overridesScopeAnnotations.add(scopeBinding.getAnnotationType());
          return super.visit(scopeBinding);
        }
        @Override public Void visit(        PrivateElements privateElements){
          overriddenKeys.addAll(privateElements.getExposedKeys());
          return super.visit(privateElements);
        }
      }
.writeAll(overrideElements);
      final Map<Scope,Object> scopeInstancesInUse=Maps.newHashMap();
      final List<ScopeBinding> scopeBindings=Lists.newArrayList();
      new ModuleWriter(binder()){
        @Override public <T>Void visit(        Binding<T> binding){
          if (!overriddenKeys.remove(binding.getKey())) {
            super.visit(binding);
            Scope scope=getScopeInstanceOrNull(binding);
            if (scope != null) {
              scopeInstancesInUse.put(scope,binding.getSource());
            }
          }
          return null;
        }
        void rewrite(        Binder binder,        PrivateElements privateElements,        Set<Key<?>> keysToSkip){
          PrivateBinder privateBinder=binder.withSource(privateElements.getSource()).newPrivateBinder();
          Set<Key<?>> skippedExposes=Sets.newHashSet();
          for (          Key<?> key : privateElements.getExposedKeys()) {
            if (keysToSkip.remove(key)) {
              skippedExposes.add(key);
            }
 else {
              privateBinder.withSource(privateElements.getExposedSource(key)).expose(key);
            }
          }
          for (          Element element : privateElements.getElements()) {
            if (element instanceof Binding && skippedExposes.remove(((Binding)element).getKey())) {
              continue;
            }
            if (element instanceof PrivateElements) {
              rewrite(privateBinder,(PrivateElements)element,skippedExposes);
              continue;
            }
            element.applyTo(privateBinder);
          }
        }
        @Override public Void visit(        PrivateElements privateElements){
          rewrite(binder,privateElements,overriddenKeys);
          return null;
        }
        @Override public Void visit(        ScopeBinding scopeBinding){
          scopeBindings.add(scopeBinding);
          return null;
        }
      }
.writeAll(elements);
      new ModuleWriter(binder()){
        @Override public Void visit(        ScopeBinding scopeBinding){
          if (!overridesScopeAnnotations.remove(scopeBinding.getAnnotationType())) {
            super.visit(scopeBinding);
          }
 else {
            Object source=scopeInstancesInUse.get(scopeBinding.getScope());
            if (source != null) {
              binder().withSource(source).addError("String_Node_Str",scopeBinding.getAnnotationType().getSimpleName());
            }
          }
          return null;
        }
      }
.writeAll(scopeBindings);
    }
    private Scope getScopeInstanceOrNull(    Binding<?> binding){
      return binding.acceptScopingVisitor(new DefaultBindingScopingVisitor<Scope>(){
        public Scope visitScope(        Scope scope){
          return scope;
        }
      }
);
    }
  }
;
}