Browse Source

Fixed potential NullPointerExeptions

master
Anthony Restaino 10 years ago
parent
commit
1eed3ca948
  1. 2
      src/acr/browser/lightning/AdBlock.java
  2. 13
      src/acr/browser/lightning/BookmarkManager.java

2
src/acr/browser/lightning/AdBlock.java

@ -63,7 +63,7 @@ public class AdBlock {
} }
public boolean isAd(String url) { public boolean isAd(String url) {
if (!mBlockAds) { if (!mBlockAds || url == null) {
return false; return false;
} }

13
src/acr/browser/lightning/BookmarkManager.java

@ -47,8 +47,7 @@ public class BookmarkManager {
*/ */
public synchronized boolean addBookmark(HistoryItem item) { public synchronized boolean addBookmark(HistoryItem item) {
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS); File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
if (item.getUrl() == null || mBookmarkMap.containsKey(item.getUrl())) {
if (mBookmarkMap.containsKey(item.getUrl())) {
return false; return false;
} }
try { try {
@ -80,7 +79,7 @@ public class BookmarkManager {
try { try {
BufferedWriter bookmarkWriter = new BufferedWriter(new FileWriter(bookmarksFile, true)); BufferedWriter bookmarkWriter = new BufferedWriter(new FileWriter(bookmarksFile, true));
for (HistoryItem item : list) { for (HistoryItem item : list) {
if (!mBookmarkMap.containsKey(item.getUrl())) { if (item.getUrl() != null && !mBookmarkMap.containsKey(item.getUrl())) {
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
object.put(TITLE, item.getTitle()); object.put(TITLE, item.getTitle());
object.put(URL, item.getUrl()); object.put(URL, item.getUrl());
@ -106,6 +105,9 @@ public class BookmarkManager {
*/ */
public synchronized boolean deleteBookmark(String url) { public synchronized boolean deleteBookmark(String url) {
List<HistoryItem> list = new ArrayList<HistoryItem>(); List<HistoryItem> list = new ArrayList<HistoryItem>();
if (url == null) {
return false;
}
mBookmarkMap.remove(url); mBookmarkMap.remove(url);
list = getBookmarks(false); list = getBookmarks(false);
File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS); File bookmarksFile = new File(mContext.getFilesDir(), FILE_BOOKMARKS);
@ -427,6 +429,11 @@ public class BookmarkManager {
private class SortIgnoreCase implements Comparator<HistoryItem> { private class SortIgnoreCase implements Comparator<HistoryItem> {
public int compare(HistoryItem o1, HistoryItem o2) { public int compare(HistoryItem o1, HistoryItem o2) {
if (o1 == null || o2 == null) {
return 0;
} else if (o1.getTitle() == null || o2.getTitle() == null) {
return o1.getTitle().compareTo(o2.getTitle());
}
return o1.getTitle().toLowerCase(Locale.getDefault()) return o1.getTitle().toLowerCase(Locale.getDefault())
.compareTo(o2.getTitle().toLowerCase(Locale.getDefault())); .compareTo(o2.getTitle().toLowerCase(Locale.getDefault()));
} }

Loading…
Cancel
Save