Skip to content

Commit

Permalink
[Android] Roll to findbugs 3.0.1.
Browse files Browse the repository at this point in the history
Includes new warnings + support for Java8.

BUG=509751

Review URL: https://codereview.chromium.org/1230763010

Cr-Commit-Position: refs/heads/master@{#339296}
  • Loading branch information
jbudorick authored and Commit bot committed Jul 17, 2015
1 parent 332a71c commit 0d6c2e5
Show file tree
Hide file tree
Showing 27 changed files with 183 additions and 119 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ deps_os = {
Var('chromium_git') + '/chromium/third_party/errorprone.git' + '@' + '72560c97fb38e3eb93db2e85c29db7b72420fad8',

'src/third_party/findbugs':
Var('chromium_git') + '/chromium/deps/findbugs.git' + '@' + '7f69fa78a6db6dc31866d09572a0e356e921bf12',
Var('chromium_git') + '/chromium/deps/findbugs.git' + '@' + '10904cdd4aae90b3d02727527570bfc3df4efea4',

'src/third_party/freetype-android/src':
Var('chromium_git') + '/chromium/src/third_party/freetype2.git' + '@' + 'e186230678ee8e4ea4ac4797ece8125761e3225a',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.chromium.base.PathUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.TraceEvent;
import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.library_loader.LibraryProcessType;
import org.chromium.base.library_loader.ProcessInitException;
Expand Down Expand Up @@ -106,6 +107,7 @@ public WebViewChromiumFactoryProvider(android.webkit.WebViewDelegate delegate) {
initialize(WebViewDelegateFactory.createProxyDelegate(delegate));
}

@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
private void initialize(WebViewDelegate webViewDelegate) {
mWebViewDelegate = webViewDelegate;
if (isBuildDebuggable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.chromium.base.BaseSwitches;
import org.chromium.base.CommandLine;
import org.chromium.base.TraceEvent;
import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.content.app.ContentApplication;
import org.chromium.ui.base.ResourceBundle;

Expand All @@ -22,6 +23,7 @@ public class AwShellApplication extends ContentApplication {

private static final String TAG = "AwShellApplication";

@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
@Override
public void onCreate() {
super.onCreate();
Expand Down
30 changes: 15 additions & 15 deletions base/android/java/src/org/chromium/base/ResourceExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.os.Handler;
import android.os.Looper;
import android.os.Trace;
import android.util.Log;

import org.chromium.base.annotations.SuppressFBWarnings;

Expand All @@ -34,7 +33,7 @@
*/
public class ResourceExtractor {

private static final String LOGTAG = "ResourceExtractor";
private static final String TAG = "cr.base";
private static final String ICU_DATA_FILENAME = "icudtl.dat";
private static final String V8_NATIVES_DATA_FILENAME = "natives_blob.bin";
private static final String V8_SNAPSHOT_DATA_FILENAME = "snapshot_blob.bin";
Expand Down Expand Up @@ -66,7 +65,7 @@ private void extractResourceHelper(InputStream is, File outFile, byte[] buffer)
OutputStream os = null;
try {
os = new FileOutputStream(outFile);
Log.i(LOGTAG, "Extracting resource " + outFile);
Log.i(TAG, "Extracting resource %s", outFile);

int count = 0;
while ((count = is.read(buffer, 0, BUFFER_SIZE)) != -1) {
Expand Down Expand Up @@ -94,7 +93,7 @@ private void extractResourceHelper(InputStream is, File outFile, byte[] buffer)
private void doInBackgroundImpl() {
final File outputDir = getOutputDir();
if (!outputDir.exists() && !outputDir.mkdirs()) {
Log.e(LOGTAG, "Unable to create pak resources directory!");
Log.e(TAG, "Unable to create pak resources directory!");
return;
}

Expand Down Expand Up @@ -132,7 +131,7 @@ private void doInBackgroundImpl() {
// Try to recover here, can we try again after deleting files instead of
// returning null? It might be useful to gather UMA here too to track if
// this happens with regularity.
Log.w(LOGTAG, "Exception unpacking required pak resources: " + e.getMessage());
Log.w(TAG, "Exception unpacking required pak resources: %s", e.getMessage());
deleteFiles();
return;
} finally {
Expand All @@ -146,7 +145,7 @@ private void doInBackgroundImpl() {
} catch (IOException e) {
// Worst case we don't write a timestamp, so we'll re-extract the resource
// paks next start up.
Log.w(LOGTAG, "Failed to write resource pak timestamp!");
Log.w(TAG, "Failed to write resource pak timestamp!");
}
}
}
Expand Down Expand Up @@ -214,7 +213,7 @@ public boolean accept(File dir, String name) {
}
});

if (timestamps.length != 1) {
if (timestamps == null || timestamps.length != 1) {
// If there's no timestamp, nuke to be safe as we can't tell the age of the files.
// If there's multiple timestamps, something's gone wrong so nuke.
return expectedTimestamp;
Expand Down Expand Up @@ -370,24 +369,25 @@ private File getOutputDir() {
private void deleteFiles() {
File icudata = new File(getAppDataDir(), ICU_DATA_FILENAME);
if (icudata.exists() && !icudata.delete()) {
Log.e(LOGTAG, "Unable to remove the icudata " + icudata.getName());
Log.e(TAG, "Unable to remove the icudata %s", icudata.getName());
}
File v8_natives = new File(getAppDataDir(), V8_NATIVES_DATA_FILENAME);
if (v8_natives.exists() && !v8_natives.delete()) {
Log.e(LOGTAG,
"Unable to remove the v8 data " + v8_natives.getName());
Log.e(TAG, "Unable to remove the v8 data %s", v8_natives.getName());
}
File v8_snapshot = new File(getAppDataDir(), V8_SNAPSHOT_DATA_FILENAME);
if (v8_snapshot.exists() && !v8_snapshot.delete()) {
Log.e(LOGTAG,
"Unable to remove the v8 data " + v8_snapshot.getName());
Log.e(TAG, "Unable to remove the v8 data %s", v8_snapshot.getName());
}
File dir = getOutputDir();
if (dir.exists()) {
File[] files = dir.listFiles();
for (File file : files) {
if (!file.delete()) {
Log.e(LOGTAG, "Unable to remove existing resource " + file.getName());

if (files != null) {
for (File file : files) {
if (!file.delete()) {
Log.e(TAG, "Unable to remove existing resource %s", file.getName());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package org.chromium.base.test.util;

import org.chromium.base.annotations.SuppressFBWarnings;

/**
* Utility class for scaling various timeouts by a common factor.
* For example, to run tests under Valgrind, you might want the following:
Expand All @@ -13,6 +15,7 @@ public class ScalableTimeout {
private static Double sTimeoutScale = null;
private static final String PROPERTY_FILE = "/data/local/tmp/chrome_timeout_scale";

@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
public static long scaleTimeout(long timeout) {
if (sTimeoutScale == null) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
public class TestFileUtil {
public static void createNewHtmlFile(String name, String title, String body)
throws IOException {
File file = new File(name);
createNewHtmlFile(new File(name), title, body);
}

public static void createNewHtmlFile(File file, String title, String body)
throws IOException {
if (!file.createNewFile()) {
throw new IOException("File \"" + name + "\" already exists");
throw new IOException("File \"" + file.getAbsolutePath() + "\" already exists");
}

Writer writer = null;
Expand All @@ -43,7 +47,10 @@ public static void createNewHtmlFile(String name, String title, String body)
}

public static void deleteFile(String name) {
File file = new File(name);
deleteFile(new File(name));
}

public static void deleteFile(File file) {
boolean deleted = file.delete();
assert (deleted || !file.exists());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.util.Log;

import org.chromium.base.CommandLine;
import org.chromium.base.annotations.SuppressFBWarnings;

import java.io.File;

Expand Down Expand Up @@ -42,6 +43,7 @@ public final class ChromeCommandLineInitUtil {
private ChromeCommandLineInitUtil() {
}

@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
public static void initChromeCommandLine(Context context) {
if (!CommandLine.isInitialized()) {
File commandLineFile = getAlternativeCommandLinePath(context);
Expand All @@ -55,6 +57,7 @@ public static void initChromeCommandLine(Context context) {
/**
* Use an alternative path if adb is enabled and the debug app is chrome.
*/
@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
private static File getAlternativeCommandLinePath(Context context) {
File alternativeCommandLineFile =
new File(COMMAND_LINE_FILE_PATH_DEBUG_APP, COMMAND_LINE_FILE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ private BookmarkNode loadBookmarkFolder(long folderId) {
}

// Use the Mobile Bookmarks folder by default.
if (folderId < 0 || folderId == ChromeBrowserProviderClient.INVALID_BOOKMARK_ID) {
if (folderId < 0) {
folderId = ChromeBrowserProviderClient.getMobileBookmarksFolderId(mContext);
if (folderId == ChromeBrowserProviderClient.INVALID_BOOKMARK_ID) return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ protected void updateCacheVisibleIds(List<Integer> priority) {
* selection occurs.
*/
public void startHiding(int nextTabId, boolean hintAtTabSelection) {
getLayoutTab(nextTabId);
mUpdateHost.startHiding(nextTabId, hintAtTabSelection);
mIsHiding = true;
mNextTabId = nextTabId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,23 @@ public static void migrateTabsFromDocumentToClassic(final Activity activity,
// All the TabStates (incognito or not) live in the same directory.
File[] allTabs = normalTabModel.getStorageDelegate().getStateDirectory().listFiles();
try {
for (int i = 0; i < allTabs.length; i++) {
String fileName = allTabs[i].getName();
Pair<Integer, Boolean> tabInfo = TabState.parseInfoFromFilename(fileName);
if (tabInfo == null) continue;
int tabId = tabInfo.first;

// Also remove the tab state file for the closed tabs.
boolean success;
if (!tabIdsToRemove.contains(tabId)) {
success = allTabs[i].renameTo(new File(migratedFolder, fileName));
} else {
success = allTabs[i].delete();
}
if (allTabs != null) {
for (int i = 0; i < allTabs.length; i++) {
String fileName = allTabs[i].getName();
Pair<Integer, Boolean> tabInfo = TabState.parseInfoFromFilename(fileName);
if (tabInfo == null) continue;
int tabId = tabInfo.first;

// Also remove the tab state file for the closed tabs.
boolean success;
if (!tabIdsToRemove.contains(tabId)) {
success = allTabs[i].renameTo(new File(migratedFolder, fileName));
} else {
success = allTabs[i].delete();
}

if (!success) Log.e(TAG, "Failed to move/delete file for tab ID: " + tabId);
if (!success) Log.e(TAG, "Failed to move/delete file for tab ID: " + tabId);
}
}

if (normalTabModel.getCount() != 0) {
Expand Down Expand Up @@ -331,10 +333,11 @@ private static MigrationActivityDelegate createActivityDelegateWithTabsToMigrate
// Create maps for all tabs that will be used during TabModel initialization.
final List<Entry> normalEntryMap = new ArrayList<Entry>();

int currentSelectorIndex = 0;
File currentFolder = TabPersistentStore.getStateDirectory(activity, currentSelectorIndex);
File currentFolder = null;
MigrationTabStateReadCallback callback = new MigrationTabStateReadCallback();
while (currentFolder.listFiles() != null && currentFolder.listFiles().length != 0) {
for (int currentSelectorIndex = 0;
(currentFolder = getNextNonEmptyFolder(activity, currentSelectorIndex)) != null;
++currentSelectorIndex) {
File[] allTabs = TabPersistentStore
.getStateDirectory(activity, currentSelectorIndex).listFiles();
try {
Expand All @@ -343,29 +346,35 @@ private static MigrationActivityDelegate createActivityDelegateWithTabsToMigrate
Log.e(TAG, "IO Exception while trying to get the last used tab id");
}

for (int i = 0; i < allTabs.length; i++) {
// Move tab state file to the document side folder.
String fileName = allTabs[i].getName();
Pair<Integer, Boolean> tabInfo = TabState.parseInfoFromFilename(fileName);
if (tabInfo == null) continue;

boolean success;
if (tabInfo.second) {
success = allTabs[i].delete();
} else {
success = allTabs[i].renameTo(new File(migratedFolder, fileName));
normalEntryMap.add(new Entry(tabInfo.first, UrlConstants.NTP_URL));
}
if (allTabs != null) {
for (int i = 0; i < allTabs.length; i++) {
// Move tab state file to the document side folder.
String fileName = allTabs[i].getName();
Pair<Integer, Boolean> tabInfo = TabState.parseInfoFromFilename(fileName);
if (tabInfo == null) continue;

boolean success;
if (tabInfo.second) {
success = allTabs[i].delete();
} else {
success = allTabs[i].renameTo(new File(migratedFolder, fileName));
normalEntryMap.add(new Entry(tabInfo.first, UrlConstants.NTP_URL));
}

if (!success) Log.e(TAG, "Failed to move/delete file: " + fileName);
if (!success) Log.e(TAG, "Failed to move/delete file: " + fileName);
}
}
currentSelectorIndex++;
currentFolder = TabPersistentStore.getStateDirectory(activity, currentSelectorIndex);
}

return new MigrationActivityDelegate(normalEntryMap, callback.getSelectedTabId());
}

private static File getNextNonEmptyFolder(Activity activity, int currentSelectorIndex) {
File folder = TabPersistentStore.getStateDirectory(activity, currentSelectorIndex);
File[] files = folder.listFiles();
return (files == null || files.length == 0) ? null : folder;
}

private static void addAppTasksFromFiles(final Activity activity,
final MigrationTabModel tabModel, final int finalizeMode) {
if (tabModel.getCount() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2438,7 +2438,6 @@ private void updateFocusSource(boolean hasFocus) {
}

// Record UMA event for how the URL bar was focused.
assert !mHasRecordedUrlFocusSource;
if (mHasRecordedUrlFocusSource) return;

Tab currentTab = getCurrentTab();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
Expand All @@ -35,7 +34,9 @@
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationState;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.chrome.R;
import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils;
import org.chromium.ui.UiUtils;
Expand All @@ -51,7 +52,7 @@
*/
public class ShareHelper {

private static final String TAG = "ShareHelper";
private static final String TAG = "cr.chrome.browser";

private static final String PACKAGE_NAME_KEY = "last_shared_package_name";
private static final String CLASS_NAME_KEY = "last_shared_class_name";
Expand All @@ -64,13 +65,14 @@ public class ShareHelper {

private ShareHelper() {}

@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
private static void deleteScreenshotFiles(File file) {
if (!file.exists()) return;
if (file.isDirectory()) {
for (File f : file.listFiles()) deleteScreenshotFiles(f);
}
if (!file.delete()) {
Log.w(TAG, "Failed to delete screenshot file: " + file.getAbsolutePath());
Log.w(TAG, "Failed to delete screenshot file: %s", file.getAbsolutePath());
}
}

Expand Down
Loading

0 comments on commit 0d6c2e5

Please sign in to comment.