Program: 23642
Project: 23642
Buggy source:
/** 
 * Generate and return the   {@link PackageInfo} for a parsed package.
 * @param p the parsed package.
 * @param flags indicating which optional information is included.
 */
public static PackageInfo generatePackageInfo(PackageParser.Package p,int gids[],int flags){
  PackageInfo pi=new PackageInfo();
  pi.packageName=p.packageName;
  pi.versionCode=p.mVersionCode;
  pi.versionName=p.mVersionName;
  pi.sharedUserId=p.mSharedUserId;
  pi.sharedUserLabel=p.mSharedUserLabel;
  pi.applicationInfo=p.applicationInfo;
  if ((flags & PackageManager.GET_GIDS) != 0) {
    pi.gids=gids;
  }
  if ((flags & PackageManager.GET_CONFIGURATIONS) != 0) {
    int N=p.configPreferences.size();
    if (N > 0) {
      pi.configPreferences=new ConfigurationInfo[N];
      p.configPreferences.toArray(pi.configPreferences);
    }
    N=p.reqFeatures != null ? p.reqFeatures.size() : 0;
    if (N > 0) {
      pi.reqFeatures=new FeatureInfo[N];
      p.reqFeatures.toArray(pi.reqFeatures);
    }
  }
  if ((flags & PackageManager.GET_ACTIVITIES) != 0) {
    int N=p.activities.size();
    if (N > 0) {
      pi.activities=new ActivityInfo[N];
      for (int i=0; i < N; i++) {
        final Activity activity=p.activities.get(i);
        if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
          pi.activities[i]=generateActivityInfo(p.activities.get(i),flags);
        }
      }
    }
  }
  if ((flags & PackageManager.GET_RECEIVERS) != 0) {
    int N=p.receivers.size();
    if (N > 0) {
      pi.receivers=new ActivityInfo[N];
      for (int i=0; i < N; i++) {
        final Activity activity=p.receivers.get(i);
        if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
          pi.receivers[i]=generateActivityInfo(p.receivers.get(i),flags);
        }
      }
    }
  }
  if ((flags & PackageManager.GET_SERVICES) != 0) {
    int N=p.services.size();
    if (N > 0) {
      pi.services=new ServiceInfo[N];
      for (int i=0; i < N; i++) {
        final Service service=p.services.get(i);
        if (service.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
          pi.services[i]=generateServiceInfo(p.services.get(i),flags);
        }
      }
    }
  }
  if ((flags & PackageManager.GET_PROVIDERS) != 0) {
    int N=p.providers.size();
    if (N > 0) {
      pi.providers=new ProviderInfo[N];
      for (int i=0; i < N; i++) {
        final Provider provider=p.providers.get(i);
        if (provider.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
          pi.providers[i]=generateProviderInfo(p.providers.get(i),flags);
        }
      }
    }
  }
  if ((flags & PackageManager.GET_INSTRUMENTATION) != 0) {
    int N=p.instrumentation.size();
    if (N > 0) {
      pi.instrumentation=new InstrumentationInfo[N];
      for (int i=0; i < N; i++) {
        pi.instrumentation[i]=generateInstrumentationInfo(p.instrumentation.get(i),flags);
      }
    }
  }
  if ((flags & PackageManager.GET_PERMISSIONS) != 0) {
    int N=p.permissions.size();
    if (N > 0) {
      pi.permissions=new PermissionInfo[N];
      for (int i=0; i < N; i++) {
        pi.permissions[i]=generatePermissionInfo(p.permissions.get(i),flags);
      }
    }
    N=p.requestedPermissions.size();
    if (N > 0) {
      pi.requestedPermissions=new String[N];
      for (int i=0; i < N; i++) {
        pi.requestedPermissions[i]=p.requestedPermissions.get(i);
      }
    }
  }
  if ((flags & PackageManager.GET_SIGNATURES) != 0) {
    if (p.mSignatures != null) {
      int N=p.mSignatures.length;
      if (N > 0) {
        pi.signatures=new Signature[N];
        System.arraycopy(p.mSignatures,0,pi.signatures,0,N);
      }
    }
  }
  return pi;
}

Fixed version (ground truth):
/** 
 * Generate and return the   {@link PackageInfo} for a parsed package.
 * @param p the parsed package.
 * @param flags indicating which optional information is included.
 */
public static PackageInfo generatePackageInfo(PackageParser.Package p,int gids[],int flags){
  PackageInfo pi=new PackageInfo();
  pi.packageName=p.packageName;
  pi.versionCode=p.mVersionCode;
  pi.versionName=p.mVersionName;
  pi.sharedUserId=p.mSharedUserId;
  pi.sharedUserLabel=p.mSharedUserLabel;
  pi.applicationInfo=p.applicationInfo;
  if ((flags & PackageManager.GET_GIDS) != 0) {
    pi.gids=gids;
  }
  if ((flags & PackageManager.GET_CONFIGURATIONS) != 0) {
    int N=p.configPreferences.size();
    if (N > 0) {
      pi.configPreferences=new ConfigurationInfo[N];
      p.configPreferences.toArray(pi.configPreferences);
    }
    N=p.reqFeatures != null ? p.reqFeatures.size() : 0;
    if (N > 0) {
      pi.reqFeatures=new FeatureInfo[N];
      p.reqFeatures.toArray(pi.reqFeatures);
    }
  }
  if ((flags & PackageManager.GET_ACTIVITIES) != 0) {
    int N=p.activities.size();
    if (N > 0) {
      if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
        pi.activities=new ActivityInfo[N];
      }
 else {
        int num=0;
        for (int i=0; i < N; i++) {
          if (p.activities.get(i).info.enabled)           num++;
        }
        pi.activities=new ActivityInfo[num];
      }
      for (int i=0; i < N; i++) {
        final Activity activity=p.activities.get(i);
        if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
          pi.activities[i]=generateActivityInfo(p.activities.get(i),flags);
        }
      }
    }
  }
  if ((flags & PackageManager.GET_RECEIVERS) != 0) {
    int N=p.receivers.size();
    if (N > 0) {
      if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
        pi.receivers=new ActivityInfo[N];
      }
 else {
        int num=0;
        for (int i=0; i < N; i++) {
          if (p.receivers.get(i).info.enabled)           num++;
        }
        pi.receivers=new ActivityInfo[num];
      }
      for (int i=0; i < N; i++) {
        final Activity activity=p.receivers.get(i);
        if (activity.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
          pi.receivers[i]=generateActivityInfo(p.receivers.get(i),flags);
        }
      }
    }
  }
  if ((flags & PackageManager.GET_SERVICES) != 0) {
    int N=p.services.size();
    if (N > 0) {
      if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
        pi.services=new ServiceInfo[N];
      }
 else {
        int num=0;
        for (int i=0; i < N; i++) {
          if (p.services.get(i).info.enabled)           num++;
        }
        pi.services=new ServiceInfo[num];
      }
      for (int i=0; i < N; i++) {
        final Service service=p.services.get(i);
        if (service.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
          pi.services[i]=generateServiceInfo(p.services.get(i),flags);
        }
      }
    }
  }
  if ((flags & PackageManager.GET_PROVIDERS) != 0) {
    int N=p.providers.size();
    if (N > 0) {
      if ((flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
        pi.providers=new ProviderInfo[N];
      }
 else {
        int num=0;
        for (int i=0; i < N; i++) {
          if (p.providers.get(i).info.enabled)           num++;
        }
        pi.providers=new ProviderInfo[num];
      }
      for (int i=0; i < N; i++) {
        final Provider provider=p.providers.get(i);
        if (provider.info.enabled || (flags & PackageManager.GET_DISABLED_COMPONENTS) != 0) {
          pi.providers[i]=generateProviderInfo(p.providers.get(i),flags);
        }
      }
    }
  }
  if ((flags & PackageManager.GET_INSTRUMENTATION) != 0) {
    int N=p.instrumentation.size();
    if (N > 0) {
      pi.instrumentation=new InstrumentationInfo[N];
      for (int i=0; i < N; i++) {
        pi.instrumentation[i]=generateInstrumentationInfo(p.instrumentation.get(i),flags);
      }
    }
  }
  if ((flags & PackageManager.GET_PERMISSIONS) != 0) {
    int N=p.permissions.size();
    if (N > 0) {
      pi.permissions=new PermissionInfo[N];
      for (int i=0; i < N; i++) {
        pi.permissions[i]=generatePermissionInfo(p.permissions.get(i),flags);
      }
    }
    N=p.requestedPermissions.size();
    if (N > 0) {
      pi.requestedPermissions=new String[N];
      for (int i=0; i < N; i++) {
        pi.requestedPermissions[i]=p.requestedPermissions.get(i);
      }
    }
  }
  if ((flags & PackageManager.GET_SIGNATURES) != 0) {
    if (p.mSignatures != null) {
      int N=p.mSignatures.length;
      if (N > 0) {
        pi.signatures=new Signature[N];
        System.arraycopy(p.mSignatures,0,pi.signatures,0,N);
      }
    }
  }
  return pi;
}