Changeset 19535 in josm


Ignore:
Timestamp:
2026-02-20T11:51:47+01:00 (10 hours ago)
Author:
stoecker
Message:

remove a lot of PMD warnings, especially outdated ignores, see #24635

Location:
trunk
Files:
38 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java

    r19050 r19535  
    380380                    try {
    381381                        c.undoCommand();
    382                     } catch (Exception e) { // NOPMD
     382                    } catch (Exception e) {
    383383                        // fix #20098: restore command stack as we will not fire an event
    384384                        commands.add(c);
  • trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java

    r19462 r19535  
    200200                            diskAttributes, null, null, new StandardSerializer())));
    201201                }
    202             } catch (Exception e) { // NOPMD
     202            } catch (Exception e) {
    203203                // in case any error in setting auxiliary cache, do not use disk cache at all - only memory
    204204                cc.setAuxCaches(Collections.emptyList());
  • trunk/src/org/openstreetmap/josm/data/imagery/vectortile/mapbox/Layer.java

    r19519 r19535  
    9999     * @throws IOException - if an IO error occurs
    100100     */
    101     @SuppressWarnings("PMD.CloseResource") // The resources _are_ closed after use; it just isn't detect with PMD 7.2.x.
    102101    public Layer(Collection<ProtobufRecord> records) throws IOException {
    103102        // Do the unique required fields first
  • trunk/src/org/openstreetmap/josm/data/osm/AbstractPrimitive.java

    r19331 r19535  
    794794
    795795    @Override
    796     @SuppressWarnings("PMD.UseArraysAsList") // See https://github.com/pmd/pmd/issues/5071
    797796    public final Collection<String> keySet() {
    798797        String[] tKeys = this.keys;
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r19528 r19535  
    658658            return Stream.empty();
    659659        }
    660         final Stream<OsmPrimitive> stream = referrers instanceof OsmPrimitive // NOPMD
     660        final Stream<OsmPrimitive> stream = referrers instanceof OsmPrimitive
    661661                ? Stream.of((OsmPrimitive) referrers)
    662662                : Arrays.stream((OsmPrimitive[]) referrers);
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r19062 r19535  
    672672                    test.initialize();
    673673                }
    674             } catch (Exception e) { // NOPMD
     674            } catch (Exception e) {
    675675                String message = tr("Error initializing test {0}:\n {1}", test.getClass().getSimpleName(), e);
    676676                Logging.error(message);
  • trunk/src/org/openstreetmap/josm/data/vector/VectorPrimitive.java

    r19528 r19535  
    189189            return Stream.empty();
    190190        }
    191         final Stream<IPrimitive> stream = referrers instanceof IPrimitive // NOPMD
     191        final Stream<IPrimitive> stream = referrers instanceof IPrimitive
    192192          ? Stream.of((IPrimitive) referrers)
    193193          : Arrays.stream((IPrimitive[]) referrers);
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/ClipboardUtils.java

    r19531 r19535  
    117117                    Thread.currentThread().interrupt();
    118118                }
    119             } catch (NullPointerException | NoClassDefFoundError e) { // NOPMD
     119            } catch (NullPointerException | NoClassDefFoundError e) {
    120120                // JDK-6322854: On Linux/X11, NPE can happen for unknown reasons, on all versions of Java
    121121                // See #24642: Access can fail due to issues in ImageIO when an image is in clipboard
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandler.java

    r19519 r19535  
    9595        } catch (IllegalStateException e) {
    9696            Logging.debug(e);
    97         } catch (NullPointerException e) { // NOPMD
     97        } catch (NullPointerException e) {
    9898            // JDK-6322854: On Linux/X11, NPE can happen for unknown reasons, on all versions of Java
    9999            Logging.error(e);
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/FileImporter.java

    r19112 r19535  
    115115            displayError(f, e);
    116116            return false;
    117         } catch (RuntimeException | LinkageError e) { // NOPMD
     117        } catch (RuntimeException | LinkageError e) {
    118118            BugReportExceptionHandler.handleException(e);
    119119            return false;
  • trunk/src/org/openstreetmap/josm/gui/layer/AutosaveTask.java

    r19122 r19535  
    264264                    GuiHelper.runInEDT(this::displayNotification);
    265265                }
    266             } catch (RuntimeException t) { // NOPMD
     266            } catch (RuntimeException t) {
    267267                // Don't let exception stop time thread
    268268                Logging.error("Autosave failed:");
  • trunk/src/org/openstreetmap/josm/gui/mappaint/RenderingCLI.java

    r19519 r19535  
    274274                try {
    275275                    argBounds = new Bounds(arg, ",", Bounds.ParseMethod.LEFT_BOTTOM_RIGHT_TOP, false);
    276                 } catch (IllegalArgumentException iae) { // NOPMD
     276                } catch (IllegalArgumentException iae) {
    277277                    throw new OptionParseException(
    278278                            tr("Unable to parse {0} parameter: {1}", "--bounds", iae.getMessage()), iae);
     
    309309                double lat = LatLonParser.parseCoordinate(parts[1]);
    310310                argAnchor = new LatLon(lat, lon);
    311             } catch (IllegalArgumentException iae) { // NOPMD
     311            } catch (IllegalArgumentException iae) {
    312312                throw new OptionParseException(tr("In option {0}: {1}", "--anchor", iae.getMessage()), iae);
    313313            }
  • trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java

    r19335 r19535  
    675675                } catch (SecurityException ex) {
    676676                    Logging.error(ex);
    677                 } catch (RuntimeException ex) { // NOPMD
     677                } catch (RuntimeException ex) {
    678678                    // allow to change most settings even if e.g. a plugin fails
    679679                    BugReportExceptionHandler.handleException(ex);
     
    696696            } catch (SecurityException ex) {
    697697                Logging.error(ex);
    698             } catch (RuntimeException ex) { // NOPMD
     698            } catch (RuntimeException ex) {
    699699                BugReportExceptionHandler.handleException(ex);
    700700            } finally {
  • trunk/src/org/openstreetmap/josm/gui/preferences/map/MapPaintPreference.java

    r18417 r19535  
    173173                return css.title;
    174174            }
    175         } catch (RuntimeException ignore) { // NOPMD
     175        } catch (RuntimeException ignore) {
    176176            Logging.debug(ignore);
    177177        }
  • trunk/src/org/openstreetmap/josm/gui/progress/swing/PleaseWaitProgressMonitor.java

    r18801 r19535  
    112112            try {
    113113                runnable.run();
    114             } catch (RuntimeException e) { // NOPMD
     114            } catch (RuntimeException e) {
    115115                throw BugReport.intercept(e).put("monitor", this);
    116116            }
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReader.java

    r19374 r19535  
    128128         * @return the last inserted element
    129129         */
     130        @SuppressWarnings("PMD.MissingOverride") // For Java >= 21 we can drop the whole class
    130131        public E getLast() {
    131132            return last;
  • trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java

    r19112 r19535  
    268268            try {
    269269                return callable.call();
    270             } catch (Exception e) { // NOPMD
     270            } catch (Exception e) {
    271271                handleEDTException(e);
    272272                return null;
  • trunk/src/org/openstreetmap/josm/gui/widgets/JosmPasswordField.java

    r14273 r19535  
    129129                    try {
    130130                        pasteAction.actionPerformed(e);
    131                     } catch (NullPointerException npe) { // NOPMD
     131                    } catch (NullPointerException npe) {
    132132                        Logging.log(Logging.LEVEL_ERROR, "NullPointerException occurred because of JDK bug 6322854. "
    133133                                +"Copy/Paste operation has not been performed. Please complain to Oracle: "+
  • trunk/src/org/openstreetmap/josm/io/Compression.java

    r19500 r19535  
    178178    public static InputStream getUncompressedFileInputStream(File file) throws IOException {
    179179        try {
    180             return getUncompressedFileInputStream(file.toPath());  // NOPMD
     180            return getUncompressedFileInputStream(file.toPath());
    181181        } catch (InvalidPathException e) {
    182182            throw new IOException(e);
     
    192192     */
    193193    public static InputStream getUncompressedFileInputStream(Path path) throws IOException {
    194         InputStream in = Files.newInputStream(path); // NOPMD
     194        InputStream in = Files.newInputStream(path);
    195195        try {
    196196            return byExtension(path.getFileName().toString()).getUncompressedInputStream(in);
     
    233233     */
    234234    public static OutputStream getCompressedFileOutputStream(File file) throws IOException {
    235         return getCompressedFileOutputStream(file.toPath()); // NOPMD
     235        return getCompressedFileOutputStream(file.toPath());
    236236    }
    237237
     
    246246     */
    247247    public static OutputStream getCompressedFileOutputStream(Path path) throws IOException {
    248         OutputStream out = Files.newOutputStream(path); // NOPMD
     248        OutputStream out = Files.newOutputStream(path);
    249249        try {
    250250            return byExtension(path.getFileName().toString()).getCompressedOutputStream(out);
  • trunk/src/org/openstreetmap/josm/io/GeoJSONServerReader.java

    r15784 r19535  
    3737                return null;
    3838            progressMonitor.subTask(tr("Downloading OSM data..."));
    39             InputStream uncompressedInputStream = compression.getUncompressedInputStream(in); // NOPMD
     39            InputStream uncompressedInputStream = compression.getUncompressedInputStream(in);
    4040            ProgressMonitor subTaskMonitor = progressMonitor.createSubTaskMonitor(1, false);
    4141            return GeoJSONReader.parseDataSet(uncompressedInputStream, subTaskMonitor);
  • trunk/src/org/openstreetmap/josm/io/GpxParser.java

    r19519 r19535  
    593593        } else if (currentState != State.LINK) {
    594594            getAttr().ifPresent(attr ->
    595                 ((Collection<GpxLink>) attr.computeIfAbsent(META_LINKS, e -> new LinkedList<GpxLink>())).add(currentLink));
     595                ((Collection<GpxLink>) attr.computeIfAbsent(META_LINKS, e -> new LinkedList<>())).add(currentLink));
    596596        }
    597597    }
  • trunk/src/org/openstreetmap/josm/io/GpxReader.java

    r19080 r19535  
    4141     */
    4242    public GpxReader(InputStream source) throws IOException {
    43         Reader utf8stream = UTFInputStreamReader.create(source); // NOPMD
     43        Reader utf8stream = UTFInputStreamReader.create(source);
    4444        Reader filtered = new InvalidXmlCharacterFilter(utf8stream); // NOPMD
    4545        this.inputSource = new InputSource(filtered);
  • trunk/src/org/openstreetmap/josm/io/NameFinder.java

    r19519 r19535  
    300300                Logging.error(ex); // SAXException does not chain correctly
    301301                throw new SAXException(ex.getMessage(), ex);
    302             } catch (NullPointerException ex) { // NOPMD
     302            } catch (NullPointerException ex) {
    303303                Logging.error(ex); // SAXException does not chain correctly
    304304                throw new SAXException(tr("Null pointer exception, possibly some missing tags."), ex);
  • trunk/src/org/openstreetmap/josm/io/OsmJsonReader.java

    r18816 r19535  
    193193                IOException soe = (IOException) exception.getCause();
    194194                soe.addSuppressed(exception); // Add the caught exception as a suppressed exception
    195                 throw new IllegalDataException(soe); // NOPMD -- PreserveStackTrace should be fixed with PMD 7
     195                throw new IllegalDataException(soe);
    196196            }
    197197            throw exception;
  • trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java

    r18611 r19535  
    124124                return null;
    125125            progressMonitor.subTask(tr("Downloading OSM data..."));
    126             InputStream uncompressedInputStream = compression.getUncompressedInputStream(in); // NOPMD
     126            InputStream uncompressedInputStream = compression.getUncompressedInputStream(in);
    127127            ProgressMonitor subTaskMonitor = progressMonitor.createSubTaskMonitor(1, false);
    128128            if ("application/json".equals(contentType)) {
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSImagery.java

    r18918 r19535  
    214214                try {
    215215                    capabilitiesUrl = new File(workingAddress).toURI().toURL();
    216                 } catch (MalformedURLException e1) { // NOPMD
     216                } catch (MalformedURLException e1) {
    217217                    // do nothing, raise original exception
    218218                    Logging.trace(e1);
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandler.java

    r18211 r19535  
    5050            }
    5151            LoadAndZoomHandler.parseChangesetTags(args);
    52         } catch (RuntimeException ex) { // NOPMD
     52        } catch (RuntimeException ex) {
    5353            Logging.warn("RemoteControl: Error parsing import remote control request:");
    5454            Logging.error(ex);
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

    r19200 r19535  
    179179                }
    180180            }
    181         } catch (RuntimeException ex) { // NOPMD
     181        } catch (RuntimeException ex) {
    182182            Logging.warn("RemoteControl: Error parsing load_and_zoom remote control request:");
    183183            Logging.error(ex);
     
    247247                ExceptionDialogUtil.explainException(ex);
    248248            } catch (ExecutionException | TimeoutException |
    249                      OsmTransferException | RuntimeException ex) { // NOPMD
     249                     OsmTransferException | RuntimeException ex) {
    250250                ExceptionDialogUtil.explainException(ex);
    251251            }
  • trunk/src/org/openstreetmap/josm/io/session/GpxTracksSessionExporter.java

    r19106 r19535  
    8080    @Override
    8181    // The new closable resources in this method will close the input OutputStream
    82     @SuppressWarnings({"squid:S2095", "PMD.CloseResource"})
     82    @SuppressWarnings("squid:S2095")
    8383    protected void addDataFile(OutputStream out) {
    8484        Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
  • trunk/src/org/openstreetmap/josm/io/session/MarkerSessionExporter.java

    r19106 r19535  
    9696
    9797    // The new closable resources in this method will close the input OutputStream
    98     @SuppressWarnings({"squid:S2095", "PMD.CloseResource"})
     98    @SuppressWarnings("squid:S2095")
    9999    protected void addDataFile(OutputStream out) {
    100100        Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
  • trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java

    r19104 r19535  
    3939     *            avoid potential future issues)
    4040     */
    41     @SuppressWarnings({"squid:S2095", "PMD.CloseResource"}) // All the closeables in this method will close the input OutputStream.
     41    @SuppressWarnings("squid:S2095") // All the closeables in this method will close the input OutputStream.
    4242    public static void exportData(DataSet data, OutputStream out) {
    4343        // This writer will close out when it is closed
  • trunk/src/org/openstreetmap/josm/plugins/PluginClassLoader.java

    r19106 r19535  
    8989     * @return the class, if found, otherwise {@code null}
    9090     */
    91     @SuppressWarnings("PMD.CloseResource") // NOSONAR We do *not* want to close class loaders in this method...
    9291    private Class<?> findClassInDependencies(String name, boolean resolve) {
    9392        for (PluginClassLoader dep : dependencies) {
     
    106105
    107106    @Override
    108     @SuppressWarnings("PMD.CloseResource") // NOSONAR We do *not* want to close class loaders in this method...
    109107    public URL findResource(String name) {
    110108        URL resource = super.findResource(name);
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r19168 r19535  
    831831     * @param plugins the plugins to add
    832832     */
    833     @SuppressWarnings("PMD.CloseResource") // NOSONAR We do *not* want to close class loaders in this method...
    834833    private static void extendJoinedPluginResourceCL(Collection<PluginInformation> plugins) {
    835834        // iterate all plugins and collect all libraries of all plugins:
     
    877876                        + "Delete from preferences?</html>", "'"+Utils.escapeReservedCharactersHTML(plugin.name)+"'", plugin.className);
    878877            }
    879         } catch (RuntimeException e) { // NOPMD
     878        } catch (RuntimeException e) {
    880879            pluginLoadingExceptions.put(plugin.name, e);
    881880            Logging.error(e);
     
    937936     * @param toLoad The plugins to generate the classloaders for
    938937     */
    939     @SuppressWarnings({"squid:S2095", "PMD.CloseResource"}) // NOSONAR the classloaders and put in a map which we want to keep.
     938    @SuppressWarnings("squid:S2095") // NOSONAR the classloaders and put in a map which we want to keep.
    940939    private static void generateClassloaders(List<PluginInformation> toLoad) {
    941940        for (PluginInformation info : toLoad) {
     
    953952     * @param toLoad The plugins to resolve dependencies for
    954953     */
    955     @SuppressWarnings({"squid:S2095", "PMD.CloseResource"}) // NOSONAR the classloaders are from a persistent map
     954    @SuppressWarnings("squid:S2095") // NOSONAR the classloaders are from a persistent map
    956955    private static void resolveDependencies(List<PluginInformation> toLoad) {
    957956        for (PluginInformation info : toLoad) {
  • trunk/src/org/openstreetmap/josm/tools/HttpClient.java

    r19519 r19535  
    402402         * @see HttpURLConnection#getErrorStream()
    403403         */
    404         @SuppressWarnings({"resource",
    405                 /* All 4 `InputStream in` reassignments would close the original when the returned stream is closed */
    406                 "PMD.CloseResource"})
    407404        public final InputStream getContent() throws IOException {
    408405            InputStream in = new ProgressInputStream(getInputStream(), getContentLength(), monitor);
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r19307 r19535  
    15821582        CheckParameterUtil.ensureParameterNotNull(input, "input");
    15831583
    1584         ImageInputStream stream = createImageInputStream(input); // NOPMD
     1584        ImageInputStream stream = createImageInputStream(input);
    15851585        BufferedImage bi = read(stream, readMetadata, enforceTransparency);
    15861586        if (bi == null) {
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReport.java

    r19246 r19535  
    154154            try {
    155155                out.println(header);
    156             } catch (RuntimeException e) { // NOPMD
     156            } catch (RuntimeException e) {
    157157                out.println("Could not generate status report: " + e.getMessage());
    158158            }
  • trunk/src/org/openstreetmap/josm/tools/bugreport/ReportedException.java

    r19101 r19535  
    8282        try {
    8383            BugReportQueue.getInstance().submit(this);
    84         } catch (RuntimeException e) { // NOPMD
     84        } catch (RuntimeException e) {
    8585            Logging.error(e);
    8686        }
     
    227227                string = value.toString();
    228228            }
    229         } catch (RuntimeException t) { // NOPMD
     229        } catch (RuntimeException t) {
    230230            Logging.warn(t);
    231231            string = "<Error calling toString()>";
  • trunk/tools/pmd/josm-ruleset.xml

    r19520 r19535  
    108108  <rule ref="category/java/design.xml">
    109109    <exclude name="PublicMemberInNonPublicType" reason="Fixing these issues does not improve the code quality, rather the opposite"/>
    110     <exclude name="AvoidCatchingGenericException"/>
    111110    <exclude name="AvoidDeeplyNestedIfStmts"/>
    112111    <exclude name="AvoidRethrowingException"/>
     
    147146  </rule>
    148147  <rule ref="category/java/errorprone.xml">
     148    <exclude name="AvoidCatchingGenericException"/>
    149149    <exclude name="AssignmentInOperand"/>
    150150    <exclude name="AssignmentToNonFinalStatic"/>
Note: See TracChangeset for help on using the changeset viewer.