Program: 48177
Project: 48177
Buggy source:
/** 
 * Initialize the client by setting properties for Android and starting up each module.
 */
public void initialize(){
  if (initialized) {
    return;
  }
  notificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  AndroidUtils.initLogging(this);
  SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(this);
  String noFactory="String_Node_Str";
  String factoryImpl=preferences.getString("String_Node_Str",noFactory);
  if (factoryImpl.equals(noFactory)) {
    Intent i=new Intent(this,TerminalFactoryActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    i.putExtra("String_Node_Str",true);
    this.startActivity(i);
    return;
  }
  IFDProperties.setProperty("String_Node_Str",factoryImpl);
  WsdefProperties.setProperty("String_Node_Str","String_Node_Str");
  try {
    terminalFactory=(AndroidTerminalFactory)IFDTerminalFactory.getInstance();
  }
 catch (  IFDException e) {
    System.exit(0);
  }
  usingNFC=terminalFactory instanceof NFCFactory;
  if (usingNFC) {
    NfcManager manager=(NfcManager)this.getSystemService(Context.NFC_SERVICE);
    NfcAdapter adapter=manager.getDefaultAdapter();
    if (adapter == null || !adapter.isEnabled()) {
      Intent i=new Intent(this,NFCErrorActivity.class);
      i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
      this.startActivity(i);
      return;
    }
  }
  terminalFactory.start(this);
  env=new ClientEnv();
  management=new TinyManagement(env);
  env.setManagement(management);
  dispatcher=new MessageDispatcher(env);
  env.setDispatcher(dispatcher);
  gui=new AndroidUserConsent(this);
  ifd=new IFD();
  ifd.setDispatcher(dispatcher);
  ifd.setGUI(gui);
  ifd.addProtocol(ECardConstants.Protocol.PACE,new PACEProtocolFactory());
  env.setIFD(ifd);
  EstablishContext establishContext=new EstablishContext();
  EstablishContextResponse establishContextResponse=ifd.establishContext(establishContext);
  if (establishContextResponse.getResult().getResultMajor().equals(ECardConstants.Major.OK)) {
    if (establishContextResponse.getContextHandle() != null) {
      contextHandle=establishContextResponse.getContextHandle();
    }
 else {
      logger.error("String_Node_Str");
      MessageDialog dialog=gui.obtainMessageDialog();
      String message=lang.translationForKey("String_Node_Str");
      String title=lang.translationForKey("String_Node_Str");
      dialog.showMessageDialog(message,title,DialogType.ERROR_MESSAGE);
      shutdown();
      System.exit(0);
    }
  }
 else {
    logger.error("String_Node_Str");
    MessageDialog dialog=gui.obtainMessageDialog();
    String message=lang.translationForKey("String_Node_Str");
    String title=lang.translationForKey("String_Node_Str");
    dialog.showMessageDialog(message,title,DialogType.ERROR_MESSAGE);
    shutdown();
    System.exit(0);
  }
  try {
    recognition=new CardRecognition(ifd,contextHandle);
  }
 catch (  Exception ex) {
    logger.error(ex.getMessage(),ex);
    MessageDialog dialog=gui.obtainMessageDialog();
    String message=lang.translationForKey("String_Node_Str");
    String title=lang.translationForKey("String_Node_Str");
    dialog.showMessageDialog(message,title,DialogType.ERROR_MESSAGE);
    shutdown();
    System.exit(0);
  }
  em=new EventManager(recognition,env,contextHandle);
  env.setEventManager(em);
  this.cardStates=new CardStateMap();
  SALStateCallback salCallback=new SALStateCallback(recognition,cardStates);
  em.registerAllEvents(salCallback);
  em.registerAllEvents(this);
  sal=new TinySAL(env,cardStates);
  sal.setGUI(gui);
  sal.addProtocol(ECardConstants.Protocol.EAC2,new EAC2ProtocolFactory());
  sal.addProtocol(ECardConstants.Protocol.EAC_GENERIC,new EACGenericProtocolFactory());
  sal.addProtocol(ECardConstants.Protocol.PIN_COMPARE,new PINCompareProtocolFactory());
  sal.addProtocol(ECardConstants.Protocol.GENERIC_CRYPTO,new GenericCryptoProtocolFactory());
  env.setSAL(sal);
  em.initialize();
  try {
    IntentBinding binding=new IntentBinding();
    ControlHandlers handler=new ControlHandlers();
    GenericTCTokenHandler genericTCTokenHandler=new GenericTCTokenHandler(cardStates,dispatcher,gui,recognition);
    ControlHandler tcTokenHandler=new IntentTCTokenHandler(genericTCTokenHandler);
    handler.addControlHandler(tcTokenHandler);
    ControlInterface control=new ControlInterface(binding,handler);
    control.start();
    IntentHandlerActivity.setHandlers(binding.getHandlers());
  }
 catch (  Exception e) {
    System.exit(0);
  }
  PluginManager pm=new PluginManager(dispatcher,gui,recognition,cardStates,null);
  pm.addPlugin(new PINPlugin());
  initialized=true;
}

Fixed version (ground truth):
/** 
 * Initialize the client by setting properties for Android and starting up each module.
 */
public void initialize(){
  if (initialized) {
    return;
  }
  notificationManager=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
  AndroidUtils.initLogging(this);
  SharedPreferences preferences=PreferenceManager.getDefaultSharedPreferences(this);
  String noFactory="String_Node_Str";
  String factoryImpl=preferences.getString("String_Node_Str",noFactory);
  if (factoryImpl.equals(noFactory)) {
    Intent i=new Intent(this,TerminalFactoryActivity.class);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    i.putExtra("String_Node_Str",true);
    this.startActivity(i);
    return;
  }
  IFDProperties.setProperty("String_Node_Str",factoryImpl);
  WsdefProperties.setProperty("String_Node_Str","String_Node_Str");
  try {
    terminalFactory=(AndroidTerminalFactory)IFDTerminalFactory.getInstance();
  }
 catch (  IFDException e) {
    System.exit(0);
  }
  usingNFC=terminalFactory instanceof NFCFactory;
  if (usingNFC) {
    NfcManager manager=(NfcManager)this.getSystemService(Context.NFC_SERVICE);
    NfcAdapter adapter=manager.getDefaultAdapter();
    if (adapter == null || !adapter.isEnabled()) {
      Intent i=new Intent(this,NFCErrorActivity.class);
      i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
      this.startActivity(i);
      return;
    }
  }
  terminalFactory.start(this);
  env=new ClientEnv();
  management=new TinyManagement(env);
  env.setManagement(management);
  dispatcher=new MessageDispatcher(env);
  env.setDispatcher(dispatcher);
  gui=new AndroidUserConsent(this);
  ifd=new IFD();
  ifd.setDispatcher(dispatcher);
  ifd.setGUI(gui);
  ifd.addProtocol(ECardConstants.Protocol.PACE,new PACEProtocolFactory());
  env.setIFD(ifd);
  EstablishContext establishContext=new EstablishContext();
  EstablishContextResponse establishContextResponse=ifd.establishContext(establishContext);
  if (establishContextResponse.getResult().getResultMajor().equals(ECardConstants.Major.OK)) {
    if (establishContextResponse.getContextHandle() != null) {
      contextHandle=establishContextResponse.getContextHandle();
    }
 else {
      logger.error("String_Node_Str");
      MessageDialog dialog=gui.obtainMessageDialog();
      String message=lang.translationForKey("String_Node_Str");
      String title=lang.translationForKey("String_Node_Str");
      dialog.showMessageDialog(message,title,DialogType.ERROR_MESSAGE);
      shutdown();
      System.exit(0);
    }
  }
 else {
    logger.error("String_Node_Str");
    MessageDialog dialog=gui.obtainMessageDialog();
    String message=lang.translationForKey("String_Node_Str");
    String title=lang.translationForKey("String_Node_Str");
    dialog.showMessageDialog(message,title,DialogType.ERROR_MESSAGE);
    shutdown();
    System.exit(0);
  }
  try {
    recognition=new CardRecognition(ifd,contextHandle);
    recognition.setGUI(gui);
  }
 catch (  Exception ex) {
    logger.error(ex.getMessage(),ex);
    MessageDialog dialog=gui.obtainMessageDialog();
    String message=lang.translationForKey("String_Node_Str");
    String title=lang.translationForKey("String_Node_Str");
    dialog.showMessageDialog(message,title,DialogType.ERROR_MESSAGE);
    shutdown();
    System.exit(0);
  }
  em=new EventManager(recognition,env,contextHandle);
  env.setEventManager(em);
  this.cardStates=new CardStateMap();
  SALStateCallback salCallback=new SALStateCallback(recognition,cardStates);
  em.registerAllEvents(salCallback);
  em.registerAllEvents(this);
  sal=new TinySAL(env,cardStates);
  sal.setGUI(gui);
  sal.addProtocol(ECardConstants.Protocol.EAC2,new EAC2ProtocolFactory());
  sal.addProtocol(ECardConstants.Protocol.EAC_GENERIC,new EACGenericProtocolFactory());
  sal.addProtocol(ECardConstants.Protocol.PIN_COMPARE,new PINCompareProtocolFactory());
  sal.addProtocol(ECardConstants.Protocol.GENERIC_CRYPTO,new GenericCryptoProtocolFactory());
  env.setSAL(sal);
  em.initialize();
  try {
    IntentBinding binding=new IntentBinding();
    ControlHandlers handler=new ControlHandlers();
    GenericTCTokenHandler genericTCTokenHandler=new GenericTCTokenHandler(cardStates,dispatcher,gui,recognition);
    ControlHandler tcTokenHandler=new IntentTCTokenHandler(genericTCTokenHandler);
    handler.addControlHandler(tcTokenHandler);
    ControlInterface control=new ControlInterface(binding,handler);
    control.start();
    IntentHandlerActivity.setHandlers(binding.getHandlers());
  }
 catch (  Exception e) {
    System.exit(0);
  }
  PluginManager pm=new PluginManager(dispatcher,gui,recognition,cardStates,null);
  pm.addPlugin(new PINPlugin());
  initialized=true;
}