Changeset 18989 in josm for trunk


Ignore:
Timestamp:
2024-02-20T16:44:22+01:00 (9 months ago)
Author:
taylor.smock
Message:

Fix #23485: JOSM crashes when opening Imagery Preferences

  • SyncEditorLayerIndex.java now checks to see if imagery entries are valid; if not, it prints the missing fields and the standard description.
  • ImageryInfo now has isValid and getMissingFields; the latter method should only be called in tests or SyncEditorLayerIndex.
  • ImageryLayerInfo removes invalid ImageryInfo objects after parsing the source
Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/SyncEditorLayerIndex.java

    r18801 r18989  
    11// License: GPL. For details, see LICENSE file.
     2
    23import static java.nio.charset.StandardCharsets.UTF_8;
    34import static org.apache.commons.lang3.StringUtils.isBlank;
     
    3839import java.util.stream.Collectors;
    3940
    40 import jakarta.json.Json;
    41 import jakarta.json.JsonArray;
    42 import jakarta.json.JsonNumber;
    43 import jakarta.json.JsonObject;
    44 import jakarta.json.JsonReader;
    45 import jakarta.json.JsonString;
    46 import jakarta.json.JsonValue;
    47 
    4841import org.openstreetmap.gui.jmapviewer.Coordinate;
    4942import org.openstreetmap.josm.data.Preferences;
     
    6659import org.openstreetmap.josm.tools.Utils;
    6760import org.xml.sax.SAXException;
     61
     62import jakarta.json.Json;
     63import jakarta.json.JsonArray;
     64import jakarta.json.JsonNumber;
     65import jakarta.json.JsonObject;
     66import jakarta.json.JsonReader;
     67import jakarta.json.JsonString;
     68import jakarta.json.JsonValue;
    6869
    6970/**
     
    500501
    501502        for (ImageryInfo e : josmEntries) {
     503            if (!e.isValid()) {
     504                myprintln("~~~ JOSM-Entry missing fields (" + String.join(", ", e.getMissingFields()) + "): " + getDescription(e));
     505            }
    502506            if (isBlank(getUrl(e))) {
    503507                myprintln("~~~ JOSM-Entry without URL: " + getDescription(e));
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r18723 r18989  
    2020import java.util.stream.Collectors;
    2121
    22 import jakarta.json.Json;
    23 import jakarta.json.JsonObject;
    24 import jakarta.json.JsonReader;
    2522import javax.swing.ImageIcon;
    2623
     
    3936import org.openstreetmap.josm.tools.StreamUtils;
    4037import org.openstreetmap.josm.tools.Utils;
     38
     39import jakarta.json.Json;
     40import jakarta.json.JsonObject;
     41import jakarta.json.JsonReader;
    4142
    4243/**
     
    205206        }
    206207    }
     208
     209    private static final String[] EMPTY_STRING = new String[0];
    207210
    208211    private double pixelPerDegree;
     
    567570     * Check if this object equals another ImageryInfo with respect to the properties
    568571     * that get written to the preference file.
    569      *
     572     * <p>
    570573     * The field {@link #pixelPerDegree} is ignored.
    571574     *
     
    965968
    966969    /**
     970     * Check to see if this info is valid (the XSD is overly permissive due to limitations of the XSD syntax).
     971     * @return {@code true} if this info is valid
     972     * @see ImageryInfo#getMissingFields()
     973     * @since 18989
     974     */
     975    public boolean isValid() {
     976        return this.getName() != null &&
     977                this.getId() != null &&
     978                this.getSourceType() != null &&
     979                this.getUrl() != null &&
     980                this.getImageryCategory() != null;
     981    }
     982
     983    /**
     984     * Get the missing fields for this info
     985     * @return The missing fields, or an empty array
     986     * @see ImageryInfo#isValid()
     987     * @since 18989
     988     */
     989    public String[] getMissingFields() {
     990        if (this.isValid()) {
     991            return EMPTY_STRING;
     992        }
     993        List<String> missingFields = new ArrayList<>();
     994        if (this.getName() == null) {
     995            missingFields.add("name");
     996        }
     997        if (this.getId() == null) {
     998            missingFields.add("id");
     999        }
     1000        if (this.getSourceType() == null) {
     1001            missingFields.add("type");
     1002        }
     1003        if (this.getUrl() == null) {
     1004            missingFields.add("url");
     1005        }
     1006        if (this.getImageryCategory() == null) {
     1007            missingFields.add("category");
     1008        }
     1009        return missingFields.toArray(new String[0]);
     1010    }
     1011
     1012    /**
    9671013     * Return the sorted list of activated source IDs.
    9681014     * @return sorted list of activated source IDs
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java

    r18211 r18989  
    167167                reader.setFastFail(fastFail);
    168168                Collection<ImageryInfo> result = reader.parse();
     169                // See #23485 (remove invalid source entries)
     170                result.removeIf(info -> !info.isValid());
    169171                newLayers.addAll(result);
    170172            } catch (IOException ex) {
Note: See TracChangeset for help on using the changeset viewer.