Subject: [PATCH] #23485: JOSM crashes when opening Imagery Preferences
---
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/scripts/SyncEditorLayerIndex.java b/scripts/SyncEditorLayerIndex.java
|
a
|
b
|
|
| 6 | 6 | import java.io.BufferedReader; |
| 7 | 7 | import java.io.BufferedWriter; |
| 8 | 8 | import java.io.IOException; |
| | 9 | import java.io.InputStream; |
| 9 | 10 | import java.io.OutputStreamWriter; |
| 10 | 11 | import java.io.Writer; |
| 11 | 12 | import java.lang.reflect.Field; |
| 12 | 13 | import java.net.MalformedURLException; |
| | 14 | import java.net.URI; |
| 13 | 15 | import java.net.URL; |
| 14 | 16 | import java.nio.charset.Charset; |
| 15 | 17 | import java.nio.file.Files; |
| … |
… |
|
| 37 | 39 | import java.util.regex.Pattern; |
| 38 | 40 | import java.util.stream.Collectors; |
| 39 | 41 | |
| 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 | | |
| 48 | 42 | import org.openstreetmap.gui.jmapviewer.Coordinate; |
| 49 | 43 | import org.openstreetmap.josm.data.Preferences; |
| 50 | 44 | import org.openstreetmap.josm.data.imagery.ImageryInfo; |
| … |
… |
|
| 57 | 51 | import org.openstreetmap.josm.data.validation.routines.DomainValidator; |
| 58 | 52 | import org.openstreetmap.josm.io.imagery.ImageryReader; |
| 59 | 53 | import org.openstreetmap.josm.spi.preferences.Config; |
| | 54 | import org.openstreetmap.josm.tools.HttpClient; |
| | 55 | import org.openstreetmap.josm.tools.Http1Client; |
| 60 | 56 | import org.openstreetmap.josm.tools.ImageProvider; |
| 61 | 57 | import org.openstreetmap.josm.tools.JosmRuntimeException; |
| 62 | 58 | import org.openstreetmap.josm.tools.Logging; |
| … |
… |
|
| 66 | 62 | import org.openstreetmap.josm.tools.Utils; |
| 67 | 63 | import org.xml.sax.SAXException; |
| 68 | 64 | |
| | 65 | import jakarta.json.Json; |
| | 66 | import jakarta.json.JsonArray; |
| | 67 | import jakarta.json.JsonNumber; |
| | 68 | import jakarta.json.JsonObject; |
| | 69 | import jakarta.json.JsonReader; |
| | 70 | import jakarta.json.JsonString; |
| | 71 | import jakarta.json.JsonValue; |
| | 72 | |
| 69 | 73 | /** |
| 70 | 74 | * Compare and analyse the differences of the editor layer index and the JOSM imagery list. |
| 71 | 75 | * The goal is to keep both lists in sync. |
| … |
… |
|
| 236 | 240 | } |
| 237 | 241 | |
| 238 | 242 | void loadSkip() throws IOException { |
| | 243 | if (Files.notExists(Paths.get(ignoreInputFile))) { |
| | 244 | return; |
| | 245 | } |
| 239 | 246 | final Pattern pattern = Pattern.compile("^\\|\\| *(ELI|Ignore) *\\|\\| *\\{\\{\\{(.+)\\}\\}\\} *\\|\\|"); |
| 240 | 247 | try (BufferedReader fr = Files.newBufferedReader(Paths.get(ignoreInputFile), UTF_8)) { |
| 241 | 248 | String line; |
| … |
… |
|
| 494 | 501 | } |
| 495 | 502 | |
| 496 | 503 | void loadJosmEntries() throws IOException, SAXException, ReflectiveOperationException { |
| | 504 | if (Files.notExists(Paths.get(josmInputFile))) { |
| | 505 | HttpClient.setFactory(Http1Client::new); |
| | 506 | final HttpClient client = HttpClient.create(URI.create("https://josm.openstreetmap.de/maps").toURL()); |
| | 507 | try (InputStream inputStream = client.connect().getContent()) { |
| | 508 | Files.copy(inputStream, Paths.get(josmInputFile)); |
| | 509 | } finally { |
| | 510 | client.disconnect(); |
| | 511 | } |
| | 512 | } |
| | 513 | |
| 497 | 514 | try (ImageryReader reader = new ImageryReader(josmInputFile)) { |
| 498 | 515 | josmEntries = reader.parse(); |
| 499 | 516 | } |
| 500 | 517 | |
| 501 | 518 | for (ImageryInfo e : josmEntries) { |
| | 519 | if (!e.isValid()) { |
| | 520 | myprintln("~~~ JOSM-Entry missing fields (" + String.join(", ", e.getMissingFields()) + "): " + getDescription(e)); |
| | 521 | } |
| 502 | 522 | if (isBlank(getUrl(e))) { |
| 503 | 523 | myprintln("~~~ JOSM-Entry without URL: " + getDescription(e)); |
| 504 | 524 | continue; |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java b/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
|
a
|
b
|
|
| 19 | 19 | import java.util.regex.Pattern; |
| 20 | 20 | import java.util.stream.Collectors; |
| 21 | 21 | |
| 22 | | import jakarta.json.Json; |
| 23 | | import jakarta.json.JsonObject; |
| 24 | | import jakarta.json.JsonReader; |
| 25 | 22 | import javax.swing.ImageIcon; |
| 26 | 23 | |
| 27 | 24 | import org.openstreetmap.josm.data.StructUtils.StructEntry; |
| … |
… |
|
| 39 | 36 | import org.openstreetmap.josm.tools.StreamUtils; |
| 40 | 37 | import org.openstreetmap.josm.tools.Utils; |
| 41 | 38 | |
| | 39 | import jakarta.json.Json; |
| | 40 | import jakarta.json.JsonObject; |
| | 41 | import jakarta.json.JsonReader; |
| | 42 | |
| 42 | 43 | /** |
| 43 | 44 | * Class that stores info about an image background layer. |
| 44 | 45 | * |
| … |
… |
|
| 205 | 206 | } |
| 206 | 207 | } |
| 207 | 208 | |
| | 209 | private static final String[] EMPTY_STRING = new String[0]; |
| | 210 | |
| 208 | 211 | private double pixelPerDegree; |
| 209 | 212 | /** maximum zoom level for TMS imagery */ |
| 210 | 213 | private int defaultMaxZoom; |
| … |
… |
|
| 963 | 966 | } |
| 964 | 967 | } |
| 965 | 968 | |
| | 969 | /** |
| | 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 | * @since xxx |
| | 973 | */ |
| | 974 | public boolean isValid() { |
| | 975 | return this.getName() != null && |
| | 976 | this.getId() != null && |
| | 977 | this.getSourceType() != null && |
| | 978 | this.getUrl() != null && |
| | 979 | this.getImageryCategory() != null; |
| | 980 | } |
| | 981 | |
| | 982 | /** |
| | 983 | * Get the missing fields for this info |
| | 984 | * @return The missing fields, or an empty array |
| | 985 | */ |
| | 986 | public String[] getMissingFields() { |
| | 987 | if (this.isValid()) { |
| | 988 | return EMPTY_STRING; |
| | 989 | } |
| | 990 | List<String> missingFields = new ArrayList<>(); |
| | 991 | if (this.getName() == null) { |
| | 992 | missingFields.add("name"); |
| | 993 | } |
| | 994 | if (this.getId() == null) { |
| | 995 | missingFields.add("id"); |
| | 996 | } |
| | 997 | if (this.getSourceType() == null) { |
| | 998 | missingFields.add("type"); |
| | 999 | } |
| | 1000 | if (this.getUrl() == null) { |
| | 1001 | missingFields.add("url"); |
| | 1002 | } |
| | 1003 | if (this.getImageryCategory() == null) { |
| | 1004 | missingFields.add("category"); |
| | 1005 | } |
| | 1006 | return missingFields.toArray(new String[0]); |
| | 1007 | } |
| | 1008 | |
| 966 | 1009 | /** |
| 967 | 1010 | * Return the sorted list of activated source IDs. |
| 968 | 1011 | * @return sorted list of activated source IDs |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java b/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java
|
a
|
b
|
|
| 166 | 166 | reader = new ImageryReader(source); |
| 167 | 167 | reader.setFastFail(fastFail); |
| 168 | 168 | Collection<ImageryInfo> result = reader.parse(); |
| | 169 | // See #23485 (remove invalid source entries) |
| | 170 | result.removeIf(info -> !info.isValid()); |
| 169 | 171 | newLayers.addAll(result); |
| 170 | 172 | } catch (IOException ex) { |
| 171 | 173 | loadError = true; |