Buggy code:
public class Application { public static Handler < DentalCheckups > checkupsHandler ; private static String surveysPath ; private static String endpoint ; private static String token ; private static final String version = "0.4" ; public static final String CURRENT_VERSION_CHECKSUM_URL = "https:////raw.githubusercontent.com//OnDoc//clinic-client//master//client//ondoc-clinic-client-0.23.jar.sha1" ; public static final String CURRENT_VERSION_URL = "https:////github.com//OnDoc//clinic-client//raw//master//client//ondoc-clinic-client-0.23.jar" ; private static Config config = Config . get ( ) ; private static void configure ( ) throws Exception { } private static void upload ( ) throws Exception { Application . configure ( ) ; if ( ( ( Application . surveysPath ) == null ) || ( Application . surveysPath . isEmpty ( ) ) ) { throw new Exception ( Message . ERROR_PATH_NOT_DEFINED ) ; } if ( ( ( Application . token ) == null ) || ( Application . token . isEmpty ( ) ) ) { throw new Exception ( Message . ERROR_TOKEN_NOT_DEFINED ) ; } File [ ] files = new File ( Application . surveysPath ) . listFiles ( ) ; if ( ( files . length ) < 1 ) { throw new Exception ( Message . ERROR_EMPTY_FOLDER ) ; } OnDoc client = ApiClient . getInstance ( ) ; Items < Patient > patientsToImport = new Items < Patient > ( ) ; Items < ToothState > toothStates = new Items < ToothState > ( ) ; patientsToImport . setItems ( new ArrayList < Patient > ( Arrays . asList ( client . getPatients ( ) ) ) ) ; toothStates . setItems ( new ArrayList < ToothState > ( Arrays . asList ( client . getToothStates ( ) ) ) ) ; if ( ( ! ( patientsToImport . hasItems ( ) ) ) || ( ! ( toothStates . hasItems ( ) ) ) ) { throw new Exception ( Message . ERROR_EMPTY_PATIENTS_LIST ) ; } List < Patient > patients = patientsToImport . getItems ( ) ; Application . checkupsHandler = new me . ondoc . file_handler . XMLHandler < DentalCheckups > ( ) . map ( DentalCheckups . class ) ; for ( final File file : files ) { String filename = file . getName ( ) ; if ( ( ! ( file . isFile ( ) ) ) || ( ! ( DentalCheckups . isValidFilename ( filename ) ) ) ) continue ; Iterator < DentalCheckups > checkupsIterator = Application . checkupsHandler . getIterator ( file , true ) ; if ( ( checkupsIterator == null ) || ( ! ( checkupsIterator . hasNext ( ) ) ) ) { Log . write ( ERROR_EMPTY_CHECKUPS_FILE ) ; continue ; } DentalCheckups dentalCheckups = checkupsIterator . next ( ) ; List < Checkup > checkups = dentalCheckups . getCheckups ( ) ; if ( checkups . isEmpty ( ) ) { Log . write ( ERROR_EMPTY_CHECKUPS_FILE ) ; continue ; } for ( final Checkup checkup : checkups ) { Patient patient = patientsToImport . first ( Patient . getFilterById ( ) , checkup . getPatient ( ) ) ; if ( ( patient == null ) || ( ! ( checkup . getPatient ( ) . equals ( patient . getPatientIdentifier ( ) ) ) ) ) { Log . write ( ( ( ( ( checkup . toString ( ) ) + "<seq2seq4repair_space>" ) + ( Message . ERROR_UNKNOWN_PATIENT ) ) + ( checkup . getPatient ( ) ) ) ) ; continue ; } List < Tooth > tooths = checkup . getTeeth ( ) . getTooths ( ) ; List < Tooth > uploadedTeeth = new ArrayList < Tooth > ( ) ; for ( Tooth tooth : tooths ) { if ( tooth == null ) continue ; ToothState currentToothState = toothStates . first ( ToothState . getFilterByName ( ) , tooth . getState ( ) ) ; if ( currentToothState == null ) { Log . write ( ( ( ( ( checkup . toString ( ) ) + "<seq2seq4repair_space>" ) + ( Message . ERROR_UNKNOWN_TOOTH_STATE ) ) + ( tooth . getState ( ) ) ) ) ; continue ; } tooth . setState ( currentToothState . getState ( ) ) ; <START_BUG> tooth . setPatient ( patient . toString ( ) ) ; <END_BUG> Tooth uploadedTooth ; try { uploadedTooth = client . uploadTooth ( tooth ) ; uploadedTeeth . add ( uploadedTooth ) ; } catch ( RetrofitError e ) { Log . write ( ( ( ( checkup . toString ( ) ) + "<seq2seq4repair_space>" ) + ( Message . ERROR_TOOTH_UPLOAD_FAILED ) ) ) ; Log . write ( e ) ; } } if ( ! ( uploadedTeeth . isEmpty ( ) ) ) { checkup . getTeeth ( ) . setTooths ( uploadedTeeth ) ; try { client . uploadCheckup ( checkup . updateTeethIdentificators ( ) ) ; } catch ( RetrofitError e ) { Log . write ( ( ( ( checkup . toString ( ) ) + "<seq2seq4repair_space>" ) + ( Message . ERROR_CHECKUP_UPLOAD_FAILED ) ) ) ; Log . write ( e ) ; } } } file . delete ( ) ; } } private static String sha1FromInputStream ( InputStream is ) throws Exception { } private static void update ( ) throws Exception { } public static void main ( String [ ] args ) { } No newline ; at end ; of file ; }

Fix:
tooth . setPatient ( patient . getPatientIdentifier ( ) ) ;