Skip to content

Commit 25780f5

Browse files
author
taylor.smock
committed
Cleanup some new PMD warnings from PMD 7.x (followup of r19101)
git-svn-id: https://josm.openstreetmap.de/svn/trunk@19108 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent b9add7c commit 25780f5

38 files changed

+178
-182
lines changed

scripts/TagInfoExtract.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ private String findImageUrl(String path) {
223223
}
224224

225225
private abstract class Extractor {
226-
abstract void run() throws Exception;
226+
abstract void run() throws IOException, OsmTransferException, ParseException, SAXException;
227227

228228
void writeJson(String name, String description, Iterable<TagInfoTag> tags) throws IOException {
229229
try (Writer writer = options.outputFile != null ? Files.newBufferedWriter(options.outputFile) : new StringWriter();

scripts/TaggingPresetSchemeWikiGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private TaggingPresetSchemeWikiGenerator() {
3434
// Hide public constructor for utility class
3535
}
3636

37-
public static void main(String[] args) throws Exception {
37+
public static void main(String[] args) throws IOException, ParserConfigurationException, SAXException, XPathExpressionException {
3838
document = parseTaggingPresetSchema();
3939
xPath = XPathFactory.newInstance().newXPath();
4040
xPath.setNamespaceContext(new TaggingNamespaceContext());

src/org/openstreetmap/josm/actions/OpenFileAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void actionPerformed(ActionEvent e) {
8383
final AbstractFileChooser fc;
8484
// If the user explicitly wants native file dialogs, let them use it.
8585
// Rather unfortunately, this means that they will not be able to select files and directories.
86-
if (FileChooserManager.PROP_USE_NATIVE_FILE_DIALOG.get()
86+
if (Boolean.TRUE.equals(FileChooserManager.PROP_USE_NATIVE_FILE_DIALOG.get())
8787
// This is almost redundant, as the JDK currently doesn't support this with (all?) native file choosers.
8888
&& !NativeFileChooser.supportsSelectionMode(FILES_AND_DIRECTORIES)) {
8989
fc = createAndOpenFileChooser(true, true, null);

src/org/openstreetmap/josm/actions/SelectAllAction.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.awt.event.ActionEvent;
88
import java.awt.event.KeyEvent;
99

10+
import org.openstreetmap.josm.data.osm.IPrimitive;
1011
import org.openstreetmap.josm.data.osm.OsmData;
1112
import org.openstreetmap.josm.tools.Shortcut;
1213

@@ -29,12 +30,7 @@ public void actionPerformed(ActionEvent e) {
2930
if (!isEnabled())
3031
return;
3132
OsmData<?, ?, ?, ?> ds = getLayerManager().getActiveData();
32-
// Do not use method reference before the Java 11 migration
33-
// Otherwise we face a compiler bug, see below:
34-
// https://bugs.openjdk.java.net/browse/JDK-8141508
35-
// https://bugs.openjdk.java.net/browse/JDK-8142476
36-
// https://bugs.openjdk.java.net/browse/JDK-8191655
37-
ds.setSelected(ds.getPrimitives(t -> t.isSelectable()));
33+
ds.setSelected(ds.getPrimitives(IPrimitive::isSelectable));
3834
}
3935

4036
@Override

src/org/openstreetmap/josm/actions/SelectByInternalPointAction.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,18 @@ public static OsmPrimitive getSmallestSurroundingObject(EastNorth internalPoint)
103103
public static void performSelection(EastNorth internalPoint, boolean doAdd, boolean doRemove) {
104104
final Collection<OsmPrimitive> surroundingObjects = getSurroundingObjects(internalPoint);
105105
final DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
106-
if (surroundingObjects.isEmpty()) {
107-
return;
108-
} else if (doRemove) {
109-
final Collection<OsmPrimitive> newSelection = new ArrayList<>(ds.getSelected());
110-
newSelection.removeAll(surroundingObjects);
111-
ds.setSelected(newSelection);
112-
} else if (doAdd) {
113-
final Collection<OsmPrimitive> newSelection = new ArrayList<>(ds.getSelected());
114-
newSelection.add(surroundingObjects.iterator().next());
115-
ds.setSelected(newSelection);
116-
} else {
117-
ds.setSelected(surroundingObjects.iterator().next());
106+
if (!surroundingObjects.isEmpty()) {
107+
if (doRemove) {
108+
final Collection<OsmPrimitive> newSelection = new ArrayList<>(ds.getSelected());
109+
newSelection.removeAll(surroundingObjects);
110+
ds.setSelected(newSelection);
111+
} else if (doAdd) {
112+
final Collection<OsmPrimitive> newSelection = new ArrayList<>(ds.getSelected());
113+
newSelection.add(surroundingObjects.iterator().next());
114+
ds.setSelected(newSelection);
115+
} else {
116+
ds.setSelected(surroundingObjects.iterator().next());
117+
}
118118
}
119119
}
120120
}

src/org/openstreetmap/josm/actions/SelectNonBranchingWaySequences.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ public SelectNonBranchingWaySequences(final Collection<Way> ways) {
5555
*/
5656
private void addNodes(Node node) {
5757
if (node == null) return;
58-
else if (!nodes.add(node))
58+
if (!nodes.add(node)) {
5959
outerNodes.remove(node);
60-
else
60+
} else {
6161
outerNodes.add(node);
62+
}
6263
}
6364

6465
/**

src/org/openstreetmap/josm/actions/SessionSaveAction.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
package org.openstreetmap.josm.actions;
33

44
import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5+
import static org.openstreetmap.josm.tools.I18n.marktr;
56
import static org.openstreetmap.josm.tools.I18n.tr;
67
import static org.openstreetmap.josm.tools.I18n.trn;
78

89
import java.awt.Component;
910
import java.awt.Dimension;
11+
import java.awt.GridBagConstraints;
1012
import java.awt.GridBagLayout;
1113
import java.awt.event.ActionEvent;
1214
import java.awt.event.KeyEvent;
@@ -83,6 +85,7 @@ public class SessionSaveAction extends DiskAccessAction implements MapFrameListe
8385
private static final BooleanProperty SAVE_LOCAL_FILES_PROPERTY = new BooleanProperty("session.savelocal", true);
8486
private static final BooleanProperty SAVE_PLUGIN_INFORMATION_PROPERTY = new BooleanProperty("session.saveplugins", false);
8587
private static final String TOOLTIP_DEFAULT = tr("Save the current session.");
88+
private static final String SAVE_SESSION = marktr("Save Session");
8689

8790
protected transient FileFilter joz = new ExtensionFileFilter("joz", "joz", tr("Session file (archive) (*.joz)"));
8891
protected transient FileFilter jos = new ExtensionFileFilter("jos", "jos", tr("Session file (*.jos)"));
@@ -119,7 +122,7 @@ public SessionSaveAction() {
119122
* @param installAdapters False, if you don't want to install layer changed and selection changed adapters
120123
*/
121124
protected SessionSaveAction(boolean toolbar, boolean installAdapters) {
122-
this(tr("Save Session"), "session", TOOLTIP_DEFAULT,
125+
this(tr(SAVE_SESSION), "session", TOOLTIP_DEFAULT,
123126
Shortcut.registerShortcut("system:savesession", tr("File: {0}", tr("Save Session...")), KeyEvent.VK_S, Shortcut.ALT_CTRL),
124127
toolbar, "save-session", installAdapters);
125128
setHelpId(ht("/Action/SessionSave"));
@@ -182,7 +185,7 @@ private boolean saveSessionImpl(boolean saveAs, boolean forceSaveAll) throws Use
182185
.filter(layer -> exporters.get(layer) != null && exporters.get(layer).shallExport())
183186
.collect(Collectors.toList());
184187

185-
boolean zipRequired = layersOut.stream().map(l -> exporters.get(l))
188+
boolean zipRequired = layersOut.stream().map(exporters::get)
186189
.anyMatch(ex -> ex != null && ex.requiresZip()) || pluginsWantToSave();
187190

188191
saveAs = !doGetFile(saveAs, zipRequired);
@@ -332,9 +335,9 @@ protected void doGetFileChooser(boolean zipRequired) throws UserCancelException
332335
AbstractFileChooser fc;
333336

334337
if (zipRequired) {
335-
fc = createAndOpenFileChooser(false, false, tr("Save Session"), joz, JFileChooser.FILES_ONLY, "lastDirectory");
338+
fc = createAndOpenFileChooser(false, false, tr(SAVE_SESSION), joz, JFileChooser.FILES_ONLY, "lastDirectory");
336339
} else {
337-
fc = createAndOpenFileChooser(false, false, tr("Save Session"), Arrays.asList(jos, joz), jos,
340+
fc = createAndOpenFileChooser(false, false, tr(SAVE_SESSION), Arrays.asList(jos, joz), jos,
338341
JFileChooser.FILES_ONLY, "lastDirectory");
339342
}
340343

@@ -365,7 +368,7 @@ public class SessionSaveAsDialog extends ExtendedDialog {
365368
* Constructs a new {@code SessionSaveAsDialog}.
366369
*/
367370
public SessionSaveAsDialog() {
368-
super(MainApplication.getMainFrame(), tr("Save Session"), tr("Save As"), tr("Cancel"));
371+
super(MainApplication.getMainFrame(), tr(SAVE_SESSION), tr("Save As"), tr("Cancel"));
369372
configureContextsensitiveHelp("Action/SessionSaveAs", true /* show help button */);
370373
initialize();
371374
setButtonIcons("save_as", "cancel");
@@ -441,10 +444,10 @@ protected final Component build() {
441444
if (exportPanel == null) continue;
442445
JPanel wrapper = new JPanel(new GridBagLayout());
443446
wrapper.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
444-
wrapper.add(exportPanel, GBC.std().fill(GBC.HORIZONTAL));
445-
ip.add(wrapper, GBC.eol().fill(GBC.HORIZONTAL).insets(2, 2, 4, 2));
447+
wrapper.add(exportPanel, GBC.std().fill(GridBagConstraints.HORIZONTAL));
448+
ip.add(wrapper, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(2, 2, 4, 2));
446449
}
447-
ip.add(GBC.glue(0, 1), GBC.eol().fill(GBC.VERTICAL));
450+
ip.add(GBC.glue(0, 1), GBC.eol().fill(GridBagConstraints.VERTICAL));
448451
JScrollPane sp = new JScrollPane(ip);
449452
sp.setBorder(BorderFactory.createEmptyBorder());
450453
JPanel p = new JPanel(new GridBagLayout());
@@ -474,7 +477,7 @@ protected final Component getDisabledExportPanel(Layer layer) {
474477
lbl.setEnabled(false);
475478
p.add(include, GBC.std());
476479
p.add(lbl, GBC.std());
477-
p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
480+
p.add(GBC.glue(1, 0), GBC.std().fill(GridBagConstraints.HORIZONTAL));
478481
return p;
479482
}
480483
}
@@ -537,7 +540,7 @@ private static void updateSessionFile(String fileName) throws UserCancelExceptio
537540
* @param layers layers that are currently represented in the session file
538541
* @deprecated since 18833, use {@link #setCurrentSession(File, List, SessionWriter.SessionWriterFlags...)} instead
539542
*/
540-
@Deprecated
543+
@Deprecated(since = "18833")
541544
public static void setCurrentSession(File file, boolean zip, List<Layer> layers) {
542545
if (zip) {
543546
setCurrentSession(file, layers, SessionWriter.SessionWriterFlags.IS_ZIP);

src/org/openstreetmap/josm/actions/downloadtasks/AbstractDownloadTask.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ public void setFailed(boolean failed) {
6060
}
6161

6262
protected static <T extends Enum<T> & UrlPattern> String[] patterns(Class<T> urlPatternEnum) {
63-
// Do not use a method reference until we switch to Java 11, as we face JDK-8141508 with Java 8
64-
return Arrays.stream(urlPatternEnum.getEnumConstants()).map(/* JDK-8141508 */ t -> t.pattern()).toArray(String[]::new);
63+
return Arrays.stream(urlPatternEnum.getEnumConstants()).map(UrlPattern::pattern).toArray(String[]::new);
6564
}
6665

6766
protected final void rememberErrorMessage(String message) {

src/org/openstreetmap/josm/actions/downloadtasks/DownloadTaskList.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ protected void handlePotentiallyDeletedPrimitives(Set<OsmPrimitive> potentiallyD
212212
*/
213213
public Set<OsmPrimitive> getDownloadedPrimitives() {
214214
return tasks.stream()
215-
.filter(t -> t instanceof DownloadOsmTask)
216-
.map(t -> ((DownloadOsmTask) t).getDownloadedData())
215+
.filter(DownloadOsmTask.class::isInstance)
216+
.map(DownloadOsmTask.class::cast)
217+
.map(DownloadOsmTask::getDownloadedData)
217218
.filter(Objects::nonNull)
218219
.flatMap(ds -> ds.allPrimitives().stream())
219220
.collect(Collectors.toSet());
@@ -239,7 +240,11 @@ public void run() {
239240
for (Future<?> future : taskFutures) {
240241
try {
241242
future.get();
242-
} catch (InterruptedException | ExecutionException | CancellationException e) {
243+
} catch (InterruptedException interruptedException) {
244+
Thread.currentThread().interrupt();
245+
Logging.error(interruptedException);
246+
return;
247+
} catch (ExecutionException | CancellationException e) {
243248
Logging.error(e);
244249
return;
245250
}
@@ -254,7 +259,6 @@ public void run() {
254259
+ tr("The following errors occurred during mass download: {0}",
255260
Utils.joinAsHtmlUnorderedList(errors)) + "</html>",
256261
tr("Errors during download"), JOptionPane.ERROR_MESSAGE);
257-
return;
258262
}
259263
});
260264
}
@@ -268,7 +272,7 @@ public void run() {
268272
final DataSet editDataSet = MainApplication.getLayerManager().getEditDataSet();
269273
if (editDataSet != null && osmData) {
270274
final List<DownloadOsmTask> osmTasks = tasks.stream()
271-
.filter(t -> t instanceof DownloadOsmTask).map(t -> (DownloadOsmTask) t)
275+
.filter(DownloadOsmTask.class::isInstance).map(DownloadOsmTask.class::cast)
272276
.filter(t -> t.getDownloadedData() != null)
273277
.collect(Collectors.toList());
274278
final Set<Bounds> tasksBounds = osmTasks.stream()

src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ public void mousePressed(MouseEvent e) {
389389
MapFrame map = MainApplication.getMap();
390390
if (!map.mapView.isActiveLayerVisible())
391391
return;
392-
if (!(Boolean) this.getValue("active"))
392+
if (Boolean.FALSE.equals(this.getValue("active")))
393393
return;
394394
if (e.getButton() != MouseEvent.BUTTON1)
395395
return;
@@ -511,7 +511,7 @@ public void mouseDragged(MouseEvent e) {
511511
//move nodes to new position
512512
if (moveCommand == null) {
513513
//make a new move command
514-
moveCommand = new MoveCommand(new ArrayList<OsmPrimitive>(movingNodeList), bestMovement);
514+
moveCommand = new MoveCommand(new ArrayList<>(movingNodeList), bestMovement);
515515
UndoRedoHandler.getInstance().add(moveCommand);
516516
} else {
517517
//reuse existing move command
@@ -938,7 +938,8 @@ private void calculatePossibleDirectionsForDualAlign() {
938938
*/
939939
private EastNorth calculateBestMovementAndNewNodes(EastNorth mouseEn) {
940940
EastNorth bestMovement = calculateBestMovement(mouseEn);
941-
EastNorth n1movedEn = initialN1en.add(bestMovement), n2movedEn;
941+
EastNorth n1movedEn = initialN1en.add(bestMovement);
942+
EastNorth n2movedEn;
942943

943944
// find out the movement distance, in metres
944945
double distance = ProjectionRegistry.getProjection().eastNorth2latlon(initialN1en).greatCircleDistance(
@@ -1157,7 +1158,8 @@ private void drawAngleSymbol(Graphics2D g2, Point2D center, Point2D normal, bool
11571158
double raoffsetx = symbolSize*factor*normal.getX();
11581159
double raoffsety = symbolSize*factor*normal.getY();
11591160

1160-
double cx = center.getX(), cy = center.getY();
1161+
final double cx = center.getX();
1162+
final double cy = center.getY();
11611163
double k = mirror ? -1 : 1;
11621164
Point2D ra1 = new Point2D.Double(cx + raoffsetx, cy + raoffsety);
11631165
Point2D ra3 = new Point2D.Double(cx - raoffsety*k, cy + raoffsetx*k);

0 commit comments

Comments
 (0)