Program: 29516
Project: 29516
Buggy source:
@Override protected SoyExpression visitNullCoalescingOpNode(NullCoalescingOpNode node){
  final SoyExpression left=visit(node.getLeftChild());
  if (left.isNonNullable()) {
    return left;
  }
  final SoyExpression right=visit(node.getRightChild());
  SoyType nonNullLeftType=SoyTypes.removeNull(left.soyType());
  Features features=Features.of();
  if (Expression.areAllCheap(left,right)) {
    features=features.plus(Feature.CHEAP);
  }
  if (right.isNonNullable()) {
    features=features.plus(Feature.NON_NULLABLE);
  }
  if (nonNullLeftType.equals(right.soyType())) {
    if (left.isBoxed() == right.isBoxed()) {
      return right.withSource(firstNonNull(left,right));
    }
    if (right.isBoxed()) {
      Optional<SoyExpression> unboxedRight=right.tryUnbox();
      if (unboxedRight.isPresent()) {
        return left.withSource(firstNonNull(left,unboxedRight.get()));
      }
    }
 else {
      final Label leftIsNull=new Label();
      final Optional<SoyExpression> nullCheckedUnboxedLeft=left.withSource(new Expression(left.resultType(),features){
        @Override void doGen(        CodeBuilder cb){
          left.gen(cb);
          cb.dup();
          cb.ifNull(leftIsNull);
        }
      }
).asNonNullable().tryUnbox();
      if (nullCheckedUnboxedLeft.isPresent()) {
        return right.withSource(new Expression(right.resultType(),features){
          @Override void doGen(          CodeBuilder adapter){
            nullCheckedUnboxedLeft.get().gen(adapter);
            Label end=new Label();
            adapter.goTo(end);
            adapter.mark(leftIsNull);
            adapter.pop();
            right.gen(adapter);
            adapter.mark(end);
          }
        }
);
      }
    }
  }
  return SoyExpression.forSoyValue(UnknownType.getInstance(),firstNonNull(left.box().cast(SoyValue.class),right.box().cast(SoyValue.class)));
}

Fixed version (ground truth):
@Override protected SoyExpression visitNullCoalescingOpNode(NullCoalescingOpNode node){
  final SoyExpression left=visit(node.getLeftChild());
  if (left.isNonNullable()) {
    return left;
  }
  final SoyExpression right=visit(node.getRightChild());
  SoyType nonNullLeftType=SoyTypes.removeNull(left.soyType());
  Features features=Features.of();
  if (Expression.areAllCheap(left,right)) {
    features=features.plus(Feature.CHEAP);
  }
  if (right.isNonNullable()) {
    features=features.plus(Feature.NON_NULLABLE);
  }
  if (nonNullLeftType.equals(right.soyType())) {
    if (left.isBoxed() == right.isBoxed()) {
      return right.withSource(firstNonNull(left,right));
    }
    if (right.isBoxed()) {
      SoyExpression boxedLeft=left.box();
      return boxedLeft.withSource(firstNonNull(boxedLeft,right));
    }
 else {
      final Label leftIsNull=new Label();
      final Optional<SoyExpression> nullCheckedUnboxedLeft=left.withSource(new Expression(left.resultType(),features){
        @Override void doGen(        CodeBuilder cb){
          left.gen(cb);
          cb.dup();
          cb.ifNull(leftIsNull);
        }
      }
).asNonNullable().tryUnbox();
      if (nullCheckedUnboxedLeft.isPresent()) {
        return right.withSource(new Expression(right.resultType(),features){
          @Override void doGen(          CodeBuilder adapter){
            nullCheckedUnboxedLeft.get().gen(adapter);
            Label end=new Label();
            adapter.goTo(end);
            adapter.mark(leftIsNull);
            adapter.pop();
            right.gen(adapter);
            adapter.mark(end);
          }
        }
);
      }
    }
  }
  return SoyExpression.forSoyValue(UnknownType.getInstance(),firstNonNull(left.box().cast(SoyValue.class),right.box().cast(SoyValue.class)));
}