Fix bug where we might have two reference-equals query subexpressions in an expression being passed to an AggregatingQueryExpressionVisitor.
@@ -19,6 +19,8 @@ import com.google.common.primitives.Booleans;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Argument;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment.ArgumentType;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction;
+import java.util.HashMap;
+import java.util.Map;
/**
* An implementation of {@link QueryExpressionVisitor} which recursively visits all nested {@link
@@ -29,24 +31,24 @@ public abstract class AggregatingQueryExpressionVisitor<T, C>
@Override
public T visit(BinaryOperatorExpression binaryOperatorExpression, C context) {
- ImmutableMap.Builder<QueryExpression, T> builder = ImmutableMap.builder();
+ Map<QueryExpression, T> queryExpressionMapping = new HashMap<>();
for (QueryExpression expr : binaryOperatorExpression.getOperands()) {
- builder.put(expr, expr.accept(this, context));
+ queryExpressionMapping.put(expr, expr.accept(this, context));
}
-
- return aggregate(builder.build());
+ return aggregate(ImmutableMap.copyOf(queryExpressionMapping));
}
@Override
public T visit(FunctionExpression functionExpression, C context) {
- ImmutableMap.Builder<QueryExpression, T> builder = ImmutableMap.builder();
+ Map<QueryExpression, T> queryExpressionMapping = new HashMap<>();
for (Argument argument : functionExpression.getArgs()) {
if (argument.getType() == ArgumentType.EXPRESSION) {
- builder.put(argument.getExpression(), argument.getExpression().accept(this, context));
+ queryExpressionMapping.put(
+ argument.getExpression(), argument.getExpression().accept(this, context));
}
}
- return aggregate(builder.build());
+ return aggregate(ImmutableMap.copyOf(queryExpressionMapping));
}
@Override
@@ -59,12 +61,12 @@ public abstract class AggregatingQueryExpressionVisitor<T, C>
@Override
public T visit(SetExpression setExpression, C context) {
- ImmutableMap.Builder<QueryExpression, T> builder = ImmutableMap.builder();
+ Map<QueryExpression, T> queryExpressionMapping = new HashMap<>();
for (TargetLiteral targetLiteral : setExpression.getWords()) {
- builder.put(targetLiteral, targetLiteral.accept(this, context));
+ queryExpressionMapping.put(targetLiteral, targetLiteral.accept(this, context));
}
- return aggregate(builder.build());
+ return aggregate(ImmutableMap.copyOf(queryExpressionMapping));
}
/**
