FindBugs appeased

This commit is contained in:
Iskra Delta 2016-10-13 10:57:15 +00:00 committed by AndyScherzinger
parent 10c1f0ff3b
commit 97da0cbc94
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
22 changed files with 91 additions and 73 deletions

View file

@ -47,6 +47,7 @@ dependencies {
compile 'com.jakewharton:disklrucache:2.0.2'
compile "com.android.support:appcompat-v7:${supportLibraryVersion}"
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.google.code.findbugs:annotations:2.0.1'
/// dependencies for local unit tests

View file

@ -37,6 +37,8 @@ import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.ui.activity.Preferences;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* Main Application of the project
@ -61,7 +63,7 @@ public class MainApp extends Application {
private static boolean mOnlyOnDevice = false;
@SuppressFBWarnings("ST")
public void onCreate(){
super.onCreate();
MainApp.mContext = getApplicationContext();

View file

@ -91,7 +91,7 @@ import com.owncloud.android.ui.dialog.SamlWebViewDialog;
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener;
import com.owncloud.android.utils.DisplayUtils;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.security.cert.X509Certificate;
import java.util.Map;
@ -1576,6 +1576,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
*
* TODO Decide how to name the OAuth accounts
*/
@SuppressFBWarnings("DMI")
private boolean createAccount(RemoteOperationResult authResult) {
/// create and save new ownCloud account
boolean isOAuth = AccountTypeUtils.

View file

@ -1111,7 +1111,7 @@ public class FileDataStorageManager {
* @return First {@OCShare} instance found in DB bound to the file in 'path'
*/
public OCShare getFirstShareByPathAndType(String path, ShareType type, String shareWith) {
Cursor c = null;
Cursor cursor = null;
if (shareWith == null) {
shareWith = "";
}
@ -1140,14 +1140,14 @@ public class FileDataStorageManager {
}
if (getContentResolver() != null) {
c = getContentResolver().query(
cursor = getContentResolver().query(
ProviderTableMeta.CONTENT_URI_SHARE,
null,
selection, selectionArgs,
null);
} else {
try {
c = getContentProviderClient().query(
cursor = getContentProviderClient().query(
ProviderTableMeta.CONTENT_URI_SHARE,
null,
selection, selectionArgs,
@ -1155,14 +1155,14 @@ public class FileDataStorageManager {
} catch (RemoteException e) {
Log_OC.e(TAG, "Could not get file details: " + e.getMessage());
c = null;
cursor = null;
}
}
OCShare share = null;
if (c.moveToFirst()) {
share = createShareInstance(c);
if (cursor != null && cursor.moveToFirst()) {
share = createShareInstance(cursor);
cursor.close();
}
c.close();
return share;
}
@ -1666,32 +1666,31 @@ public class FileDataStorageManager {
Integer.toString(ShareType.GROUP.getValue()),
Integer.toString(ShareType.FEDERATED.getValue())};
Cursor c = null;
Cursor cursor = null;
if (getContentResolver() != null) {
c = getContentResolver().query(
cursor = getContentResolver().query(
ProviderTableMeta.CONTENT_URI_SHARE,
null, where, whereArgs, null);
} else {
try {
c = getContentProviderClient().query(
cursor = getContentProviderClient().query(
ProviderTableMeta.CONTENT_URI_SHARE,
null, where, whereArgs, null);
} catch (RemoteException e) {
Log_OC.e(TAG, "Could not get list of shares with: " + e.getMessage());
c = null;
cursor = null;
}
}
ArrayList<OCShare> shares = new ArrayList<OCShare>();
OCShare share = null;
if (c.moveToFirst()) {
if (cursor != null && cursor.moveToFirst()) {
do {
share = createShareInstance(c);
share = createShareInstance(cursor);
shares.add(share);
// }
} while (c.moveToNext());
} while (cursor.moveToNext());
cursor.close();
}
c.close();
return shares;
}

View file

@ -549,22 +549,27 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
@Override
public boolean equals(Object o) {
if (o instanceof OCFile) {
OCFile that = (OCFile) o;
if (that != null) {
return this.mId == that.mId;
}
}
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
return false;
OCFile ocFile = (OCFile) o;
return mId == ocFile.mId && mParentId == ocFile.mParentId;
}
@Override
public int hashCode() {
int result = (int) (mId ^ (mId >>> 32));
result = 31 * result + (int) (mParentId ^ (mParentId >>> 32));
return result;
}
@Override
public String toString() {
String asString = "[id=%s, name=%s, mime=%s, downloaded=%s, local=%s, remote=%s, " +
"parentId=%s, favorite=%s etag=%s]";
asString = String.format(asString, Long.valueOf(mId), getFileName(), mMimeType, isDown(),
mLocalPath, mRemotePath, Long.valueOf(mParentId), Boolean.valueOf(mFavorite),
asString = String.format(asString, mId, getFileName(), mMimeType, isDown(),
mLocalPath, mRemotePath, mParentId, mFavorite,
mEtag);
return asString;
}

View file

@ -57,6 +57,8 @@ import java.io.File;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* Manager for concurrent access to thumbnails cache.
*/
@ -75,13 +77,13 @@ public class ThumbnailsCacheManager {
private static final int mCompressQuality = 70;
private static OwnCloudClient mClient = null;
public static Bitmap mDefaultImg =
public static final Bitmap mDefaultImg =
BitmapFactory.decodeResource(
MainApp.getAppContext().getResources(),
R.drawable.file_image
);
public static Bitmap mDefaultVideo =
public static final Bitmap mDefaultVideo =
BitmapFactory.decodeResource(
MainApp.getAppContext().getResources(),
R.drawable.file_movie
@ -180,6 +182,7 @@ public class ThumbnailsCacheManager {
mImageViewReference = new WeakReference<ImageView>(imageView);
}
@SuppressFBWarnings("Dm")
@Override
protected Bitmap doInBackground(Object... params) {
Bitmap thumbnail = null;
@ -403,6 +406,7 @@ public class ThumbnailsCacheManager {
mAccount = account;
}
@SuppressFBWarnings("Dm")
@Override
protected Bitmap doInBackground(String... params) {
Bitmap thumbnail = null;

View file

@ -265,14 +265,12 @@ public class MediaControlView extends FrameLayout /* implements OnLayoutChangeLi
@Override
public void handleMessage(Message msg) {
int pos;
switch (msg.what) {
case SHOW_PROGRESS:
pos = setProgress();
if (!mDragging) {
msg = obtainMessage(SHOW_PROGRESS);
sendMessageDelayed(msg, 1000 - (pos % 1000));
}
break;
if (msg.what == SHOW_PROGRESS) {
pos = setProgress();
if (!mDragging) {
msg = obtainMessage(SHOW_PROGRESS);
sendMessageDelayed(msg, 1000 - (pos % 1000));
}
}
}
};
@ -417,7 +415,6 @@ public class MediaControlView extends FrameLayout /* implements OnLayoutChangeLi
if (!playing) mPlayer.pause(); // necessary in some 2.3.x devices
setProgress();
break;
}
}

View file

@ -68,7 +68,7 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
/// Keys to add extras to the action
public static final String EXTRA_FILE = MY_PACKAGE + ".extra.FILE";
public static final String EXTRA_ACCOUNT = MY_PACKAGE + ".extra.ACCOUNT";
public static String EXTRA_START_POSITION = MY_PACKAGE + ".extra.START_POSITION";
public static final String EXTRA_START_POSITION = MY_PACKAGE + ".extra.START_POSITION";
public static final String EXTRA_PLAY_ON_LOAD = MY_PACKAGE + ".extra.PLAY_ON_LOAD";

View file

@ -141,7 +141,6 @@ public class OAuth2GetAccessToken extends RemoteOperation {
int i = 0;
String key = "";
String value = "";
StringBuilder sb = new StringBuilder();
while (pairs.length > i) {
int j = 0;
String[] part = pairs[i].split("=");
@ -149,13 +148,10 @@ public class OAuth2GetAccessToken extends RemoteOperation {
String p = part[j];
if (j == 0) {
key = p;
sb.append(key + " = ");
} else if (j == 1) {
value = p;
mOAuth2ParsedAuthorizationResponse.put(key, value);
sb.append(value + "\n");
}
Log_OC.v(TAG, "[" + i + "," + j + "] = " + p);
j++;
}

View file

@ -41,8 +41,10 @@ import com.owncloud.android.utils.FileStorageUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.ArrayList;
@ -191,7 +193,7 @@ public class LogHistoryActivity extends ToolbarActivity {
}
protected void onPostExecute(String result) {
if (textViewReference != null && result != null) {
if (result != null) {
final TextView logTV = textViewReference.get();
if (logTV != null) {
mLogText = result;
@ -219,8 +221,9 @@ public class LogHistoryActivity extends ToolbarActivity {
File file = new File(mLogPath,logFileName[i]);
if (file.exists()) {
// Check if FileReader is ready
if (new FileReader(file).ready()) {
br = new BufferedReader(new FileReader(file));
final InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file), "UTF8");
if (inputStreamReader.ready()) {
br = new BufferedReader(inputStreamReader);
while ((line = br.readLine()) != null) {
// Append the log info
text.append(line);
@ -231,7 +234,7 @@ public class LogHistoryActivity extends ToolbarActivity {
}
}
catch (IOException e) {
Log_OC.d(TAG, e.getMessage().toString());
Log_OC.d(TAG, e.getMessage());
} finally {
if (br != null) {

View file

@ -75,8 +75,6 @@ public class ManageAccountsActivity extends FileActivity
private final Handler mHandler = new Handler();
private String mAccountName;
private AccountListAdapter mAccountListAdapter;
protected FileUploader.FileUploaderBinder mUploaderBinder = null;
protected FileDownloader.FileDownloaderBinder mDownloaderBinder = null;
private ServiceConnection mDownloadServiceConnection, mUploadServiceConnection = null;
Set<String> mOriginalAccounts;
String mOriginalCurrentAccount;
@ -329,12 +327,6 @@ public class ManageAccountsActivity extends FileActivity
public Handler getHandler() { return mHandler; }
// Methods for ComponentsGetter
@Override
public FileDownloader.FileDownloaderBinder getFileDownloaderBinder() {
return mDownloaderBinder;
}
@Override
public FileUploader.FileUploaderBinder getFileUploaderBinder() {
return mUploaderBinder;

View file

@ -361,7 +361,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
PrintWriter out;
try {
File f = File.createTempFile("nextcloud", TEXT_FILE_SUFFIX);
out = new PrintWriter(f);
out = new PrintWriter(f, "UTF8");
out.println(getIntent().getStringExtra(Intent.EXTRA_TEXT));
out.close();

View file

@ -58,6 +58,8 @@ import java.util.Comparator;
import java.util.Observable;
import java.util.Observer;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* This Adapter populates a ListView with following types of uploads: pending,
* active, completed. Filtering possible.
@ -116,10 +118,12 @@ public class ExpandableUploadListAdapter extends BaseExpandableListAdapter imple
}
}
@SuppressFBWarnings("Bx")
private int compareUploadId(OCUpload upload1, OCUpload upload2) {
return Long.valueOf(upload1.getUploadId()).compareTo(upload2.getUploadId());
}
@SuppressFBWarnings("Bx")
private int compareUpdateTime(OCUpload upload1, OCUpload upload2) {
return Long.valueOf(upload2.getUploadEndTimestamp()).compareTo(upload1.getUploadEndTimestamp());
}

View file

@ -394,19 +394,16 @@ public class FileListListAdapter extends BaseAdapter implements FilterableListAd
if (mJustFolders) {
mFiles = getFolders(mFiles);
}
if (!mShowHiddenFiles) {
mFiles = filterHiddenFiles(mFiles);
}
mFiles = FileStorageUtils.sortOcFolder(mFiles);
mFilesAll.addAll(mFiles);
} else {
mFiles = null;
mFilesAll.clear();
}
mFiles = FileStorageUtils.sortOcFolder(mFiles);
mFilesAll.clear();
mFilesAll.addAll(mFiles);
notifyDataSetChanged();
}

View file

@ -51,8 +51,11 @@ import com.owncloud.android.ui.activity.ShareActivity;
import com.owncloud.android.ui.dialog.ShareLinkToDialog;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
@ -83,10 +86,10 @@ public class FileOperationsHelper {
private String getUrlFromFile(String storagePath, Pattern pattern) {
String url = null;
FileReader fr = null;
InputStreamReader fr = null;
BufferedReader br = null;
try {
fr = new FileReader(storagePath);
fr = new InputStreamReader(new FileInputStream(storagePath), "UTF8");
br = new BufferedReader(fr);
String line;

View file

@ -27,7 +27,7 @@ import android.os.Handler;
import android.os.HandlerThread;
import android.os.Process;
import android.support.v4.app.NotificationCompat;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import com.owncloud.android.R;
public class NotificationUtils {
@ -52,7 +52,7 @@ public class NotificationUtils {
setColor(context.getResources().getColor(R.color.primary));
}
@SuppressFBWarnings("DMI")
public static void cancelWithDelay(
final NotificationManager notificationManager,
final int notificationId,

View file

@ -59,6 +59,8 @@ import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.fragment.FileFragment;
import com.owncloud.android.utils.MimeTypeUtil;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* Holds a swiping galley where image files contained in an ownCloud directory are shown
@ -348,10 +350,11 @@ public class PreviewImageActivity extends FileActivity implements
private void backToDisplayActivity() {
finish();
}
@SuppressFBWarnings("DLS")
@Override
public void showDetails(OCFile file) {
Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
final Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
showDetailsIntent.setAction(FileDisplayActivity.ACTION_DETAILS);
showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, file);
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT,
@ -359,7 +362,6 @@ public class PreviewImageActivity extends FileActivity implements
startActivity(showDetailsIntent);
int pos = mPreviewImagePagerAdapter.getFilePosition(file);
file = mPreviewImagePagerAdapter.getFileAt(pos);
}
private void requestForDownload(OCFile file) {

View file

@ -52,6 +52,7 @@ import com.owncloud.android.utils.MimeTypeUtil;
import java.lang.ref.WeakReference;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import third_parties.michaelOrtiz.TouchImageViewCustom;
@ -340,6 +341,7 @@ public class PreviewImageFragment extends FileFragment {
super.onPause();
}
@SuppressFBWarnings("Dm")
@Override
public void onDestroy() {
if (mBitmap != null) {

View file

@ -47,6 +47,7 @@ import com.owncloud.android.utils.MimeTypeUtil;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.lang.ref.WeakReference;
import java.util.LinkedList;
@ -175,12 +176,12 @@ public class PreviewTextFragment extends FileFragment {
}
final String location = (String) params[0];
FileInputStream inputStream = null;
InputStreamReader inputStream = null;
Scanner sc = null;
StringWriter source = new StringWriter();
BufferedWriter bufferedWriter = new BufferedWriter(source);
try {
inputStream = new FileInputStream(location);
inputStream = new InputStreamReader(new FileInputStream(location), "UTF8");
sc = new Scanner(inputStream);
while (sc.hasNextLine()) {
bufferedWriter.append(sc.nextLine());

View file

@ -50,6 +50,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Vector;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import third_parties.daveKoeller.AlphanumComparator;
@ -271,6 +272,7 @@ public class FileStorageUtils {
final int multiplier = mSortAscending ? 1 : -1;
Collections.sort(files, new Comparator<OCFile>() {
@SuppressFBWarnings(value = "Bx", justification = "Would require stepping up API level")
public int compare(OCFile o1, OCFile o2) {
Long obj1 = o1.getModificationTimestamp();
return multiplier * obj1.compareTo(o2.getModificationTimestamp());
@ -290,6 +292,7 @@ public class FileStorageUtils {
List<File> files = new ArrayList<File>(Arrays.asList(filesArray));
Collections.sort(files, new Comparator<File>() {
@SuppressFBWarnings(value = "Bx", justification = "Would require stepping up API level")
public int compare(File o1, File o2) {
Long obj1 = o1.lastModified();
return multiplier * obj1.compareTo(o2.lastModified());
@ -307,12 +310,14 @@ public class FileStorageUtils {
final int multiplier = mSortAscending ? 1 : -1;
Collections.sort(files, new Comparator<OCFile>() {
@SuppressFBWarnings(value = "Bx", justification = "Would require stepping up API level")
public int compare(OCFile o1, OCFile o2) {
if (o1.isFolder() && o2.isFolder()) {
Long obj1 = o1.getFileLength();
return multiplier * obj1.compareTo(o2.getFileLength());
} else if (o1.isFolder()) {
return -1;
} else if (o2.isFolder()) {
return 1;
} else {
@ -334,6 +339,7 @@ public class FileStorageUtils {
List<File> files = new ArrayList<File>(Arrays.asList(filesArray));
Collections.sort(files, new Comparator<File>() {
@SuppressFBWarnings(value = "Bx", justification = "Would require stepping up API level")
public int compare(File o1, File o2) {
if (o1.isDirectory() && o2.isDirectory()) {
Long obj1 = getFolderSize(o1);
@ -357,6 +363,7 @@ public class FileStorageUtils {
* Sorts list by Name
* @param files files to sort
*/
@SuppressFBWarnings(value = "Bx", justification = "Would require stepping up API level")
public static Vector<OCFile> sortOCFilesByName(Vector<OCFile> files){
final int multiplier = mSortAscending ? 1 : -1;

View file

@ -33,6 +33,8 @@ import android.webkit.MimeTypeMap;
import com.owncloud.android.lib.common.utils.Log_OC;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* A helper class for some Uri operations.
@ -123,6 +125,7 @@ public class UriUtils {
* @return The path in the file system to the content or null if it could not be found (not a file)
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
@SuppressFBWarnings("Bx")
public static String getLocalPath(Uri uri, Context context) {
final boolean isKitKatOrLater = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
@ -246,7 +249,6 @@ public class UriUtils {
} else if (MimeTypeUtil.isAudio(mimeType)) {
displayNameColumn = MediaStore.Audio.AudioColumns.DISPLAY_NAME;
} else {
displayNameColumn = MediaStore.Files.FileColumns.DISPLAY_NAME;
}

View file

@ -45,7 +45,7 @@ import java.util.ArrayList;
*/
public class GridViewWithHeaderAndFooter extends GridView {
public static boolean DEBUG = false;
public static final boolean DEBUG = false;
/**
* A class that represents a fixed view in a list, for example a header at the top