Buggy code:
@ Repository public class RevisionSaveRepositoryImpl implements RevisionSaveRepository { @ Autowired private ConfigurationRepository configurations ; @ Autowired private RevisionRepository revisions ; @ Autowired private StudyVariablesParser parser ; @ Autowired private ReferenceService references ; @ Override public Pair < ReturnResult , TransferData > saveRevision ( TransferData transferData ) { } private void finalizeSave ( RevisionData revision , TransferData transferData , Configuration configuration , DateTimeUserPair info , MutablePair < Boolean , Boolean > changesAndErrors ) { } private void finalizeStudy ( RevisionData revision , TransferData transferData , DateTimeUserPair info , MutablePair < Boolean , Boolean > changesAndErrors ) { } private void finalizePublication ( RevisionData data , TransferData transferData ) { } private void finalizeStudyAttachment ( RevisionData attachment , TransferData transferData , MutablePair < Boolean , Boolean > changesAndErrors ) { } private boolean hasVariablesFileFor ( Language language , RevisionData study ) { } private boolean variablesFileForEqual ( Language language , Long value , RevisionData study ) { } private boolean fileIsVarFile ( String path ) { } private boolean hasFile ( Pair < StatusCode , ValueDataField > fieldPair , TransferData transferData , MutablePair < Boolean , Boolean > changesAndErrors ) { } private boolean hasAndIsOriginal ( RevisionData revision ) { } private boolean attachmentAlreadyParsed ( RevisionData revision ) { } private void parseVariableFile ( RevisionData attachment , TransferData transferData , RevisionData study , Language language ) { } private class SaveHandler { private final DateTimeUserPair info ; private final RevisionKey key ; private final List < ImmutablePair < Long , ImmutablePair < String , Boolean > > > bidirectional = new ArrayList < > ( ) ; private SaveHandler ( DateTimeUserPair info , RevisionKey key ) { } private MutablePair < Boolean , Boolean > saveFields ( Configuration configuration , TransferData transferData , RevisionData revisionData ) { } private void checkBidirectionality ( Long id , List < Pair < String , Boolean > > pairs , DateTimeUserPair info ) { } private void doTypeSpecificBidirectionality ( RevisionData data , List < Pair < String , Boolean > > pairs , DateTimeUserPair info ) { } private Pair < StatusCode , Boolean > saveField ( Field field , Configuration configuration , TransferFieldContainer transferFields , DataFieldContainer dataFields , Map < String , Change > changeMap ) { } private Pair < StatusCode , Boolean > saveContainer ( Field field , Configuration configuration , TransferFieldContainer transferFields , DataFieldContainer dataFields , Map < String , Change > changeMap ) { } private void saveContainerRowsFor ( Language language , MutablePair < StatusCode , Boolean > returnPair , Field field , Configuration configuration , TransferField transferField , ContainerDataField container , Map < String , Change > changeMap ) { } private < T > void swap ( List < T > list , int a , int b ) { } private Pair < StatusCode , Boolean > saveReferenceContainer ( Field field , Configuration configuration , TransferFieldContainer transferFields , DataFieldContainer dataFields , Map < String , Change > changeMap ) { } private void cleanExtraRowsFromTransferField ( Language language , TransferField tf , RowContainerDataField container ) { } private Pair < StatusCode , Boolean > saveValue ( Field field , Configuration configuration , TransferFieldContainer transferFields , DataFieldContainer dataFields , Map < String , Change > changeMap ) { } private void saveValueFor ( Language language , MutablePair < StatusCode , Boolean > returnPair , Field field , Configuration configuration , TransferField transferField , DataFieldContainer dataFields , Map < String , Change > changeMap , TransferFieldContainer transferFields ) { Value value = transferField . currentAsValueFor ( language ) ; <START_BUG> FieldError typeError = value . typeCheck ( field . getType ( ) ) ; <END_BUG> if ( typeError != null ) { TransferValue tv = transferField . getValueFor ( language ) ; if ( tv != null ) { tv . addError ( typeError ) ; returnPair . setRight ( true ) ; } } Pair < StatusCode , ValueDataField > codePair = dataFields . dataField ( ValueDataFieldCall . check ( field . getKey ( ) , value , language ) . setConfiguration ( configuration ) ) ; StatusCode statusCode = codePair . getLeft ( ) ; boolean isFreeText = isFieldFreeText ( field . getKey ( ) , configuration ) ; if ( ! ( ( ( statusCode == ( StatusCode . FIELD_INSERT ) ) || ( statusCode == ( StatusCode . FIELD_UPDATE ) ) ) || ( ( statusCode == ( StatusCode . FIELD_NOT_WRITABLE ) ) && isFreeText ) ) ) { switch ( statusCode ) { case FIELD_NOT_MUTABLE : transferField . addErrorFor ( language , IMMUTABLE ) ; returnPair . setRight ( true ) ; break ; case FIELD_NOT_EDITABLE : transferField . addErrorFor ( language , NOT_EDITABLE ) ; returnPair . setRight ( true ) ; break ; default : break ; } } else { codePair = dataFields . dataField ( ValueDataFieldCall . set ( field . getKey ( ) , value , language ) . setInfo ( info ) . setConfiguration ( configuration ) . setChangeMap ( changeMap ) ) ; statusCode = codePair . getLeft ( ) ; if ( ( statusCode == ( StatusCode . FIELD_INSERT ) ) || ( statusCode == ( StatusCode . FIELD_UPDATE ) ) ) { returnPair . setLeft ( FIELD_CHANGED ) ; } } if ( ( field . getType ( ) ) == ( FieldType . SELECTION ) ) { SelectionList list = configuration . getRootSelectionList ( field . getSelectionList ( ) ) ; if ( ( ( list . getFreeText ( ) . isEmpty ( ) ) || ( ! ( value . hasValue ( ) ) ) ) || ( ! ( StringUtils . hasText ( list . getFreeTextKey ( ) ) ) ) ) { return ; } boolean saveFreeText = false ; for ( String free : list . getFreeText ( ) ) { if ( free . equals ( value . getValue ( ) ) ) { saveFreeText = true ; break ; } }

Fix:
FieldError typeError = ( value != null ) ? value . typeCheck ( field . getType ( ) ) : null ;