Skip to content

Commit

Permalink
Collapse catch statements with the same body in a multi-catch, add PM…
Browse files Browse the repository at this point in the history
…D rule to enforce it
  • Loading branch information
aaime committed Dec 28, 2020
1 parent b7e015e commit c02517b
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,7 @@ private void registerConverterDynamically(
} else if (instance instanceof SingleValueConverter) {
registerConverter((SingleValueConverter) instance, priority);
}
} catch (Exception e) {
throw new com.thoughtworks.xstream.InitializationException(
"Could not instantiate converter : " + className, e);
} catch (LinkageError e) {
} catch (Exception | LinkageError e) {
throw new com.thoughtworks.xstream.InitializationException(
"Could not instantiate converter : " + className, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ private void executeStoresConcurrently(int numberOfStores, int numberOfThreads)
FileBlobStore nStore =
new FileBlobStore(temp.getRoot().getAbsolutePath());
putLayerMetadataConcurrently(key, nStore, numberOfThreads);
} catch (InterruptedException eh) {
} catch (InterruptedException | StorageException eh) {
eh.printStackTrace();
} catch (StorageException e) {
e.printStackTrace();
} finally {
latch.countDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,7 @@ public void saveConfig(DiskQuotaConfig config) {
Assert.isTrue(diskQuotaEnabled, "called saveConfig but DiskQuota is disabled!");
try {
configLoader.saveConfig(config);
} catch (ConfigurationException e) {
throw new RuntimeException(e);
} catch (IOException e) {
} catch (ConfigurationException | IOException e) {
throw new RuntimeException(e);
}
if (config != quotaConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ public GeoRSSReader createReader(final Reader feed) throws IOException {
GeoRSSReader reader;
try {
reader = new StaxGeoRSSReader(feed);
} catch (XMLStreamException e) {
throw new IllegalStateException(e);
} catch (FactoryConfigurationError e) {
} catch (XMLStreamException | FactoryConfigurationError e) {
throw new IllegalStateException(e);
}
return reader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.opengis.geometry.MismatchedDimensionException;
import org.opengis.referencing.datum.PixelInCell;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.NoninvertibleTransformException;
import org.opengis.referencing.operation.TransformException;

/**
Expand Down Expand Up @@ -204,9 +205,7 @@ private Geometry transformToGridCrs(final Geometry geometryInLayerCrs, final int
Geometry geomInGridCrs;
try {
geomInGridCrs = JTS.transform(geometryInLayerCrs, worldToGrid);
} catch (MismatchedDimensionException e) {
throw new IllegalArgumentException(e);
} catch (TransformException e) {
} catch (MismatchedDimensionException | TransformException e) {
throw new IllegalArgumentException(e);
}

Expand Down Expand Up @@ -255,9 +254,7 @@ private MathTransform getWorldToGridTransform(
mapper.setSwapXY(false);
try {
worldToScreen = mapper.createTransform().inverse();
} catch (org.opengis.referencing.operation.NoninvertibleTransformException e) {
throw new IllegalArgumentException(e);
} catch (IllegalStateException e) {
} catch (NoninvertibleTransformException | IllegalStateException e) {
throw new IllegalArgumentException(e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.geowebcache.layer.TileLayerDispatcher;
import org.geowebcache.layer.TileLayerDispatcherMock;
import org.geowebcache.layer.wms.WMSLayer;
import org.geowebcache.service.ServiceException;
import org.geowebcache.storage.StorageBroker;
import org.springframework.mock.web.MockHttpServletRequest;

Expand Down Expand Up @@ -139,11 +138,7 @@ public void testConveyorCreation() {
assertEquals(
CQL_FILTER_PARAMETER_VALUE,
URLDecoder.decode(parameters.get(CQL_FILTER_PARAMETER_NAME), "UTF8"));
} catch (ServiceException e) {
fail();
} catch (GeoWebCacheException e) {
fail();
} catch (UnsupportedEncodingException e) {
} catch (UnsupportedEncodingException | GeoWebCacheException e) {
fail();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,7 @@ protected static long[] parseGridLocString(String key) throws ServiceException {
ret[0] = Long.parseLong(key.substring(1, yloc));
ret[1] = Long.parseLong(key.substring(yloc + 1, zloc));
ret[2] = Long.parseLong(key.substring(zloc + 1, key.length()));
} catch (NumberFormatException nfe) {
throw new ServiceException("Unable to parse " + key);
} catch (StringIndexOutOfBoundsException sobe) {
} catch (NumberFormatException | StringIndexOutOfBoundsException nfe) {
throw new ServiceException("Unable to parse " + key);
}
return ret;
Expand Down
2 changes: 1 addition & 1 deletion geowebcache/pmd-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ under the License.
<rule ref="category/java/codestyle.xml/UselessQualifiedThis" />
<rule ref="category/java/codestyle.xml/UnnecessaryCast" />
<rule ref="category/java/codestyle.xml/UseDiamondOperator" />

<rule ref="category/java/codestyle.xml/IdenticalCatchBranches" />

<!-- rule ref="category/java/design.xml/CollapsibleIfStatements" / -->
<!-- rule ref="category/java/design.xml/SimplifiedTernary" / -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ public ResponseEntity<?> doPost(HttpServletRequest req) throws IOException {
}
} catch (IllegalArgumentException e) {
throw new RestException(e.getMessage(), HttpStatus.BAD_REQUEST);
} catch (StorageException e) {
throw new RestException(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
} catch (GeoWebCacheException e) {
} catch (StorageException | GeoWebCacheException e) {
throw new RestException(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
return mtr.getResponse(contentType);
Expand All @@ -157,9 +155,7 @@ protected void handleRequest(HttpServletRequest req, HttpServletResponse resp, O
}
} catch (IllegalArgumentException e) {
throw new RestException(e.getMessage(), HttpStatus.BAD_REQUEST);
} catch (StorageException e) {
throw new RestException(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
} catch (GeoWebCacheException e) {
} catch (StorageException | GeoWebCacheException e) {
throw new RestException(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Expand Down

0 comments on commit c02517b

Please sign in to comment.