Buggy code:
public final class VocabularyCSVOutputHelper { public static final int CONCEPT_ENTRIES_COUNT = 6 ; public static final int URI_INDEX = 0 ; public static final int LABEL_INDEX = 1 ; public static final int DEFINITION_INDEX = 2 ; public static final int NOTATION_INDEX = 3 ; public static final int STATUS_INDEX = 4 ; public static final int ACCEPTED_DATE_INDEX = 5 ; private VocabularyCSVOutputHelper ( ) { } public static void writeCSV ( OutputStream out , String uriPrefix , String folderContextRoot , List < VocabularyConcept > concepts , List < Triple < String , String , Integer > > attributesMeta ) throws IOException { OutputStreamWriter osw = new OutputStreamWriter ( out , "UTF-8" ) ; VocabularyCSVOutputHelper . addBOM ( out ) ; List < String > toBeAddedToHeader = new ArrayList < String > ( ) ; for ( Triple < String , String , Integer > row : attributesMeta ) { String lang = "" ; if ( StringUtils . isNotEmpty ( row . getCentral ( ) ) ) { lang = "@" + ( row . getCentral ( ) ) ; } int numOfElements = row . getRight ( ) ; for ( int i = 0 ; i < numOfElements ; i ++ ) { toBeAddedToHeader . add ( ( ( row . getLeft ( ) ) + lang ) ) ; } } String [ ] entries = new String [ ( VocabularyCSVOutputHelper . CONCEPT_ENTRIES_COUNT ) + ( toBeAddedToHeader . size ( ) ) ] ; VocabularyCSVOutputHelper . addFixedEntryHeaders ( entries ) ; for ( int i = 0 ; i < ( toBeAddedToHeader . size ( ) ) ; i ++ ) { entries [ ( i + ( VocabularyCSVOutputHelper . CONCEPT_ENTRIES_COUNT ) ) ] = toBeAddedToHeader . get ( i ) ; } CSVWriter writer = new CSVWriter ( osw , ',' ) ; writer . writeNext ( entries ) ; DateFormat dateFormatter = new SimpleDateFormat ( "yyyy-MM-dd" ) ; for ( VocabularyConcept c : concepts ) { int elemPos = 0 ; String value = "" ; List < DataElement > attributeElems = null ; entries = new String [ ( VocabularyCSVOutputHelper . CONCEPT_ENTRIES_COUNT ) + ( toBeAddedToHeader . size ( ) ) ] ; entries [ VocabularyCSVOutputHelper . URI_INDEX ] = uriPrefix + ( c . getIdentifier ( ) ) ; entries [ VocabularyCSVOutputHelper . LABEL_INDEX ] = c . getLabel ( ) ; entries [ VocabularyCSVOutputHelper . DEFINITION_INDEX ] = c . getDefinition ( ) ; entries [ VocabularyCSVOutputHelper . NOTATION_INDEX ] = c . getNotation ( ) ; entries [ VocabularyCSVOutputHelper . STATUS_INDEX ] = c . getStatus ( ) . getLabel ( ) ; entries [ VocabularyCSVOutputHelper . ACCEPTED_DATE_INDEX ] = ( ( c . getAcceptedDate ( ) ) != null ) ? dateFormatter . format ( c . getAcceptedDate ( ) ) : "" ; for ( Triple < String , String , Integer > row : attributesMeta ) { String elemName = row . getLeft ( ) ; <START_BUG> attributeElems = getDataElementValuesByNameAndLang ( elemName , row . getCentral ( ) , c . getElementAttributes ( ) ) ; <END_BUG> int sizeOfAttributeElems = 0 ; if ( attributeElems != null ) { sizeOfAttributeElems = attributeElems . size ( ) ; for ( int j = 0 ; j < sizeOfAttributeElems ; j ++ ) { DataElement e = attributeElems . get ( j ) ; if ( e . isRelationalElement ( ) ) { value = e . getRelatedConceptUri ( ) ; } else if ( ( ( StringUtils . isNotEmpty ( e . getRelatedConceptIdentifier ( ) ) ) && ( StringUtils . isNotEmpty ( e . getDatatype ( ) ) ) ) && ( e . getDatatype ( ) . equalsIgnoreCase ( "reference" ) ) ) { value = folderContextRoot + ( e . getRelatedConceptIdentifier ( ) ) ; } else { value = e . getAttributeValue ( ) ; } entries [ ( ( ( VocabularyCSVOutputHelper . CONCEPT_ENTRIES_COUNT ) + elemPos ) + j ) ] = value ; } } int maximumNumberOfElements = row . getRight ( ) ; for ( int j = sizeOfAttributeElems ; j < maximumNumberOfElements ; j ++ ) { entries [ ( ( ( VocabularyCSVOutputHelper . CONCEPT_ENTRIES_COUNT ) + elemPos ) + j ) ] = null ; } elemPos += maximumNumberOfElements ; } writer . writeNext ( entries ) ; } writer . close ( ) ; osw . close ( ) ; } private static void addBOM ( OutputStream out ) throws IOException { } public static void addFixedEntryHeaders ( String [ ] entries ) { } }

Fix:
attributeElems = VocabularyOutputHelper . getDataElementValuesByNameAndLang ( elemName , row . getCentral ( ) , c . getElementAttributes ( ) ) ;