Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove catch Throwable to expose Error #3196

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ public void printClientConfig(final JSONWriter json, final Template template)
json.endArray();
json.endObject();

} catch (Throwable e) {
} catch (RuntimeException e) {
// Note: If this test fails and you just added a new attribute, make
// sure to set defaults in AbstractMapfishSpringTest.configureAttributeForTesting
throw new Error(
throw new RuntimeException(
"Error printing the clientConfig of: " + DataSourceAttribute.class.getName(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,11 @@ public final void printClientConfig(final JSONWriter json, final Template templa

Optional<JSONObject> clientOptions = getClientInfo();
clientOptions.ifPresent(jsonObject -> json.key(JSON_CLIENT_INFO).value(jsonObject));
} catch (Throwable e) {
} catch (RuntimeException | IllegalAccessException e) {
// Note: If this test fails and you just added a new attribute, make
// sure to set defaults in AbstractMapfishSpringTest.configureAttributeForTesting
throw new Error("Error printing the clientConfig of: " + getValueType().getName(), e);
throw new RuntimeException(
"Error printing the clientConfig of: " + getValueType().getName(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mapfish.print.attribute.map;

import java.awt.Dimension;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -12,7 +13,7 @@
import org.json.JSONException;
import org.json.JSONObject;
import org.mapfish.print.Constants;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.PrintException;
import org.mapfish.print.attribute.ReflectiveAttribute;
import org.mapfish.print.config.Configuration;
import org.mapfish.print.config.ConfigurationException;
Expand Down Expand Up @@ -82,9 +83,9 @@ public static CoordinateReferenceSystem parseProjection(
return CRS.decode(projection, longitudeFirst);
}
} catch (NoSuchAuthorityCodeException e) {
throw new RuntimeException(projection + " was not recognized as a crs code", e);
throw new PrintException(projection + " was not recognized as a crs code", e);
} catch (FactoryException e) {
throw new RuntimeException("Error occurred while parsing: " + projection, e);
throw new PrintException("Error occurred while parsing: " + projection, e);
}
}

Expand Down Expand Up @@ -437,14 +438,14 @@ private List<MapLayer> parseLayers() {
List<MapLayer> layerList = new ArrayList<>();

for (int i = 0; i < this.getRawLayers().size(); i++) {
try {
PObject layer = this.getRawLayers().getObject(i);
// only render if the opacity is greater than 0
if (Math.abs(layer.optDouble("opacity", 1.0)) > Constants.OPACITY_PRECISION) {
PObject layer = this.getRawLayers().getObject(i);
// only render if the opacity is greater than 0
if (Math.abs(layer.optDouble("opacity", 1.0)) > Constants.OPACITY_PRECISION) {
try {
parseSingleLayer(layerList, layer);
} catch (IOException e) {
throw new PrintException("Failed to parse layer : " + layer, e);
}
} catch (Throwable throwable) {
throw ExceptionUtils.getRuntimeException(throwable);
}
}

Expand All @@ -453,8 +454,7 @@ private List<MapLayer> parseLayers() {

@SuppressWarnings("unchecked")
private void parseSingleLayer(final List<MapLayer> layerList, final PObject layer)
throws Throwable {

throws IOException {
final Map<String, MapLayerFactoryPlugin> layerParsers =
GenericMapAttribute.this.applicationContext.getBeansOfType(MapLayerFactoryPlugin.class);
for (MapLayerFactoryPlugin layerParser : layerParsers.values()) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/mapfish/print/config/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public final void validate(final List<Throwable> validationErrors, final Configu

try {
getProcessorGraph();
} catch (Throwable t) {
} catch (RuntimeException t) {
validationErrors.add(t);
}

Expand Down
17 changes: 14 additions & 3 deletions core/src/main/java/org/mapfish/print/http/CertificateStore.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package org.mapfish.print.http;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URI;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.List;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.PrintException;
import org.mapfish.print.config.Configuration;
import org.mapfish.print.config.ConfigurationObject;
import org.mapfish.print.config.HasConfiguration;
Expand Down Expand Up @@ -89,8 +95,13 @@ private SSLContext createSslContext() {
newSslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

return newSslContext;
} catch (Throwable t) {
throw ExceptionUtils.getRuntimeException(t);
} catch (NoSuchAlgorithmException
| KeyStoreException
| UnrecoverableKeyException
| CertificateException
| IOException
| KeyManagementException t) {
throw new PrintException("Failed to create SSL Context", t);
}
}

Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/org/mapfish/print/map/CustomEPSGCodes.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.mapfish.print.map;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.geotools.referencing.factory.epsg.FactoryUsingWKT;
import org.geotools.util.factory.Hints;
import org.mapfish.print.PrintException;

/** This class is an authority factory that allows defining custom EPSG codes. */
public final class CustomEPSGCodes extends FactoryUsingWKT {
Expand Down Expand Up @@ -39,8 +41,8 @@ protected URL getDefinitionsURL() {
stream.read();
}
return url;
} catch (Throwable e) {
throw new AssertionError("Unable to load /epsg.properties file from root of classpath.");
} catch (NullPointerException | IOException e) {
throw new PrintException("Unable to load /epsg.properties file from root of classpath.", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collections;
import java.util.Set;
Expand All @@ -13,8 +14,8 @@
import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
import org.geotools.gce.geotiff.GeoTiffFormat;
import org.mapfish.print.Constants;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.FileUtils;
import org.mapfish.print.PrintException;
import org.mapfish.print.config.Template;
import org.mapfish.print.http.MfClientHttpRequestFactory;
import org.mapfish.print.map.AbstractLayerParams;
Expand Down Expand Up @@ -106,8 +107,8 @@ private Function<MfClientHttpRequestFactory, AbstractGridCoverage2DReader> getGe
}

return new GeoTiffFormat().getReader(geotiffFile);
} catch (Throwable t) {
throw ExceptionUtils.getRuntimeException(t);
} catch (IOException | URISyntaxException e) {
throw new PrintException("Failed to get GeotiffReader", e);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.map.GridCoverageLayer;
import org.geotools.map.Layer;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.PrintException;
import org.mapfish.print.StatsUtils;
import org.mapfish.print.attribute.map.MapBounds;
import org.mapfish.print.attribute.map.MapfishMapContext;
Expand Down Expand Up @@ -83,8 +83,10 @@ protected final List<? extends Layer> getLayers(
BufferedImage image;
try {
image = loadImage(httpRequestFactory, mapContext);
} catch (Throwable t) {
throw ExceptionUtils.getRuntimeException(t);
} catch (RuntimeException t) {
throw t;
} catch (Exception t) {
throw new PrintException("Failed to LoadImage", t);
}

final MapBounds bounds = mapContext.getBounds();
Expand Down Expand Up @@ -215,7 +217,7 @@ protected BufferedImage fetchImage(
}
timerDownload.stop();
return image;
} catch (Throwable e) {
} catch (RuntimeException e) {
this.registry.counter(baseMetricName + ".error").inc();
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.annotation.Nullable;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.geotools.api.style.Style;
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.styling.DefaultResourceLocator;
Expand Down Expand Up @@ -125,7 +126,7 @@ public URL locateResource(final String uri) {
sldParser.setInput(new ByteArrayInputStream(bytes));
styles = sldParser.readXML();

} catch (Throwable e) {
} catch (ParserConfigurationException | SAXException | IOException e) {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.geotools.styling.StyleBuilder;
import org.json.JSONObject;
import org.mapfish.print.Constants;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.config.Configuration;
import org.mapfish.print.map.style.ParserPluginUtils;
import org.mapfish.print.map.style.SLDParserPlugin;
Expand Down Expand Up @@ -454,14 +453,10 @@ public Optional<Style> parseStyle(
clientHttpRequestFactory,
styleString,
(final byte[] input) -> {
try {
return tryParse(
configuration,
new String(input, Constants.DEFAULT_CHARSET),
clientHttpRequestFactory);
} catch (Throwable e) {
throw ExceptionUtils.getRuntimeException(e);
}
return tryParse(
configuration,
new String(input, Constants.DEFAULT_CHARSET),
clientHttpRequestFactory);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import net.sf.jasperreports.repo.RepositoryService;
import org.locationtech.jts.util.AssertionFailedException;
import org.mapfish.print.Constants;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.PrintException;
import org.mapfish.print.attribute.map.MapAttribute;
import org.mapfish.print.config.Configuration;
import org.mapfish.print.config.Template;
Expand Down Expand Up @@ -295,8 +295,12 @@ private void checkRequiredFields(
}
}
source.moveFirst();
} catch (Throwable e) {
throw ExceptionUtils.getRuntimeException(e);
} catch (JRException
| ParserConfigurationException
| IOException
| ClassNotFoundException
| SAXException e) {
throw new PrintException("Checking required fields failed", e);
}

StringBuilder finalError = new StringBuilder();
Expand Down Expand Up @@ -329,8 +333,8 @@ private void checkRequiredValues(
}
}
}
} catch (Throwable e) {
throw ExceptionUtils.getRuntimeException(e);
} catch (ParserConfigurationException | IOException | SAXException | ClassNotFoundException e) {
throw new PrintException("Checking required values failed", e);
}

StringBuilder finalError = new StringBuilder();
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/mapfish/print/output/Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void populateFromAttributes(
attribute.getValue().getValue(template, attribute.getKey(), requestJsonAttributes));
} catch (ObjectMissingException | IllegalArgumentException e) {
throw e;
} catch (Throwable e) {
} catch (RuntimeException e) {
String templateName = "unknown";
for (Map.Entry<String, Template> entry :
template.getConfiguration().getTemplates().entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -154,16 +155,7 @@ public Void execute(final In in, final ExecutionContext context) {
value = convertKeywords(value);
}
writeMethodParameter.getMethod().invoke(in.pdfConfig, value);
} catch (Throwable e) {
if (writeMethodParameter == null) {
throw new RuntimeException(
"An error occurred while executing !updatePdfConfig. Unable to set "
+ "configuration property '"
+ entry.getKey()
+ " with value "
+ value
+ ". ");
}
} catch (IllegalAccessException | InvocationTargetException | RuntimeException e) {
throw new RuntimeException(
"An error occurred while executing !updatePdfConfig. Unable to set configuration "
+ "property '"
Expand All @@ -173,7 +165,8 @@ public Void execute(final In in, final ExecutionContext context) {
+ ". The expected type is "
+ writeMethodParameter.getParameterType()
+ " but the type of the value being set was: "
+ (value != null ? value.getClass() : "null"));
+ (value != null ? value.getClass() : "null"),
e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protected Values compute() {
LOGGER.debug("Starting to execute processor graph: \n{}", graph);
try {
tryExecuteNodes(graph.roots, this.execContext, false);
} catch (Throwable ex) {
} catch (RuntimeException ex) {
this.execContext.cancel(); // cancel all pending computations in case of error
throw ex;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -84,7 +85,7 @@ public BufferedImage resolve(final MfClientHttpRequestFactory requestFactory, fi
response.getStatusCode(),
response.getStatusText());
}
} catch (Throwable e) {
} catch (RuntimeException | URISyntaxException | IOException e) {
LOGGER.warn("Error loading table row image: {}", uriString, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ protected void extraValidation(
checkStyleExists(validationErrors, stylesMap, this.firstHeaderStyle);
checkStyleExists(validationErrors, stylesMap, this.headerStyle);
checkStyleExists(validationErrors, stylesMap, this.lastHeaderStyle);
} catch (Throwable e) {
} catch (RuntimeException | IOException | JRException e) {
validationErrors.add(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public final synchronized MapPrinter create(@Nullable final String app)
printer.setConfiguration(configFile, bytes);

this.printers.put(finalApp, printer);
} catch (Throwable e) {
} catch (RuntimeException | IOException e) {
LOGGER.error(
"Error occurred while reading configuration file '{}', '{}'",
configFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ public void run() {
}
} catch (javax.persistence.PessimisticLockException e) {
// Ignore error on pessimistic locking
} catch (Throwable t) {
} catch (RuntimeException t) {
LOGGER.error("Error while polling/updating registry", t);
}
}
Expand Down
Loading