LocalRepoManager: fix null check when copying APKs

findbugs found this problem and reported it like this:

Nullcheck of org.fdroid.fdroid.data.App.installedApk at line 191 of value
previously dereferenced in org.fdroid.fdroid.localrepo.LocalRepoManager.copyApksToRepo(List)

A value is checked here to see whether it is null, but this value can't be
null because it was previously dereferenced and if it were null a null
pointer exception would have occurred at the earlier dereference.
Essentially, this code and the previous dereference disagree as to whether
this value is allowed to be null. Either the check is redundant or the
previous dereference is erroneous.
This commit is contained in:
Hans-Christoph Steiner 2014-07-29 23:19:54 -04:00
parent bc5cf590c7
commit af3a6369cc

View File

@ -4,12 +4,15 @@ package org.fdroid.fdroid.localrepo;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.*;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetManager;
import android.graphics.*;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.preference.PreferenceManager;
@ -17,15 +20,32 @@ import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import org.fdroid.fdroid.*;
import org.fdroid.fdroid.Hasher;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.App;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import java.io.*;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.security.cert.CertificateEncodingException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
@ -187,11 +207,13 @@ public class LocalRepoManager {
for (String packageName : appsToCopy) {
App app = apps.get(packageName);
File outFile = new File(repoDir, app.installedApk.apkName);
if (app.installedApk == null
|| !Utils.symlinkOrCopyFile(app.installedApk.installedFile, outFile)) {
throw new IllegalStateException("Unable to copy APK");
if (app.installedApk != null) {
File outFile = new File(repoDir, app.installedApk.apkName);
if (Utils.symlinkOrCopyFile(app.installedApk.installedFile, outFile))
continue;
}
// if we got here, something went wrong
throw new IllegalStateException("Unable to copy APK");
}
}
@ -246,7 +268,7 @@ public class LocalRepoManager {
/**
* Extracts the icon from an APK and writes it to the repo as a PNG
*
*
* @return path to the PNG file
*/
public void copyIconToRepo(Drawable drawable, String packageName, int versionCode) {