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 mechanism to hide Exception tree #3200

Merged
merged 1 commit into from
Feb 14, 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
18 changes: 0 additions & 18 deletions core/src/main/java/org/mapfish/print/ExceptionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,6 @@ public final class ExceptionUtils {

private ExceptionUtils() {}

/**
* Returns a {@link RuntimeException} for the given exception.
*
* @param exc An exception.
* @return A {@link RuntimeException}
*/
public static RuntimeException getRuntimeException(final Throwable exc) {
Throwable e = exc;
while (e.getCause() instanceof RuntimeException) {
e = e.getCause();
}
if (e instanceof RuntimeException) {
return (RuntimeException) e;
} else {
return new RuntimeException(exc);
}
}

/**
* Because exceptions might get re-thrown several times, an error message like
* "java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException:
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/mapfish/print/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static URL testForLegalFileUrl(final Configuration configuration, final U
}
}
} catch (MalformedURLException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Malformed URL", e);
}
}
return url;
Expand Down
25 changes: 18 additions & 7 deletions core/src/main/java/org/mapfish/print/URIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static Multimap<String, String> getParameters(final String rawQuery) {
key = URLDecoder.decode(pair.substring(0, pos), "UTF-8");
value = URLDecoder.decode(pair.substring(pos + 1), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to get parameters for query " + rawQuery, e);
}
}

Expand Down Expand Up @@ -135,7 +135,7 @@ public static URI addParams(
try {
return new URI(result.toString());
} catch (URISyntaxException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to create URI for " + result, e);
}
}

Expand All @@ -154,15 +154,26 @@ private static boolean addParams(
}
try {
result.append(URLEncoder.encode(key, Constants.DEFAULT_ENCODING));
result.append("=");
} catch (UnsupportedEncodingException e) {
throw createPrintException(key, e);
}
result.append("=");
try {
result.append(URLEncoder.encode(val, Constants.DEFAULT_ENCODING));
} catch (UnsupportedEncodingException e) {
throw ExceptionUtils.getRuntimeException(e);
throw createPrintException(val, e);
}
}
return first;
}

private static PrintException createPrintException(
final String toEncode, final UnsupportedEncodingException e) {
String message =
String.format("Failed to encode %s using %s", toEncode, Constants.DEFAULT_ENCODING);
return new PrintException(message, e);
}

/**
* Add a parameter to the query params (the params map) replacing any parameter that might be
* there.
Expand Down Expand Up @@ -227,7 +238,7 @@ public static URI setQueryParams(
initialUri.getFragment());
}
} catch (URISyntaxException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to set query parameters", e);
}
}

Expand Down Expand Up @@ -258,7 +269,7 @@ public static String toString(final MfClientHttpRequestFactory requestFactory, f
try {
return toString(requestFactory, url.toURI());
} catch (URISyntaxException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Incorrect syntax for " + url, e);
}
}

Expand Down Expand Up @@ -292,7 +303,7 @@ public static URI setPath(final URI initialUri, final String path) {
initialUri.getFragment());
}
} catch (URISyntaxException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to set path " + path, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.json.JSONWriter;
import org.locationtech.jts.util.Assert;
import org.locationtech.jts.util.AssertionFailedException;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.PrintException;
import org.mapfish.print.config.Template;
import org.mapfish.print.parser.HasDefaultValue;
import org.mapfish.print.parser.MapfishParser;
Expand Down Expand Up @@ -343,7 +343,7 @@ private void encodeAttributeValue(
try {
value = typeOrComponentType.getDeclaredConstructor().newInstance();
} catch (InvocationTargetException | NoSuchMethodException | InstantiationException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to encode Attribute for " + typeOrComponentType, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.GeodeticCalculator;
import org.locationtech.jts.geom.Coordinate;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.FloatingPointUtil;
import org.mapfish.print.PrintException;
import org.mapfish.print.map.DistanceUnit;
import org.mapfish.print.map.Scale;

Expand Down Expand Up @@ -175,7 +175,7 @@ private ReferencedEnvelope computeGeodeticBBox(
rollLatitude(maxGeoY),
crs);
} catch (TransformException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to compute geodetic bbox", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.geotools.map.MapContent;
import org.geotools.renderer.lite.StreamingRenderer;
import org.locationtech.jts.util.Assert;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.FloatingPointUtil;
import org.mapfish.print.PrintException;
import org.mapfish.print.attribute.map.MapLayer;
import org.mapfish.print.attribute.map.MapfishMapContext;
import org.mapfish.print.http.HttpRequestFetcher;
Expand Down Expand Up @@ -133,8 +133,10 @@ public final void render(
layerTransformer.getBounds().toReferencedEnvelope(paintArea);
renderer.paint(graphics2D, paintArea, mapArea);
graphics2D.setTransform(originalTransform);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to render.", e);
} finally {
content.dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.geotools.api.data.FeatureSource;
import org.geotools.data.collection.CollectionFeatureSource;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.PrintException;
import org.mapfish.print.attribute.map.MapfishMapContext;
import org.mapfish.print.config.Template;
import org.mapfish.print.http.MfClientHttpRequestFactory;
Expand Down Expand Up @@ -87,7 +87,7 @@ public FeatureSource load(
featureCollection = parser.autoTreat(template, geoJsonString);
return new CollectionFeatureSource(featureCollection);
} catch (IOException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to load " + mapContext, e);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import org.geotools.gml2.GMLConfiguration;
import org.geotools.xsd.Configuration;
import org.geotools.xsd.Parser;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.FileUtils;
import org.mapfish.print.PrintException;
import org.mapfish.print.URIUtils;
import org.mapfish.print.attribute.map.MapfishMapContext;
import org.mapfish.print.config.Template;
Expand Down Expand Up @@ -98,7 +98,7 @@ public FeatureSource load(
try {
featureCollection = createFeatureSource(template, requestFactory, url);
} catch (IOException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to create feature source for " + url, e);
}
if (featureCollection == null) {
throw new IllegalArgumentException(url + " does not reference a GML file");
Expand Down Expand Up @@ -126,7 +126,7 @@ private SimpleFeatureCollection createFeatureSource(
return parseGml3(gmlData);
}
} catch (URISyntaxException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to create URI for " + url, e);
}
} catch (MalformedURLException e) {
return null;
Expand Down Expand Up @@ -177,7 +177,7 @@ private SimpleFeatureCollection parseGml32(final String gmlData) throws IOExcept
}

} catch (SAXException | ParserConfigurationException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to parse Gml32 " + gmlData, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateSequence;
import org.locationtech.jts.geom.Envelope;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.PrintException;

/** The LinearCoordinateSequence class. */
public final class LinearCoordinateSequence implements CoordinateSequence, Cloneable {
Expand Down Expand Up @@ -210,7 +210,7 @@ public CoordinateSequence copy() {
clone.spacing = this.spacing;
return clone;
} catch (CloneNotSupportedException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to create a copy", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
import org.geotools.filter.text.cql2.CQLException;
import org.geotools.filter.text.ecql.ECQL;
import org.geotools.styling.StyleBuilder;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.FontTools;
import org.mapfish.print.PrintException;
import org.mapfish.print.SetsUtils;
import org.mapfish.print.config.Configuration;
import org.mapfish.print.map.DistanceUnit;
Expand Down Expand Up @@ -286,8 +286,7 @@ private String validateURL(final String externalGraphicUrl) {
final URL fileURL = new URL("file://" + externalGraphicUrl);
return testForLegalFileUrl(this.configuration, fileURL).toExternalForm();
} catch (MalformedURLException e1) {
// unable to convert to file url so give up and throw exception;
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Unable to convert to file URL " + externalGraphicUrl, e);
}
}
return externalGraphicUrl;
Expand Down Expand Up @@ -868,7 +867,8 @@ private Expression toExpressionFromCQl(final String property) {
try {
return ECQL.toExpression(property, this.styleBuilder.getFilterFactory());
} catch (CQLException e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException(
"Failed to convert from CQL to expression, the property " + property, e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import org.geotools.filter.text.cql2.CQLException;
import org.geotools.filter.text.ecql.ECQL;
import org.geotools.styling.StyleBuilder;
import org.json.JSONException;
import org.json.JSONObject;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.config.Configuration;
import org.mapfish.print.wrapper.json.PJsonArray;
import org.mapfish.print.wrapper.json.PJsonObject;
Expand Down Expand Up @@ -162,11 +160,7 @@ private void updateSymbolizerProperties(
final PJsonObject ruleJson, final PJsonObject symbolizerJson) {
Map<String, String> values = buildValuesMap(ruleJson, symbolizerJson);
for (Map.Entry<String, String> entry : values.entrySet()) {
try {
symbolizerJson.getInternalObj().put(entry.getKey(), entry.getValue());
} catch (JSONException e) {
throw ExceptionUtils.getRuntimeException(e);
}
symbolizerJson.getInternalObj().put(entry.getKey(), entry.getValue());
}
}

Expand Down
10 changes: 6 additions & 4 deletions core/src/main/java/org/mapfish/print/map/tiled/CoverageTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.Callable;
import java.util.concurrent.RecursiveTask;
Expand All @@ -16,7 +18,7 @@
import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.coverage.grid.GridCoverageFactory;
import org.geotools.geometry.GeneralBounds;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.PrintException;
import org.mapfish.print.StatsUtils;
import org.mapfish.print.config.Configuration;
import org.mapfish.print.map.style.json.ColorParser;
Expand Down Expand Up @@ -147,8 +149,8 @@ public GridCoverage2D call() {
this.tilePreparationInfo.getGridCoverageMaxY());
return factory.create(
this.tiledLayer.createCommonUrl(), coverageImage, gridEnvelope, null, null, null);
} catch (Exception e) {
throw ExceptionUtils.getRuntimeException(e);
} catch (URISyntaxException | UnsupportedEncodingException e) {
throw new PrintException("Failed to call the coverage task", e);
}
}

Expand Down Expand Up @@ -276,7 +278,7 @@ protected Tile compute() {
return new Tile(image, getTileIndexX(), getTileIndexY());
} catch (IOException e) {
this.registry.counter(baseMetricName + ".error").inc();
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to compute Coverage Task", e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.mapfish.print.ExceptionUtils;
import org.mapfish.print.FloatingPointUtil;
import org.mapfish.print.PrintException;
import org.mapfish.print.attribute.map.MapBounds;
import org.mapfish.print.attribute.map.MapfishMapContext;
import org.mapfish.print.http.HttpRequestFetcher;
Expand Down Expand Up @@ -197,8 +197,10 @@ public TilePreparationInfo call() {
gridCoverageMaxX,
gridCoverageMaxY,
mapProjection);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw ExceptionUtils.getRuntimeException(e);
throw new PrintException("Failed to call Tile preparation task", e);
}
});
}
Expand Down
Loading