Buggy code:
public class ProduceFormInstance implements ProcessStateAction { private static Log log = LogFactory . getLog ( ProduceFormInstance . class ) ; public void processAction ( StateAction stateAction , Patient patient , PatientState patientState , HashMap < String , Object > parameters ) { } public void changeState ( PatientState patientState , HashMap < String , Object > parameters ) { } protected void produceForm ( Integer formId , Integer locationId , Integer locationTagId , Integer encounterId , Integer sessionId , FormInstance formInstance , PatientState patientState , Patient patient , String formName , ATDService atdService , Boolean autoPrint ) { String mergeDirectory = IOUtil . formatDirectoryName ( Util . getFormAttributeValue ( formId , FORM_ATTR_DEFAULT_MERGE_DIRECTORY , locationTagId , locationId ) ) ; String outputTypeString = Util . getFormAttributeValue ( formId , FORM_ATTR_OUTPUT_TYPE , locationTagId , locationId ) ; if ( outputTypeString == null ) { outputTypeString = Context . getAdministrationService ( ) . getGlobalProperty ( GLOBAL_PROP_DEFAULT_OUTPUT_TYPE ) ; if ( outputTypeString == null ) { outputTypeString = ChirdlUtilConstants . FORM_ATTR_VAL_TELEFORM_XML ; } } StringTokenizer tokenizer = new StringTokenizer ( outputTypeString , ChirdlUtilConstants . GENERAL_INFO_COMMA ) ; HashMap < String , OutputStream > outputs = new HashMap < String , OutputStream > ( ) ; int maxDssElements = org . openmrs . module . atd . util . Util . getMaxDssElements ( formId , locationTagId , locationId ) ; File pdfFile = null ; while ( tokenizer . hasMoreTokens ( ) ) { String mergeFilename = null ; try { String currToken = tokenizer . nextToken ( ) . trim ( ) ; if ( ( currToken . equalsIgnoreCase ( FORM_ATTR_VAL_TELEFORM_XML ) ) || ( currToken . equalsIgnoreCase ( FORM_ATTR_VAL_TELEFORM_PDF ) ) ) { File pendingDir = new File ( mergeDirectory , ChirdlUtilConstants . FILE_PENDING ) ; pendingDir . mkdirs ( ) ; mergeFilename = ( ( ( pendingDir . getAbsolutePath ( ) ) + ( File . separator ) ) + ( formInstance . toString ( ) ) ) + ( ChirdlUtilConstants . FILE_EXTENSION_XML ) ; } if ( currToken . equalsIgnoreCase ( FORM_ATTR_VAL_PDF ) ) { File pdfDir = new File ( mergeDirectory , ChirdlUtilConstants . FORM_ATTR_VAL_PDF ) ; pdfDir . mkdirs ( ) ; mergeFilename = ( ( ( pdfDir . getAbsolutePath ( ) ) + ( File . separator ) ) + ( formInstance . toString ( ) ) ) + ( ChirdlUtilConstants . FILE_EXTENSION_PDF ) ; pdfFile = new File ( mergeFilename ) ; } if ( mergeFilename != null ) { FileOutputStream output = new FileOutputStream ( mergeFilename ) ; outputs . put ( currToken , output ) ; } else { ProduceFormInstance . log . error ( "mergeFilename<seq2seq4repair_space>is<seq2seq4repair_space>null" ) ; } } catch ( IOException e ) { ProduceFormInstance . log . error ( ( "Could<seq2seq4repair_space>not<seq2seq4repair_space>produce<seq2seq4repair_space>merge<seq2seq4repair_space>xml<seq2seq4repair_space>for<seq2seq4repair_space>file:<seq2seq4repair_space>" + mergeFilename ) , e ) ; } } atdService . produce ( outputs , patientState , patient , encounterId , formName , maxDssElements , sessionId ) ; for ( OutputStream output : outputs . values ( ) ) { try { output . flush ( ) ; output . close ( ) ; } catch ( IOException e ) { } } <START_BUG> if ( ( Boolean . TRUE . equals ( autoPrint ) ) && ( pdfFile != null ) ) { <END_BUG> autoPrintForm ( formId , locationId , locationTagId , pdfFile ) ; } } protected void autoPrintForm ( Integer formId , Integer locationId , Integer locationTagId , File formToPrint ) { } }

Fix:
if ( ( ( Boolean . TRUE ) == autoPrint ) && ( pdfFile != null ) ) {