Skip to content

Commit

Permalink
Prohibit NestedSet from being passed to NestedSetBuilder.addAll.
Browse files Browse the repository at this point in the history
All call sites where this was happening have been cleaned up.

RELNOTES: None.
PiperOrigin-RevId: 250913770
  • Loading branch information
Googler authored and copybara-github committed May 31, 2019
1 parent 00e29b7 commit bed7e4f
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,12 @@ public NestedSetBuilder<E> add(E element) {
public NestedSetBuilder<E> addAll(Iterable<? extends E> elements) {
Preconditions.checkNotNull(elements);
if (elements instanceof NestedSet) {
NestedSet<? extends E> elementsAsNestedSet = (NestedSet<? extends E>) elements;
if (order.equals(Order.STABLE_ORDER)) {
// If direct/transitive order doesn't matter, add the nested set as a transitive member to
// avoid copying its elements.
return addTransitive(elementsAsNestedSet);
} else {
// Direct/transitive order matters, but we might be able to save an iteration if we hit the
// Iterables.size call below with a list instead of a nested set.
// TODO(jhorvitz): Are callers doing this intentionally?
elements = elementsAsNestedSet.toList();
return addTransitive((NestedSet<? extends E>) elements);
}
throw new IllegalArgumentException("NestedSet should be added as a transitive member");
}
if (items == null) {
items = CompactHashSet.createWithExpectedSize(Iterables.size(elements));
Expand Down

0 comments on commit bed7e4f

Please sign in to comment.