Program: 86327
Project: 86327
Buggy source:
public void add(){
  AlertDialog.Builder builder=new AlertDialog.Builder(this);
  LayoutInflater inflater=getLayoutInflater();
  View view=inflater.inflate(R.layout.library_select_dialog,null);
  final ExpandableListView lv=(ExpandableListView)view.findViewById(R.id.lvBibs);
  try {
    libraries=((OpacClient)getApplication()).getLibraries();
  }
 catch (  IOException e) {
    ACRA.getErrorReporter().handleException(e);
  }
catch (  JSONException e) {
    ACRA.getErrorReporter().handleException(e);
  }
  final LibraryListAdapter la=new LibraryListAdapter(this);
  Collections.sort(libraries);
  for (  Library lib : libraries) {
    la.addItem(lib);
  }
  lv.setAdapter(la);
  lv.setOnChildClickListener(new OnChildClickListener(){
    @Override public boolean onChildClick(    ExpandableListView arg0,    View arg1,    int groupPosition,    int childPosition,    long arg4){
      AccountDataSource data=new AccountDataSource(WelcomeActivity.this);
      data.open();
      Account acc=new Account();
      acc.setLibrary(la.getChild(groupPosition,childPosition).getIdent());
      acc.setLabel(getString(R.string.default_account_name));
      long insertedid=data.addAccount(acc);
      data.close();
      dialog.dismiss();
      ((OpacClient)getApplication()).setAccount(insertedid);
      Intent i=new Intent(WelcomeActivity.this,AccountEditActivity.class);
      i.putExtra("String_Node_Str",insertedid);
      i.putExtra("String_Node_Str",true);
      i.putExtra("String_Node_Str",true);
      startActivity(i);
      return false;
    }
  }
);
  final TextView tvLocateString=(TextView)view.findViewById(R.id.tvLocateString);
  final ImageView ivLocationIcon=(ImageView)view.findViewById(R.id.ivLocationIcon);
  final LinearLayout llLocate=(LinearLayout)view.findViewById(R.id.llLocate);
  final LocationManager locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
  Criteria criteria=new Criteria();
  criteria.setAccuracy(Criteria.ACCURACY_COARSE);
  final String provider=locationManager.getBestProvider(criteria,true);
  if (provider == null)   llLocate.setVisibility(View.GONE);
  llLocate.setOnClickListener(new OnClickListener(){
    @Override public void onClick(    View v){
      tvLocateString.setText(R.string.geolocate_progress);
      ivLocationIcon.setImageResource(R.drawable.ic_locate);
      if (provider == null)       return;
      locationManager.requestLocationUpdates(provider,0,0,new LocationListener(){
        @Override public void onStatusChanged(        String provider,        int status,        Bundle extras){
        }
        @Override public void onProviderEnabled(        String provider){
        }
        @Override public void onProviderDisabled(        String provider){
        }
        @Override public void onLocationChanged(        Location location){
          if (location != null) {
            double lat=location.getLatitude();
            double lon=location.getLongitude();
            float shortest=-1;
            Library closest=null;
            for (            Library lib : libraries) {
              float[] result=new float[1];
              double[] geo=lib.getGeo();
              if (geo == null)               continue;
              Location.distanceBetween(lat,lon,geo[0],geo[1],result);
              if (shortest == -1 || result[0] < shortest) {
                shortest=result[0];
                closest=lib;
              }
            }
            if (closest != null) {
              tvLocateString.setText(getString(R.string.geolocate_found,closest.getCity()));
              ivLocationIcon.setImageResource(R.drawable.ic_located);
              int[] position=la.findPosition(closest);
              if (position != null) {
                lv.expandGroup(position[0],false);
                lv.setSelectedChild(position[0],position[1],true);
              }
            }
          }
        }
      }
);
    }
  }
);
  builder.setView(view).setNegativeButton(R.string.cancel,new DialogInterface.OnClickListener(){
    @Override public void onClick(    DialogInterface dialog,    int id){
      dialog.cancel();
    }
  }
);
  dialog=builder.create();
  dialog.show();
}

Fixed version (ground truth):
public void add(){
  AlertDialog.Builder builder=new AlertDialog.Builder(this);
  LayoutInflater inflater=getLayoutInflater();
  View view=inflater.inflate(R.layout.library_select_dialog,null);
  final ExpandableListView lv=(ExpandableListView)view.findViewById(R.id.lvBibs);
  try {
    libraries=((OpacClient)getApplication()).getLibraries();
  }
 catch (  IOException e) {
    ACRA.getErrorReporter().handleException(e);
  }
  final LibraryListAdapter la=new LibraryListAdapter(this);
  Collections.sort(libraries);
  for (  Library lib : libraries) {
    la.addItem(lib);
  }
  lv.setAdapter(la);
  lv.setOnChildClickListener(new OnChildClickListener(){
    @Override public boolean onChildClick(    ExpandableListView arg0,    View arg1,    int groupPosition,    int childPosition,    long arg4){
      AccountDataSource data=new AccountDataSource(WelcomeActivity.this);
      data.open();
      Account acc=new Account();
      acc.setLibrary(la.getChild(groupPosition,childPosition).getIdent());
      acc.setLabel(getString(R.string.default_account_name));
      long insertedid=data.addAccount(acc);
      data.close();
      dialog.dismiss();
      ((OpacClient)getApplication()).setAccount(insertedid);
      Intent i=new Intent(WelcomeActivity.this,AccountEditActivity.class);
      i.putExtra("String_Node_Str",insertedid);
      i.putExtra("String_Node_Str",true);
      i.putExtra("String_Node_Str",true);
      startActivity(i);
      return false;
    }
  }
);
  final TextView tvLocateString=(TextView)view.findViewById(R.id.tvLocateString);
  final ImageView ivLocationIcon=(ImageView)view.findViewById(R.id.ivLocationIcon);
  final LinearLayout llLocate=(LinearLayout)view.findViewById(R.id.llLocate);
  final LocationManager locationManager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
  Criteria criteria=new Criteria();
  criteria.setAccuracy(Criteria.ACCURACY_COARSE);
  final String provider=locationManager.getBestProvider(criteria,true);
  if (provider == null)   llLocate.setVisibility(View.GONE);
  llLocate.setOnClickListener(new OnClickListener(){
    @Override public void onClick(    View v){
      tvLocateString.setText(R.string.geolocate_progress);
      ivLocationIcon.setImageResource(R.drawable.ic_locate);
      if (provider == null)       return;
      locationManager.requestLocationUpdates(provider,0,0,new LocationListener(){
        @Override public void onStatusChanged(        String provider,        int status,        Bundle extras){
        }
        @Override public void onProviderEnabled(        String provider){
        }
        @Override public void onProviderDisabled(        String provider){
        }
        @Override public void onLocationChanged(        Location location){
          if (location != null) {
            double lat=location.getLatitude();
            double lon=location.getLongitude();
            float shortest=-1;
            Library closest=null;
            for (            Library lib : libraries) {
              float[] result=new float[1];
              double[] geo=lib.getGeo();
              if (geo == null)               continue;
              Location.distanceBetween(lat,lon,geo[0],geo[1],result);
              if (shortest == -1 || result[0] < shortest) {
                shortest=result[0];
                closest=lib;
              }
            }
            if (closest != null) {
              tvLocateString.setText(getString(R.string.geolocate_found,closest.getCity()));
              ivLocationIcon.setImageResource(R.drawable.ic_located);
              int[] position=la.findPosition(closest);
              if (position != null) {
                lv.expandGroup(position[0],false);
                lv.setSelectedChild(position[0],position[1],true);
              }
            }
          }
        }
      }
);
    }
  }
);
  builder.setView(view).setNegativeButton(R.string.cancel,new DialogInterface.OnClickListener(){
    @Override public void onClick(    DialogInterface dialog,    int id){
      dialog.cancel();
    }
  }
);
  dialog=builder.create();
  dialog.show();
}