Buggy code:
public class Cql2ElmVisitor extends cqlBaseVisitor { private final ObjectFactory of = new ObjectFactory ( ) ; private final org . hl7 . cql_annotations . r1 . ObjectFactory af = new org . hl7 . cql_annotations . r1 . ObjectFactory ( ) ; private boolean annotate = false ; private boolean dateRangeOptimization = false ; private TokenStream tokenStream ; private LibraryInfo libraryInfo = null ; private Library library = null ; private TranslatedLibrary translatedLibrary = null ; private String currentContext = "Patient" ; private final Map < String , TranslatedLibrary > libraries = new HashMap < > ( ) ; private final Stack < QueryContext > queries = new Stack < > ( ) ; private final Stack < TimingOperatorContext > timingOperators = new Stack < > ( ) ; private final Stack < Narrative > narratives = new Stack < > ( ) ; private int currentToken = - 1 ; private int nextLocalId = 1 ; private final List < Retrieve > retrieves = new ArrayList < > ( ) ; private final List < Expression > expressions = new ArrayList < > ( ) ; private final List < CqlTranslatorException > errors = new ArrayList < > ( ) ; private Map < String , ModelHelper > modelHelpers = new HashMap < > ( ) ; private boolean implicitPatientCreated = false ; public void enableAnnotations ( ) { } public void disableAnnotations ( ) { } public void enableDateRangeOptimization ( ) { } public void disableDateRangeOptimization ( ) { } public TokenStream getTokenStream ( ) { } public void setTokenStream ( TokenStream value ) { } public LibraryInfo getLibraryInfo ( ) { } public void setLibraryInfo ( LibraryInfo value ) { } public Library getLibrary ( ) { } public List < Retrieve > getRetrieves ( ) { } public List < Expression > getExpressions ( ) { } public List < CqlTranslatorException > getErrors ( ) { } private int getNextLocalId ( ) { } private void pushNarrative ( @ NotNull ParseTree tree ) { } private Narrative popNarrative ( @ NotNull ParseTree tree , Object o ) { } @ Override public Object visit ( @ NotNull ParseTree tree ) { } @ Override public Object visitLogic ( @ NotNull LogicContext ctx ) { } @ Override public VersionedIdentifier visitLibraryDefinition ( @ NotNull LibraryDefinitionContext ctx ) { } @ Override public UsingDef visitUsingDefinition ( @ NotNull UsingDefinitionContext ctx ) { } @ Override public Object visitIncludeDefinition ( @ NotNull IncludeDefinitionContext ctx ) { } @ Override public ParameterDef visitParameterDefinition ( @ NotNull ParameterDefinitionContext ctx ) { } @ Override public NamedTypeSpecifier visitNamedTypeSpecifier ( @ NotNull NamedTypeSpecifierContext ctx ) { } @ Override public TupleElementDefinition visitTupleElementDefinition ( @ NotNull TupleElementDefinitionContext ctx ) { } @ Override public Object visitTupleTypeSpecifier ( @ NotNull TupleTypeSpecifierContext ctx ) { TupleType resultType = new TupleType ( ) ; TupleTypeSpecifier typeSpecifier = of . createTupleTypeSpecifier ( ) ; for ( TupleElementDefinitionContext definitionContext : ctx . tupleElementDefinition ( ) ) { TupleElementDefinition element = ( ( TupleElementDefinition ) ( visit ( definitionContext ) ) ) ; <START_BUG> resultType . addElement ( new TupleTypeElement ( element . getName ( ) , element . getResultType ( ) ) ) ; <END_BUG> typeSpecifier . getElement ( ) . add ( element ) ; } typeSpecifier . setResultType ( resultType ) ; return typeSpecifier ; } @ Override public IntervalTypeSpecifier visitIntervalTypeSpecifier ( @ NotNull IntervalTypeSpecifierContext ctx ) { } @ Override public ListTypeSpecifier visitListTypeSpecifier ( @ NotNull ListTypeSpecifierContext ctx ) { } @ Override public String visitCodeSystemVersion ( @ NotNull CodeSystemVersionContext ctx ) { } @ Override public String visitCodeSystemVersions ( @ NotNull CodeSystemVersionsContext ctx ) { } @ Override public ValueSetDef visitValuesetDefinition ( @ NotNull ValuesetDefinitionContext ctx ) { } @ Override public Object visitContextDefinition ( @ NotNull ContextDefinitionContext ctx ) { } @ Override public ExpressionDef visitExpressionDefinition ( @ NotNull ExpressionDefinitionContext ctx ) { } @ Override public Literal visitStringLiteral ( @ NotNull StringLiteralContext ctx ) { } @ Override public Literal visitBooleanLiteral ( @ NotNull BooleanLiteralContext ctx ) { } @ Override public Object visitIntervalSelector ( @ NotNull IntervalSelectorContext ctx ) { } @ Override public Object visitTupleElementSelector ( @ NotNull TupleElementSelectorContext ctx ) { } @ Override public Object visitTupleSelector ( @ NotNull TupleSelectorContext ctx ) { } @ Override public Object visitListSelector ( @ NotNull ListSelectorContext ctx ) { } @ Override public Null visitNullLiteral ( @ NotNull NullLiteralContext ctx ) { } @ Override public Expression visitQuantityLiteral ( @ NotNull QuantityLiteralContext ctx ) { } @ Override public Not visitNotExpression ( @ NotNull NotExpressionContext ctx ) { } @ Override public Exists visitExistenceExpression ( @ NotNull ExistenceExpressionContext ctx ) { } @ Override public BinaryExpression visitMultiplicationExpressionTerm ( @ NotNull MultiplicationExpressionTermContext ctx ) { } @ Override public Power visitPowerExpressionTerm ( @ NotNull PowerExpressionTermContext ctx ) { } @ Override public Object visitPolarityExpressionTerm ( @ NotNull PolarityExpressionTermContext ctx ) { } @ Override public BinaryExpression visitAdditionExpressionTerm ( @ NotNull AdditionExpressionTermContext ctx ) { } @ Override public Object visitPredecessorExpressionTerm ( @ NotNull PredecessorExpressionTermContext ctx ) { } @ Override public Object visitSuccessorExpressionTerm ( @ NotNull SuccessorExpressionTermContext ctx ) { } @ Override public Object visitElementExtractorExpressionTerm ( @ NotNull ElementExtractorExpressionTermContext ctx ) { } @ Override public Object visitTimeBoundaryExpressionTerm ( @ NotNull TimeBoundaryExpressionTermContext ctx ) { } private DateTimePrecision parseDateTimePrecision ( String dateTimePrecision ) { } @ Override public Object visitTimeUnitExpressionTerm ( @ NotNull TimeUnitExpressionTermContext ctx ) { } @ Override public Object visitDurationExpressionTerm ( @ NotNull DurationExpressionTermContext ctx ) { } @ Override public Object visitRangeExpression ( @ NotNull RangeExpressionContext ctx ) { } @ Override public Object visitTimeRangeExpression ( @ NotNull TimeRangeExpressionContext ctx ) { } @ Override public Object visitWidthExpressionTerm ( @ NotNull WidthExpressionTermContext ctx ) { } @ Override public Expression visitParenthesizedTerm ( @ NotNull ParenthesizedTermContext ctx ) { } @ Override public Object visitMembershipExpression ( @ NotNull MembershipExpressionContext ctx ) { } @ Override public And visitAndExpression ( @ NotNull AndExpressionContext ctx ) { }

Fix:
resultType . addElement ( new TupleTypeElement ( element . getName ( ) , element . getType ( ) . getResultType ( ) ) ) ;