Skip to content

Commit

Permalink
Fix most new PMD issues
Browse files Browse the repository at this point in the history
It would be better to use the newer switch syntax introduced in Java 14 (JEP 361),
but we currently target Java 11+. When we move to Java 17, this should be
reverted and the newer switch syntax should be used.

git-svn-id: https://josm.openstreetmap.de/svn/trunk@19307 0c6e7542-c601-0410-84e7-c038aed88b3b
  • Loading branch information
taylor.smock committed Feb 3, 2025
1 parent 7ce8ee1 commit eb61873
Show file tree
Hide file tree
Showing 41 changed files with 151 additions and 142 deletions.
2 changes: 0 additions & 2 deletions scripts/TagInfoExtract.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ public static void main(String[] args) throws IOException, OsmTransferException,
case EXTERNAL_PRESETS:
script.new ExternalPresets().run();
break;
default:
throw new IllegalStateException("Invalid type " + script.options.mode);
}
if (!script.options.noexit) {
System.exit(0);
Expand Down
2 changes: 0 additions & 2 deletions src/org/openstreetmap/josm/actions/AutoScaleAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ public AutoScaleAction(final AutoScaleMode mode) {
case NEXT:
setHelpId(ht("/Action/ZoomToNext"));
break;
default:
throw new IllegalArgumentException("Unknown mode: " + mode);
}
installAdapters();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ private void updateCursor() {
case DRAGGING:
newCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
break;
default: throw new AssertionError();
}
if (newCursor != null) {
mv.setNewCursor(newCursor, this);
Expand Down
9 changes: 4 additions & 5 deletions src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@

/**
* Move is an action that can move all kind of OsmPrimitives (except keys for now).
*
* <p>
* If an selected object is under the mouse when dragging, move all selected objects.
* If an unselected object is under the mouse when dragging, it becomes selected
* and will be moved.
* If no object is under the mouse, move all selected objects (if any)
*
* <p>
* On Mac OS X, Ctrl + mouse button 1 simulates right click (map move), so the
* feature "selection remove" is disabled on this platform.
*/
Expand Down Expand Up @@ -401,9 +401,9 @@ private boolean repaintIfRequired(OsmPrimitive newHighlight) {
/**
* Look, whether any object is selected. If not, select the nearest node.
* If there are no nodes in the dataset, do nothing.
*
* <p>
* If the user did not press the left mouse button, do nothing.
*
* <p>
* Also remember the starting position of the movement and change the mouse
* cursor to movement.
*/
Expand Down Expand Up @@ -464,7 +464,6 @@ public void mousePressed(MouseEvent e) {
GuiHelper.scheduleTimer(initialMoveDelay+1, evt -> updateStatusLine(), false);
break;
case SELECT:
default:
if (!(ctrl && PlatformManager.isPlatformOsx())) {
// start working with rectangle or lasso
selectionManager.register(mv, lassoMode);
Expand Down
4 changes: 1 addition & 3 deletions src/org/openstreetmap/josm/command/SplitWayCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public static Optional<SplitWayCommand> doSplitWay(Way way,
}
}

MissingMemberStrategy missingMemberStrategy;
MissingMemberStrategy missingMemberStrategy = USER_ABORTED; // default case
if (relationsNeedingMoreMembers.isEmpty()) {
// The split can be performed without any extra downloads.
missingMemberStrategy = GO_AHEAD_WITHOUT_DOWNLOADS;
Expand All @@ -392,7 +392,6 @@ public static Optional<SplitWayCommand> doSplitWay(Way way,
missingMemberStrategy = GO_AHEAD_WITH_DOWNLOADS;
break;
case ABORT:
default:
missingMemberStrategy = USER_ABORTED;
break;
}
Expand All @@ -418,7 +417,6 @@ public static Optional<SplitWayCommand> doSplitWay(Way way,
// the split without downloading them.
break;
case USER_ABORTED:
default:
return Optional.empty();
}
return Optional.of(splitBasedOnAnalyses(way, newWays, newSelection, analysis, indexOfWayToKeep));
Expand Down
5 changes: 2 additions & 3 deletions src/org/openstreetmap/josm/data/APIDataSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.openstreetmap.josm.data.osm.Relation;
import org.openstreetmap.josm.data.osm.RelationMember;
import org.openstreetmap.josm.data.osm.Way;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.Utils;

/**
Expand Down Expand Up @@ -104,7 +103,7 @@ public final void init(Collection<OsmPrimitive> primitives) {
case ADD: toAdd.add(osm); break;
case UPDATE: toUpdate.add(osm); break;
case DELETE: toDelete.add(osm); break;
default: Logging.trace("Ignored primitive {0} -> {1}", osm, op);
// Used to have a default case for logging: Logging.trace("Ignored primitive {0} -> {1}", osm, op);
}
}
}
Expand Down Expand Up @@ -227,7 +226,7 @@ public void removeProcessed(Collection<IPrimitive> processed) {
/**
* Adjusts the upload order for new relations. Child relations are uploaded first,
* parent relations second.
*
* <p>
* This method detects cyclic dependencies in new relation. Relations with cyclic
* dependencies can't be uploaded.
*
Expand Down
1 change: 0 additions & 1 deletion src/org/openstreetmap/josm/data/Bounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ public Bounds(String asString, String separator, ParseMethod parseMethod, boolea
this.maxLon = initLon(values[2], roundToOsmPrecision);
break;
case MINLAT_MINLON_MAXLAT_MAXLON:
default:
this.minLat = initLat(values[0], roundToOsmPrecision);
this.minLon = initLon(values[1], roundToOsmPrecision);
this.maxLat = initLat(values[2], roundToOsmPrecision);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ public void loadingFinished(CacheEntry object, CacheEntryAttributes attributes,
break;
case CANCELED:
tile.loadingCanceled();
break;
default: // This should be removed when we move to Java 17+
// do nothing
}

Expand Down
3 changes: 2 additions & 1 deletion src/org/openstreetmap/josm/data/osm/SimplePrimitiveId.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ public static String toSimpleId(PrimitiveId primitive) {
case MULTIPOLYGON:
case RELATION:
return "r" + primitive.getUniqueId();
default:
throw new IllegalArgumentException("Unknown primitive type: " + primitive.getType());
}
throw new IllegalArgumentException("Unknown primitive type: " + primitive.getType());
}
}
3 changes: 1 addition & 2 deletions src/org/openstreetmap/josm/data/osm/pbf/Blob.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ public InputStream inputStream() throws IOException {
throw new IOException(this.compressionType + " pbf is not currently supported");
case zlib:
return new InflaterInputStream(bais);
default:
throw new IOException("unknown compression type is not currently supported: " + this.compressionType.name());
}
throw new IOException("unknown compression type is not currently supported: " + this.compressionType.name());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ public void initialize(ProjParameters params) throws ProjectionConfigurationExce
xmf = rq * dd;
ymf = rq / dd;
break;
default:
throw new AssertionError(mode);
}
}

Expand All @@ -132,7 +130,11 @@ public double[] project(final double phi, final double lambda) {
final double sinlam = Math.sin(lambda);
final double sinphi = Math.sin(phi);
double q = qsfn(sinphi);
final double sinb, cosb, b, c, x, y;
double sinb, cosb, b, c, x, y;
// Set c, x, y to 0 until we move to Java 17 where we can use a better switch expression.
c = 0;
x = 0;
y = 0;
switch (mode) {
case OBLIQUE:
sinb = q / qp;
Expand Down Expand Up @@ -172,8 +174,6 @@ public double[] project(final double phi, final double lambda) {
x = y = 0.;
}
break;
default:
throw new AssertionError(mode);
}
if (Math.abs(c) < EPSILON_LATITUDE) {
return new double[] {0, 0}; // this is an error, we should handle it somehow
Expand All @@ -191,9 +191,8 @@ public double[] invproject(double x, double y) {
return invprojectNS(x, -y);
case SOUTH_POLE:
return invprojectNS(x, y);
default:
throw new AssertionError(mode);
}
throw new AssertionError(mode);
}

private double[] invprojectEO(double x, double y) {
Expand Down
1 change: 1 addition & 0 deletions src/org/openstreetmap/josm/data/validation/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
*
* @author frsantos
*/
@SuppressWarnings("PMD.UnitTestShouldUseTestAnnotation")
public class Test implements OsmPrimitiveVisitor {

protected static final Predicate<OsmPrimitive> IN_DOWNLOADED_AREA = new NotOutsideDataSourceArea();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1867,8 +1867,6 @@ public static synchronized void updateTLDOverride(ArrayType table, String... tld
case INFRASTRUCTURE_RO:
case LOCAL_RO:
throw new IllegalArgumentException("Cannot update the table: " + table);
default:
throw new IllegalArgumentException("Unexpected enum value: " + table);
}
}

Expand All @@ -1880,7 +1878,7 @@ public static synchronized void updateTLDOverride(ArrayType table, String... tld
* @since 1.5.1
*/
public static String[] getTLDEntries(ArrayType table) {
final String[] array;
String[] array = null;
switch (table) {
case COUNTRY_CODE_MINUS:
array = countryCodeTLDsMinus;
Expand All @@ -1906,7 +1904,8 @@ public static String[] getTLDEntries(ArrayType table) {
case LOCAL_RO:
array = LOCAL_TLDS;
break;
default:
}
if (array == null) {
throw new IllegalArgumentException("Unexpected enum value: " + table);
}
return Arrays.copyOf(array, array.length); // clone the array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ protected void renderToolTipText(MultiValueResolutionDecision decision) {
toolTipText = tr("All values joined as ''{0}'' are going to be applied for key ''{1}''",
decision.getChosenValue(), decision.getKey());
break;
default:
throw new AssertionError("Unknown decision type in renderToolTipText(): " + decision.getDecisionType());
}
setToolTipText(toolTipText);
cbDecisionRenderer.setToolTipText(toolTipText);
Expand Down Expand Up @@ -170,7 +172,9 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
case 2:
renderValue(decision);
return cbDecisionRenderer;

default:
return this;
}
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ String getLabelText() {
case KEEP:
return tr("Keep");
case UNDECIDED:
default:
return tr("Undecided");
}
return tr("Undecided");
}

String getLabelToolTipText() {
Expand All @@ -42,8 +42,8 @@ String getLabelToolTipText() {
case KEEP:
return tr("Keep this relation member for the target object");
case UNDECIDED:
default:
return tr("Not decided yet");
}
return tr("Not decided yet");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ private static Component setColors(Component comp, JTable table, boolean isSelec
comp.setForeground(ConflictColors.FGCOLOR_MEMBER_REMOVE.get());
comp.setBackground(ConflictColors.BGCOLOR_MEMBER_REMOVE.get());
break;
default: throw new AssertionError("Unknown decision type: " + model.getDecision(row).getDecision());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

/**
* This model manages a list of conflicting relation members.
*
* <p>
* It can be used as {@link javax.swing.table.TableModel}.
*/
public class RelationMemberConflictResolverModel extends DefaultTableModel {
Expand Down Expand Up @@ -112,8 +112,8 @@ public Object getValueAt(int row, int column) {
case 3: /* original */ return d.getOriginalPrimitive();
case 4: /* decision keep */ return RelationMemberConflictDecisionType.KEEP == d.getDecision();
case 5: /* decision remove */ return RelationMemberConflictDecisionType.REMOVE == d.getDecision();
default: return null;
}
return null;
}

@Override
Expand Down Expand Up @@ -211,7 +211,7 @@ public void populate(Collection<RelationToChildReference> references) {

/**
* Prepare the default decisions for the current model.
*
* <p>
* Keep/delete decisions are made if every member has the same role and the members are in consecutive order within the relation.
* For multiple occurrences those conditions are tested stepwise for each occurrence.
*/
Expand All @@ -221,7 +221,7 @@ public void prepareDefaultRelationDecisions() {

/**
* Prepare the default decisions for the current model.
*
* <p>
* Keep/delete decisions are made if every member has the same role and the members are in consecutive order within the relation.
* For multiple occurrences those conditions are tested stepwise for each occurrence.
*
Expand Down Expand Up @@ -382,6 +382,7 @@ protected Command buildResolveCommand(Relation relation, OsmPrimitive newPrimiti
// do nothing
break;
case UNDECIDED:
default:
// FIXME: this is an error
break;
}
Expand Down Expand Up @@ -418,6 +419,7 @@ protected boolean isChanged(Relation relation, OsmPrimitive newPrimitive) {
return true;
break;
case UNDECIDED:
default:
// FIXME: handle error
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,9 @@ public void actionPerformed(ActionEvent evt) {
options,
options[1]
);
switch (ret) {
case JOptionPane.YES_OPTION:
if (ret == JOptionPane.YES_OPTION) {
buttonAction(1, evt);
break;
default:
} else {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected void renderModificationType(ChangesetModificationType type) {
case CREATED: setText(tr("Created")); break;
case UPDATED: setText(tr("Updated")); break;
case DELETED: setText(tr("Deleted")); break;
default: throw new IllegalStateException("Unexpected value: " + type);
}
setToolTipText(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ public int getRowCount() {

@Override
public Object getValueAt(int row, int col) {
switch (col) {
case 0: return data.get(row).getModificationType();
default: return data.get(row).getPrimitive();
if (col == 0) {
return data.get(row).getModificationType();
}
return data.get(row).getPrimitive();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ public void actionPerformed(ActionEvent arg0) {
pnlAdvancedQueries.displayMessageIfInvalid();
return;
}
default:
throw new IllegalStateException("Unexpected value: " + tpQueryPanels.getSelectedIndex());
}
setCanceled(false);
setVisible(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@ public Object getValueAt(int rowIndex, int columnIndex) {
return members.get(rowIndex).getMember();
case 2:
return getWayConnection(rowIndex);
default:
// should not happen
return null;
}
// should not happen
return null;
}

@Override
Expand Down
Loading

0 comments on commit eb61873

Please sign in to comment.