Changeset 17523 in josm


Ignore:
Timestamp:
2021-02-22T12:27:24+01:00 (15 months ago)
Author:
Don-vip
Message:

fix #20519 - NPE in Upload Dialog

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r17521 r17523  
    342342    /**
    343343     * Returns the given comment with appended hashtags from dataset changeset tags, if not already present.
    344      * @param comment changeset comment
     344     * @param comment changeset comment. Can be null
    345345     * @param dataSet optional dataset, which can contain hashtags in its changeset tags
    346346     * @return comment with dataset changesets tags, if any, not duplicated
    347347     */
    348     private static String getCommentWithDataSetHashTag(String comment, DataSet dataSet) {
    349         StringBuilder result = new StringBuilder(comment);
     348    static String getCommentWithDataSetHashTag(String comment, DataSet dataSet) {
     349        StringBuilder result = comment == null ? new StringBuilder() : new StringBuilder(comment);
    350350        if (dataSet != null) {
    351351            String hashtags = dataSet.getChangeSetTags().get("hashtags");
  • trunk/test/unit/org/openstreetmap/josm/gui/io/UploadDialogTest.java

    r17275 r17523  
    2020import org.junit.jupiter.api.extension.RegisterExtension;
    2121import org.openstreetmap.josm.TestUtils;
     22import org.openstreetmap.josm.data.osm.DataSet;
    2223import org.openstreetmap.josm.gui.io.UploadDialog.UploadAction;
    2324import org.openstreetmap.josm.io.UploadStrategySpecification;
     
    195196        doTestValidateUploadTag("upload.source");
    196197    }
     198
     199    @Test
     200    void testGetCommentWithDataSetHashTag() {
     201        assertEquals("", UploadDialog.getCommentWithDataSetHashTag(null, null));
     202        DataSet ds = new DataSet();
     203        assertEquals("foo", UploadDialog.getCommentWithDataSetHashTag("foo", ds));
     204        ds.getChangeSetTags().put("hashtags", "bar");
     205        assertEquals("foo #bar", UploadDialog.getCommentWithDataSetHashTag("foo", ds));
     206        ds.getChangeSetTags().put("hashtags", "bar;baz;#bar");
     207        assertEquals("foo #bar #baz", UploadDialog.getCommentWithDataSetHashTag("foo", ds));
     208    }
    197209}
Note: See TracChangeset for help on using the changeset viewer.