Browse Source

Fixed potential NullPointerExceptions

Rather than try to correct the issue of the Comparator crashing in
BookmarkManager because the Strings/HistoryItems were null, I modified
the HistoryItem object so that the title, url, and folder strings can no
longer be null but will instead be empty if set to null, this then
prevents the BookmarkManager from throwing an NPE when sorting the items
by title.
master
Anthony Restaino 10 years ago
parent
commit
42de0b3ae7
  1. 4
      src/acr/browser/lightning/BookmarkManager.java
  2. 6
      src/acr/browser/lightning/HistoryItem.java

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

@ -429,10 +429,8 @@ public class BookmarkManager { @@ -429,10 +429,8 @@ public class BookmarkManager {
private class SortIgnoreCase implements Comparator<HistoryItem> {
public int compare(HistoryItem o1, HistoryItem o2) {
if (o1 == null || o2 == null) {
if (o1 == null || o2 == null || o1.getTitle() == null || o2.getTitle() == 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()));

6
src/acr/browser/lightning/HistoryItem.java

@ -67,7 +67,7 @@ public class HistoryItem implements Comparable<HistoryItem> { @@ -67,7 +67,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
}
public void setFolder(String folder) {
mFolder = folder;
mFolder = (folder == null) ? "" : folder;
}
public void setOrder(int order) {
@ -93,7 +93,7 @@ public class HistoryItem implements Comparable<HistoryItem> { @@ -93,7 +93,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
// setting name
public void setUrl(String url) {
this.mUrl = url;
this.mUrl = (url == null) ? "" : url;
}
// getting phone number
@ -103,7 +103,7 @@ public class HistoryItem implements Comparable<HistoryItem> { @@ -103,7 +103,7 @@ public class HistoryItem implements Comparable<HistoryItem> {
// setting phone number
public void setTitle(String title) {
this.mTitle = title;
this.mTitle = (title == null) ? "" : title;
}
@Override

Loading…
Cancel
Save