Changeset 17837 in josm for trunk/src/org


Ignore:
Timestamp:
2021-04-30T21:52:45+02:00 (3 years ago)
Author:
simon04
Message:

fix #20824 - NPE while sorting notes

Location:
trunk/src/org/openstreetmap/josm/data/notes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/notes/Note.java

    r17712 r17837  
    5353
    5454    /** Sorts notes by user, then creation date */
    55     public static final Comparator<Note> USER_COMPARATOR = (n1, n2) -> {
    56         String n1User = n1.getFirstComment().getUser().getName();
    57         String n2User = n2.getFirstComment().getUser().getName();
    58         return n1User.equals(n2User) ? DATE_COMPARATOR.compare(n1, n2) : n1User.compareTo(n2User);
    59     };
     55    public static final Comparator<Note> USER_COMPARATOR =
     56            Comparator.comparing(Note::getUserName, Comparator.nullsLast(Comparator.naturalOrder())).thenComparing(DATE_COMPARATOR);
    6057
    6158    /** Sorts notes by the last modified date */
    62     public static final Comparator<Note> LAST_ACTION_COMPARATOR =
    63             (n1, n2) -> NoteComment.DATE_COMPARATOR.compare(n1.getLastComment(), n2.getLastComment());
     59    public static final Comparator<Note> LAST_ACTION_COMPARATOR = Comparator.comparing(Note::getLastComment, NoteComment.DATE_COMPARATOR);
    6460
    6561    private long id;
     
    181177    public NoteComment getFirstComment() {
    182178        return comments.isEmpty() ? null : comments.get(0);
     179    }
     180
     181    private String getUserName() {
     182        return getFirstComment() == null ? null : getFirstComment().getUser().getName();
    183183    }
    184184
  • trunk/src/org/openstreetmap/josm/data/notes/NoteComment.java

    r17712 r17837  
    4040
    4141    /** Sorts note comments strictly by creation date */
    42     public static final Comparator<NoteComment> DATE_COMPARATOR = Comparator.comparing(n -> n.commentTimestamp);
     42    public static final Comparator<NoteComment> DATE_COMPARATOR = Comparator.nullsLast(Comparator.comparing(n -> n.commentTimestamp));
    4343
    4444    /**
Note: See TracChangeset for help on using the changeset viewer.