Index: /trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java	(revision 13827)
+++ /trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java	(revision 13828)
@@ -140,5 +140,5 @@
             if (!GraphicsEnvironment.isHeadless()) {
                 JOptionPane.showMessageDialog(Main.parent, tr("Could not parse WMTS layer list."),
-                        tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
+                        tr("WMTS Error"), JOptionPane.ERROR_MESSAGE);
             }
             Logging.log(Logging.LEVEL_ERROR, "Could not parse WMTS layer list.", e);
Index: /trunk/src/org/openstreetmap/josm/data/imagery/GetCapabilitiesParseHelper.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/imagery/GetCapabilitiesParseHelper.java	(revision 13827)
+++ /trunk/src/org/openstreetmap/josm/data/imagery/GetCapabilitiesParseHelper.java	(revision 13828)
@@ -75,4 +75,6 @@
 
     /**
+     * Returns reader with properties set for parsing WM(T)S documents
+     *
      * @param in InputStream with pointing to GetCapabilities XML stream
      * @return safe XMLStreamReader, that is not validating external entities, nor loads DTD's
@@ -235,4 +237,6 @@
 
     /**
+     * Normalize url
+     *
      * @param url URL
      * @return normalized URL
Index: /trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java	(revision 13827)
+++ /trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java	(revision 13828)
@@ -24,4 +24,5 @@
 import javax.json.Json;
 import javax.json.JsonObject;
+import javax.json.JsonReader;
 import javax.json.stream.JsonCollectors;
 import javax.swing.ImageIcon;
@@ -556,9 +557,11 @@
         modTileFeatures = e.modTileFeatures;
         if (e.default_layers != null) {
-            defaultLayers = Json.createReader(new StringReader(e.default_layers)).
-                    readArray().
-                    stream().
-                    map(x -> DefaultLayer.fromJson((JsonObject) x, imageryType)).
-                    collect(Collectors.toList());
+            try (JsonReader jsonReader = Json.createReader(new StringReader(e.default_layers))) {
+                defaultLayers = jsonReader.
+                        readArray().
+                        stream().
+                        map(x -> DefaultLayer.fromJson((JsonObject) x, imageryType)).
+                        collect(Collectors.toList());
+            }
         }
         customHttpHeaders = e.customHttpHeaders;
Index: /trunk/src/org/openstreetmap/josm/data/imagery/TileLoaderFactory.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/imagery/TileLoaderFactory.java	(revision 13827)
+++ /trunk/src/org/openstreetmap/josm/data/imagery/TileLoaderFactory.java	(revision 13828)
@@ -17,4 +17,6 @@
 
     /**
+     * Creates TileLoaderFactory - factory that creates tile loaders with all options already set
+     *
      * @param listener that will be notified, when tile has finished loading
      * @param headers that will be sent with requests to TileSource. <code>null</code> indicates none
Index: /trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java	(revision 13827)
+++ /trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java	(revision 13828)
@@ -14,5 +14,7 @@
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Deque;
 import java.util.LinkedHashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -21,5 +23,4 @@
 import java.util.Optional;
 import java.util.SortedSet;
-import java.util.Stack;
 import java.util.TreeSet;
 import java.util.concurrent.ConcurrentHashMap;
@@ -252,5 +253,5 @@
 
     /**
-     * Exception thrown when praser doesn't find expected information in GetCapabilities document
+     * Exception thrown when parser doesn't find expected information in GetCapabilities document
      *
      */
@@ -258,4 +259,5 @@
 
         /**
+         * Create WMTS exception
          * @param cause description of cause
          */
@@ -265,4 +267,5 @@
 
         /**
+         * Create WMTS exception
          * @param cause description of cause
          * @param t nested exception
@@ -373,4 +376,6 @@
 
     /**
+     * Call remote server and parse response to WMTSCapabilities object
+     *
      * @param url of the getCapabilities document
      * @param headers HTTP headers to set when calling getCapabilities url
@@ -479,5 +484,5 @@
     private static Layer parseLayer(XMLStreamReader reader) throws XMLStreamException {
         Layer layer = new Layer();
-        Stack<QName> tagStack = new Stack<>();
+        Deque<QName> tagStack = new LinkedList<>();
         List<String> supportedMimeTypes = new ArrayList<>(Arrays.asList(ImageIO.getReaderMIMETypes()));
         supportedMimeTypes.add("image/jpgpng");         // used by ESRI
Index: /trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMSLayerPanel.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMSLayerPanel.java	(revision 13827)
+++ /trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMSLayerPanel.java	(revision 13828)
@@ -42,5 +42,4 @@
     private final transient WMSLayerTree tree = new WMSLayerTree();
     private final JComboBox<String> formats = new JComboBox<>();
-    private final JLabel wmsInstruction;
     private final JosmTextArea wmsUrl = new JosmTextArea(3, 40).transferFocusOnTab();
     private final JButton showBounds = new JButton(tr("Show bounds"));
@@ -73,5 +72,5 @@
         addCommonSettings();
 
-        wmsInstruction = new JLabel(tr("{0} Edit generated {1} URL (optional)", "6.", "WMS"));
+        JLabel wmsInstruction = new JLabel(tr("{0} Edit generated {1} URL (optional)", "6.", "WMS"));
         add(wmsInstruction, GBC.eol());
         wmsInstruction.setLabelFor(wmsUrl);
Index: /trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMTSLayerPanel.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMTSLayerPanel.java	(revision 13827)
+++ /trunk/src/org/openstreetmap/josm/gui/preferences/imagery/AddWMTSLayerPanel.java	(revision 13828)
@@ -46,7 +46,5 @@
         JButton getLayers = new JButton(tr("{0} Get layers", "3."));
         getLayers.setEnabled(setDefaultLayer.isSelected());
-        setDefaultLayer.addActionListener(e -> {
-                getLayers.setEnabled(setDefaultLayer.isSelected());
-        });
+        setDefaultLayer.addActionListener(e -> getLayers.setEnabled(setDefaultLayer.isSelected()));
         add(setDefaultLayer, GBC.eop());
         add(getLayers, GBC.eop().fill(GBC.HORIZONTAL));
@@ -76,4 +74,5 @@
                 layerPanel.revalidate();
             } catch (IOException | WMTSGetCapabilitiesException ex) {
+                Logging.trace(ex);
                 JOptionPane.showMessageDialog(
                         getParent(),
Index: /trunk/src/org/openstreetmap/josm/gui/preferences/imagery/HeadersTable.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/preferences/imagery/HeadersTable.java	(revision 13827)
+++ /trunk/src/org/openstreetmap/josm/gui/preferences/imagery/HeadersTable.java	(revision 13828)
@@ -81,5 +81,4 @@
     }
 
-    private final JTable table;
     private List<String[]> headers;
 
@@ -98,5 +97,5 @@
         super(new GridBagLayout());
         this.headers = getHeadersAsVector(headers);
-        table = new JTable(new HeaderTableModel());
+        JTable table = new JTable(new HeaderTableModel());
         table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
         table.setAutoCreateRowSorter(true);
Index: /trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java	(revision 13827)
+++ /trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java	(revision 13828)
@@ -177,5 +177,5 @@
                 capabilitiesUrl = new URL(workingAddress);
             } catch (MalformedURLException e) {
-                if (savedExc != null) {
+                if (savedExc == null) {
                     savedExc = e;
                 }
