Changeset 18805 in josm for trunk/src/org


Ignore:
Timestamp:
2023-08-14T17:34:52+02:00 (11 months ago)
Author:
taylor.smock
Message:

Fix #23117: NPE in PlaceSelection$NamedResultTableModel

This occurs when (a) search results are returned and then (b) the user searches
for more results, but nominatim returns garbage.

In addition, this also fixes some lint issues.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/download/PlaceSelection.java

    r18173 r18805  
    8383
    8484    private static class Server {
    85         public final String name;
    86         public final BiFunction<String, Collection<SearchResult>, URL> urlFunction;
    87         public final String thirdcol;
    88         public final String fourthcol;
     85        final String name;
     86        final BiFunction<String, Collection<SearchResult>, URL> urlFunction;
     87        final String thirdcol;
     88        final String fourthcol;
    8989
    9090        Server(String n, BiFunction<String, Collection<SearchResult>, URL> u, String t, String f) {
     
    133133    /**
    134134     * Adds a new tab to the download dialog in JOSM.
    135      *
     135     * <p>
    136136     * This method is, for all intents and purposes, the constructor for this class.
    137137     */
     
    192192        public void actionPerformed(ActionEvent e) {
    193193            String searchExpression = cbSearchExpression.getText();
    194             if (!isEnabled() || searchExpression.trim().isEmpty())
     194            if (!isEnabled() || searchExpression.trim().isEmpty() || serverComboBox.getSelectedItem() == null)
    195195                return;
    196196            cbSearchExpression.addCurrentItemToHistory();
     
    298298                            JOptionPane.WARNING_MESSAGE, null
    299299                    ));
     300                    generateLastException(e);
    300301                }
    301302            } catch (IOException | ParserConfigurationException e) {
    302                 if (!canceled) {
    303                     OsmTransferException ex = new OsmTransferException(e);
    304                     ex.setUrl(url.toString());
    305                     lastException = ex;
    306                 }
     303                generateLastException(e);
     304            }
     305        }
     306
     307        /**
     308         * Generate an {@link OsmTransferException} that will be stored in {@link #lastException} if the operation is
     309         * not cancelled.
     310         * @param throwable The throwable to store as an {@link OsmTransferException}
     311         */
     312        private void generateLastException(Throwable throwable) {
     313            if (!canceled) {
     314                OsmTransferException ex = new OsmTransferException(throwable);
     315                ex.setUrl(url.toString());
     316                lastException = ex;
    307317            }
    308318        }
     
    337347        }
    338348
     349        /**
     350         * Add data to the table
     351         * @param data The data to add
     352         */
    339353        public void addData(List<SearchResult> data) {
    340354            this.data.addAll(data);
     
    403417        }
    404418
     419        /**
     420         * Set the header column values for the third and fourth columns
     421         * @param third The new header for the third column
     422         * @param fourth The new header for the fourth column
     423         */
    405424        public void setHeadlines(String third, String fourth) {
    406425            col3.setHeaderValue(third);
Note: See TracChangeset for help on using the changeset viewer.