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

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

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

Loading…
Cancel
Save