Program: 152871
Project: 152871
Buggy source:
void BuildActivityResultActions(){
  ActivityResultActions=new java.util.HashMap<Integer,RequestResponseAction>();
  ActivityResultActions.put(LoadProgramRequest,new RequestResponseAction(){
    public void Run(    int ResultCode,    android.content.Intent Data){
      final String ProgName=Data.getData().getPath();
      final boolean IsLib=Data.getIntExtra(Picker.AltIndexID,0) != 0;
      final boolean LoadingMasterLibrary=IsLib && ProgName.intern() == "String_Node_Str";
class LoadProgram extends Global.Task {
        private static final int LOAD_STATE=0;
        private static final int LOAD_MASTER_LIBRARY=1;
        private static final int LOAD_PROG=2;
        private static final int LOAD_DONE=3;
        private int Step;
        private Global.Task Subtask;
        private LoadProgram(        int Step){
          this.Step=Step;
          Subtask=null;
        }
        public LoadProgram(){
          this(StateLoaded ? LoadingMasterLibrary ? LOAD_MASTER_LIBRARY : LOAD_PROG : LOAD_STATE);
        }
        @Override public boolean PreRun(){
switch (Step) {
case LOAD_STATE:
            Subtask=new Persistent.RestoreState(Main.this);
          break;
case LOAD_MASTER_LIBRARY:
        Subtask=new Persistent.LoadMasterLibrary(Main.this);
      break;
case LOAD_PROG:
    Subtask=new Persistent.Load(ProgName,IsLib,false,Global.Disp,Global.Buttons,Global.Calc);
  break;
}
return Subtask != null && Subtask.PreRun();
}
@Override public void BGRun(){
if (Subtask != null) {
if (Step == LOAD_STATE) {
  Subtask.BGRun();
}
 else {
  try {
    Subtask.BGRun();
  }
 catch (  Persistent.DataFormatException Failed) {
    SetStatus(-1,Failed);
  }
}
}
}
@Override public void PostRun(){
if (Subtask != null) {
Subtask.PostRun();
switch (Step) {
case LOAD_STATE:
  StateLoaded=true;
Global.StartBGTask(new LoadProgram(LoadingMasterLibrary ? LOAD_MASTER_LIBRARY : LOAD_PROG),null);
break;
case LOAD_MASTER_LIBRARY:
case LOAD_PROG:
if (TaskFailure == null) {
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(IsLib ? R.string.library_loaded : R.string.program_loaded),LoadingMasterLibrary ? getString(R.string.master_library) : new java.io.File(ProgName).getName()),android.widget.Toast.LENGTH_SHORT).show();
Global.StartBGTask(new Global.Task(){
@Override public void BGRun(){
  Persistent.SaveState(Main.this,IsLib);
}
}
,getString(R.string.saving));
}
 else {
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.file_load_error),TaskFailure.toString()),android.widget.Toast.LENGTH_LONG).show();
}
break;
}
}
}
}
;
Global.StartBGTask(new LoadProgram(),getString(R.string.loading));
}
}
);
ActivityResultActions.put(SaveProgramRequest,new RequestResponseAction(){
public void Run(int ResultCode,android.content.Intent Data){
final String TheName=Data.getData().getPath().substring(1) + Persistent.ProgExt;
final String SaveDir=android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "String_Node_Str" + Persistent.ProgramsDir;
Global.StartBGTask(new Global.Task(){
@Override public void BGRun(){
try {
new java.io.File(SaveDir).mkdirs();
Persistent.Save(Global.Buttons,Global.Calc,false,false,SaveDir + "String_Node_Str" + TheName);
}
 catch (RuntimeException Failed) {
SetStatus(-1,Failed);
}
}
@Override public void PostRun(){
if (TaskStatus == 0) {
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.program_saved),TheName),android.widget.Toast.LENGTH_SHORT).show();
}
 else {
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.program_save_error),TaskFailure.toString()),android.widget.Toast.LENGTH_LONG).show();
}
}
}
,getString(R.string.saving));
}
}
);
ActivityResultActions.put(ImportDataRequest,new RequestResponseAction(){
public void Run(int ResultCode,android.content.Intent Data){
final String FileName=Data.getData().getPath();
try {
Global.Calc.ClearImport();
Global.Import.ImportData(FileName);
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.import_started),FileName),android.widget.Toast.LENGTH_SHORT).show();
}
 catch (Persistent.DataFormatException Failed) {
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.file_load_error),Failed.toString()),android.widget.Toast.LENGTH_LONG).show();
}
}
}
);
ActivityResultActions.put(ExportDataRequest,new RequestResponseAction(){
public void Run(int ResultCode,android.content.Intent Data){
switch (ResultCode) {
case android.app.Activity.RESULT_OK:
Global.Export.Close();
try {
String FileName=Data.getData().getPath();
if (!ExportAppend) {
final String SaveDir=android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "String_Node_Str" + Persistent.DataDir;
new java.io.File(SaveDir).mkdirs();
FileName=SaveDir + FileName;
}
Global.Export.Open(FileName,ExportAppend,ExportNumbersOnly);
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.export_started),FileName),android.widget.Toast.LENGTH_SHORT).show();
}
 catch (RuntimeException Failed) {
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.export_error),Failed.toString()),android.widget.Toast.LENGTH_LONG).show();
}
break;
case SwitchAppend:
case SwitchSaveAs:
ExportAppend=ResultCode == SwitchAppend;
LaunchExportPicker();
break;
}
}
}
);
}

Fixed version (ground truth):
void BuildActivityResultActions(){
  ActivityResultActions=new java.util.HashMap<Integer,RequestResponseAction>();
  ActivityResultActions.put(LoadProgramRequest,new RequestResponseAction(){
    public void Run(    int ResultCode,    android.content.Intent Data){
      final String ProgName=Data.getData().getPath();
      final boolean IsLib=Data.getIntExtra(Picker.AltIndexID,0) != 0;
      final boolean LoadingMasterLibrary=IsLib && ProgName.intern() == "String_Node_Str";
class LoadProgram extends Global.Task {
        private static final int LOAD_STATE=0;
        private static final int LOAD_MASTER_LIBRARY=1;
        private static final int LOAD_PROG=2;
        private static final int LOAD_DONE=3;
        private int Step;
        private Global.Task Subtask;
        private LoadProgram(        int Step){
          this.Step=Step;
          Subtask=null;
        }
        public LoadProgram(){
          this(StateLoaded ? LoadingMasterLibrary ? LOAD_MASTER_LIBRARY : LOAD_PROG : LOAD_STATE);
        }
        @Override public boolean PreRun(){
switch (Step) {
case LOAD_STATE:
            Subtask=new Persistent.RestoreState(Main.this);
          break;
case LOAD_MASTER_LIBRARY:
        Subtask=new Persistent.LoadMasterLibrary(Main.this);
      break;
case LOAD_PROG:
    Subtask=new Persistent.Load(ProgName,IsLib,false,Global.Disp,Global.Buttons,Global.Calc);
  break;
}
return Subtask != null && Subtask.PreRun();
}
@Override public void BGRun(){
if (Subtask != null) {
if (Step == LOAD_STATE) {
  Subtask.BGRun();
}
 else {
  try {
    Subtask.BGRun();
    if (Subtask.TaskFailure != null) {
      SetStatus(-1,Subtask.TaskFailure);
    }
  }
 catch (  Persistent.DataFormatException Failed) {
    SetStatus(-1,Failed);
  }
}
}
}
@Override public void PostRun(){
if (Subtask != null) {
Subtask.PostRun();
switch (Step) {
case LOAD_STATE:
  StateLoaded=true;
Global.StartBGTask(new LoadProgram(LoadingMasterLibrary ? LOAD_MASTER_LIBRARY : LOAD_PROG),null);
break;
case LOAD_MASTER_LIBRARY:
case LOAD_PROG:
if (TaskFailure == null) {
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(IsLib ? R.string.library_loaded : R.string.program_loaded),LoadingMasterLibrary ? getString(R.string.master_library) : new java.io.File(ProgName).getName()),android.widget.Toast.LENGTH_SHORT).show();
Global.StartBGTask(new Global.Task(){
@Override public void BGRun(){
  Persistent.SaveState(Main.this,IsLib);
}
}
,getString(R.string.saving));
}
 else {
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.file_load_error),TaskFailure.toString()),android.widget.Toast.LENGTH_LONG).show();
}
break;
}
}
}
}
;
Global.StartBGTask(new LoadProgram(),getString(R.string.loading));
}
}
);
ActivityResultActions.put(SaveProgramRequest,new RequestResponseAction(){
public void Run(int ResultCode,android.content.Intent Data){
final String TheName=Data.getData().getPath().substring(1) + Persistent.ProgExt;
final String SaveDir=android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "String_Node_Str" + Persistent.ProgramsDir;
Global.StartBGTask(new Global.Task(){
@Override public void BGRun(){
try {
new java.io.File(SaveDir).mkdirs();
Persistent.Save(Global.Buttons,Global.Calc,false,false,SaveDir + "String_Node_Str" + TheName);
}
 catch (RuntimeException Failed) {
SetStatus(-1,Failed);
}
}
@Override public void PostRun(){
if (TaskStatus == 0) {
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.program_saved),TheName),android.widget.Toast.LENGTH_SHORT).show();
}
 else {
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.program_save_error),TaskFailure.toString()),android.widget.Toast.LENGTH_LONG).show();
}
}
}
,getString(R.string.saving));
}
}
);
ActivityResultActions.put(ImportDataRequest,new RequestResponseAction(){
public void Run(int ResultCode,android.content.Intent Data){
final String FileName=Data.getData().getPath();
try {
Global.Calc.ClearImport();
Global.Import.ImportData(FileName);
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.import_started),FileName),android.widget.Toast.LENGTH_SHORT).show();
}
 catch (Persistent.DataFormatException Failed) {
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.file_load_error),Failed.toString()),android.widget.Toast.LENGTH_LONG).show();
}
}
}
);
ActivityResultActions.put(ExportDataRequest,new RequestResponseAction(){
public void Run(int ResultCode,android.content.Intent Data){
switch (ResultCode) {
case android.app.Activity.RESULT_OK:
Global.Export.Close();
try {
String FileName=Data.getData().getPath();
if (!ExportAppend) {
final String SaveDir=android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "String_Node_Str" + Persistent.DataDir;
new java.io.File(SaveDir).mkdirs();
FileName=SaveDir + FileName;
}
Global.Export.Open(FileName,ExportAppend,ExportNumbersOnly);
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.export_started),FileName),android.widget.Toast.LENGTH_SHORT).show();
}
 catch (RuntimeException Failed) {
android.widget.Toast.makeText(Main.this,String.format(Global.StdLocale,getString(R.string.export_error),Failed.toString()),android.widget.Toast.LENGTH_LONG).show();
}
break;
case SwitchAppend:
case SwitchSaveAs:
ExportAppend=ResultCode == SwitchAppend;
LaunchExportPicker();
break;
}
}
}
);
}