Buggy code:
class AttributeMetaDataRepository { private static final int BATCH_SIZE = 1000 ; public static final AttributeMetaDataMetaData META_DATA = AttributeMetaDataMetaData . INSTANCE ; private final UuidGenerator uuidGenerator ; private final Repository repository ; private EntityMetaDataRepository entityMetaDataRepository ; private final LanguageService languageService ; public AttributeMetaDataRepository ( ManageableRepositoryCollection collection , LanguageService languageService ) { } public void setEntityMetaDataRepository ( EntityMetaDataRepository entityMetaDataRepository ) { } Repository getRepository ( ) { } public Entity add ( AttributeMetaData att ) { } public Iterable < Entity > add ( Iterable < AttributeMetaData > attrs ) { Iterable < List < AttributeMetaData > > batches = Iterables . partition ( attrs , AttributeMetaDataRepository . BATCH_SIZE ) ; return new Iterable < Entity > ( ) { @ Override public Iterator < Entity > iterator ( ) { return java . util . stream . StreamSupport . stream ( batches . spliterator ( ) , false ) . flatMap ( ( batch ) -> { <START_BUG> List < Entity > attrEntities = convertToAttrEntities ( attrs ) ; <END_BUG> repository . add ( attrEntities . stream ( ) ) ; return attrEntities . stream ( ) ; } ) . iterator ( ) ; } private List < Entity > convertToAttrEntities ( Iterable < AttributeMetaData > attrs ) { return java . util . stream . StreamSupport . stream ( attrs . spliterator ( ) , false ) . map ( this :: convertToAttrEntity ) . collect ( Collectors . toList ( ) ) ; } private Entity convertToAttrEntity ( AttributeMetaData attr ) { Entity attributeMetaDataEntity = new org . molgenis . data . support . MapEntity ( AttributeMetaDataRepository . META_DATA ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . IDENTIFIER , uuidGenerator . generateId ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . NAME , attr . getName ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . DATA_TYPE , attr . getDataType ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . NILLABLE , attr . isNillable ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . AUTO , attr . isAuto ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . VISIBLE , attr . isVisible ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . LABEL , attr . getLabel ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . DESCRIPTION , attr . getDescription ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . AGGREGATEABLE , attr . isAggregateable ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . READ_ONLY , attr . isReadonly ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . UNIQUE , attr . isUnique ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . EXPRESSION , attr . getExpression ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . VISIBLE_EXPRESSION , attr . getVisibleExpression ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . VALIDATION_EXPRESSION , attr . getValidationExpression ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . DEFAULT_VALUE , attr . getDefaultValue ( ) ) ; if ( ( ( attr . getDataType ( ) ) instanceof EnumField ) && ( ( attr . getEnumOptions ( ) ) != null ) ) { attributeMetaDataEntity . set ( AttributeMetaDataMetaData . ENUM_OPTIONS , Joiner . on ( ',' ) . join ( attr . getEnumOptions ( ) ) ) ; } if ( ( attr . getRange ( ) ) != null ) { attributeMetaDataEntity . set ( AttributeMetaDataMetaData . RANGE_MIN , attr . getRange ( ) . getMin ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . RANGE_MAX , attr . getRange ( ) . getMax ( ) ) ; } if ( ( attr . getRefEntity ( ) ) != null ) { String entityName = attr . getRefEntity ( ) . getName ( ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . REF_ENTITY , entityName ) ; } if ( ( attr . getDataType ( ) ) instanceof CompoundField ) { List < Entity > attrPartsEntities = convertToAttrEntities ( attr . getAttributeParts ( ) ) ; repository . add ( attrPartsEntities . stream ( ) ) ; attributeMetaDataEntity . set ( AttributeMetaDataMetaData . PARTS , attrPartsEntities ) ; } for ( String languageCode : attr . getLabelLanguageCodes ( ) ) { String attributeName = ( ( AttributeMetaDataMetaData . LABEL ) + '-' ) + languageCode ; String label = attr . getLabel ( languageCode ) ; if ( label != null ) attributeMetaDataEntity . set ( attributeName , label ) ; } for ( String languageCode : attr . getDescriptionLanguageCodes ( ) ) { String attributeName = ( ( AttributeMetaDataMetaData . DESCRIPTION ) + '-' ) + languageCode ; String description = attr . getDescription ( languageCode ) ; if ( description != null ) attributeMetaDataEntity . set ( attributeName , description ) ; } return attributeMetaDataEntity ; } } ; } public void deleteAttributes ( Iterable < Entity > attributes ) { } public void deleteAll ( ) { } public DefaultAttributeMetaData toAttributeMetaData ( Entity entity ) { } No newline ; at end ; of file ; }

Fix:
List < Entity > attrEntities = convertToAttrEntities ( batch ) ;