sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Keep trace of path by which an ArithmeticException may occur.
Date Wed, 07 Nov 2018 18:26:56 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new fd62385  Keep trace of path by which an ArithmeticException may occur.
fd62385 is described below

commit fd6238538e412ebcc5d3f5b9bfc8642f412c883f
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Nov 7 19:26:31 2018 +0100

    Keep trace of path by which an ArithmeticException may occur.
---
 .../src/main/java/org/apache/sis/internal/netcdf/Axis.java     |  1 +
 .../main/java/org/apache/sis/internal/netcdf/GridGeometry.java |  2 ++
 .../src/main/java/org/apache/sis/internal/netcdf/Variable.java |  2 ++
 .../org/apache/sis/internal/netcdf/impl/ChannelDecoder.java    | 10 +++++-----
 .../java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java |  4 ++++
 .../org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java  |  3 +++
 .../java/org/apache/sis/internal/netcdf/impl/VariableInfo.java |  7 +++++++
 .../apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java   |  1 +
 .../java/org/apache/sis/storage/netcdf/MetadataReader.java     |  2 ++
 .../main/java/org/apache/sis/storage/netcdf/NetcdfStore.java   |  2 +-
 .../main/java/org/apache/sis/internal/storage/io/Region.java   |  2 ++
 11 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
index b070054..8d41055 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
@@ -78,6 +78,7 @@ public final class Axis {
      * @param  sourceSizes       the number of cell elements along that axis.
      * @throws IOException if an I/O operation was necessary but failed.
      * @throws DataStoreException if a logical error occurred.
+     * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE},
or other overflow occurs.
      */
     public Axis(final GridGeometry owner, final Object axis, final AttributeNames.Dimension
attributeNames,
             final int[] sourceDimensions, final int[] sourceSizes) throws IOException, DataStoreException
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java
index 4e01b20..9137f3d 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java
@@ -65,6 +65,7 @@ public abstract class GridGeometry {
      * @return the CRS axes, in netCDF order (reverse of "natural" order).
      * @throws IOException if an I/O operation was necessary but failed.
      * @throws DataStoreException if a logical error occurred.
+     * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE},
or other overflow occurs.
      */
     public abstract Axis[] getAxes() throws IOException, DataStoreException;
 
@@ -80,6 +81,7 @@ public abstract class GridGeometry {
      * @return the coordinate at the given index, or {@link Double#NaN} if it can not be
computed.
      * @throws IOException if an I/O operation was necessary but failed.
      * @throws DataStoreException if a logical error occurred.
+     * @throws ArithmeticException if the axis size exceeds {@link Integer#MAX_VALUE}, or
other overflow occurs.
      */
     protected abstract double coordinateForAxis(Object axis, int j, int i) throws IOException,
DataStoreException;
 }
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
index 3e4f952..bbccb00 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
@@ -209,6 +209,7 @@ public abstract class Variable extends NamedElement {
      * @return the data as an array of a Java primitive type.
      * @throws IOException if an error occurred while reading the data.
      * @throws DataStoreException if a logical error occurred.
+     * @throws ArithmeticException if the size of the variable exceeds {@link Integer#MAX_VALUE},
or other overflow occurs.
      */
     public abstract Vector read() throws IOException, DataStoreException;
 
@@ -231,6 +232,7 @@ public abstract class Variable extends NamedElement {
      * @return the data as an array of a Java primitive type.
      * @throws IOException if an error occurred while reading the data.
      * @throws DataStoreException if a logical error occurred.
+     * @throws ArithmeticException if the size of the region to read exceeds {@link Integer#MAX_VALUE},
or other overflow occurs.
      */
     public abstract Vector read(int[] areaLower, int[] areaUpper, int[] subsampling) throws
IOException, DataStoreException;
 
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
index b52f92e..f2b3e1c 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
@@ -537,10 +537,10 @@ public final class ChannelDecoder extends Decoder {
      *
      * @param  nelems         the number of variables to read.
      * @param  allDimensions  the dimensions previously read by {@link #readDimensions(int)}.
+     * @throws DataStoreContentException if a logical error is detected.
+     * @throws ArithmeticException if a variable is too large.
      */
-    private VariableInfo[] readVariables(final int nelems, final Dimension[] allDimensions)
-            throws IOException, DataStoreException
-    {
+    private VariableInfo[] readVariables(final int nelems, final Dimension[] allDimensions)
throws IOException, DataStoreException {
         if (allDimensions == null) {
             throw malformedHeader();        // May happen if readDimensions(…) has not
been invoked.
         }
@@ -789,8 +789,8 @@ public final class ChannelDecoder extends Decoder {
     public DiscreteSampling[] getDiscreteSampling() throws IOException, DataStoreException
{
         if ("trajectory".equalsIgnoreCase(stringValue(CF.FEATURE_TYPE))) try {
             return FeaturesInfo.create(this);
-        } catch (IllegalArgumentException e) {
-            // Not a problem with content, but rather with configuration.
+        } catch (IllegalArgumentException | ArithmeticException e) {
+            // Illegal argument is not a problem with content, but rather with configuration.
             throw new DataStoreException(e.getLocalizedMessage(), e);
         }
         return new FeaturesInfo[0];
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
index d3b9fa2..764afe6 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
@@ -172,6 +172,7 @@ final class FeaturesInfo extends DiscreteSampling {
      * Creates new discrete sampling parsers from the attribute values found in the given
decoder.
      *
      * @throws IllegalArgumentException if the geometric object library is not available.
+     * @throws ArithmeticException if the size of a variable exceeds {@link Integer#MAX_VALUE},
or other overflow occurs.
      */
     static FeaturesInfo[] create(final ChannelDecoder decoder) throws IOException, DataStoreException
{
         final List<FeaturesInfo> features = new ArrayList<>(3);     // Will usually
contain at most one element.
@@ -334,6 +335,9 @@ search: for (final VariableInfo counts : decoder.variables) {
         /**
          * Executes the given action only on the next feature, if any.
          *
+         * @throws ArithmeticException if the size of a variable exceeds {@link Integer#MAX_VALUE},
or other overflow occurs.
+         * @throws BackingStoreException if an {@link IOException} or {@link DataStoreException}
occurred.
+         *
          * @todo current reading process implies lot of seeks, which is inefficient.
          */
         @Override
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
index 494e356..6ecbdb8 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
@@ -122,6 +122,7 @@ final class GridGeometryInfo extends GridGeometry {
      * @return the CRS axes, in netCDF order (reverse of "natural" order).
      * @throws IOException if an I/O operation was necessary but failed.
      * @throws DataStoreException if a logical error occurred.
+     * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE},
or other overflow occurs.
      */
     @Override
     public Axis[] getAxes() throws IOException, DataStoreException {
@@ -187,6 +188,8 @@ final class GridGeometryInfo extends GridGeometry {
     /**
      * Returns a coordinate for the given two-dimensional grid coordinate axis.
      * This is (indirectly) a callback method for {@link #getAxes()}.
+     *
+     * @throws ArithmeticException if the axis size exceeds {@link Integer#MAX_VALUE}, or
other overflow occurs.
      */
     @Override
     protected double coordinateForAxis(final Object axis, final int j, final int i) throws
IOException, DataStoreException {
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
index 19b429b..8bdadf9 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
@@ -179,6 +179,8 @@ final class VariableInfo extends Variable implements Comparable<VariableInfo>
{
      * @param  size        the variable size. May be inaccurate and ignored.
      * @param  offset      the offset where the variable data begins in the netCDF file.
      * @param  listeners   where to report warnings, if any.
+     * @throws ArithmeticException if the variable size exceeds {@link Long#MAX_VALUE}.
+     * @throws DataStoreContentException if a logical error is detected.
      */
     VariableInfo(final ChannelDataInput      input,
                  final String                name,
@@ -289,6 +291,8 @@ final class VariableInfo extends Variable implements Comparable<VariableInfo>
{
      *
      * <p>After padding has been applied, this method set the {@link #offsetToNextRecord}
of all unlimited
      * variables to the number of bytes to skip before reading the next record.</p>
+     *
+     * @throws ArithmeticException if the stride between two records exceeds {@link Long#MAX_VALUE}.
      */
     static void complete(final VariableInfo[] variables) {
         final VariableInfo[] unlimited = new VariableInfo[variables.length];
@@ -531,6 +535,8 @@ final class VariableInfo extends Variable implements Comparable<VariableInfo>
{
      * Reads all the data for this variable and returns them as an array of a Java primitive
type.
      * Multi-dimensional variables are flattened as a one-dimensional array (wrapped in a
vector).
      * The vector is cached and returned as-is in all future invocation of this method.
+     *
+     * @throws ArithmeticException if the size of the variable exceeds {@link Integer#MAX_VALUE},
or other overflow occurs.
      */
     @Override
     @SuppressWarnings("ReturnOfCollectionOrArrayField")
@@ -580,6 +586,7 @@ final class VariableInfo extends Variable implements Comparable<VariableInfo>
{
      * @param  areaUpper    index after the last value to read along each dimension, as unsigned
integers.
      * @param  subsampling  sub-sampling along each dimension. 1 means no sub-sampling.
      * @return the data as an array of a Java primitive type.
+     * @throws ArithmeticException if the size of the region to read exceeds {@link Integer#MAX_VALUE},
or other overflow occurs.
      */
     @Override
     public Vector read(int[] areaLower, int[] areaUpper, int[] subsampling) throws IOException,
DataStoreContentException {
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java
index 6a145c9..9f2336c 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java
@@ -91,6 +91,7 @@ final class GridGeometryWrapper extends GridGeometry {
      * @return the CRS axes, in netCDF order (reverse of "natural" order).
      * @throws IOException if an I/O operation was necessary but failed.
      * @throws DataStoreException if a logical error occurred.
+     * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE},
or other overflow occurs.
      */
     @Override
     public Axis[] getAxes() throws IOException, DataStoreException {
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
index eb5a298..d43677f 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
@@ -698,6 +698,7 @@ split:  while ((start = CharSequences.skipLeadingWhitespaces(value, start,
lengt
      * This is the {@code <mdb:spatialRepresentationInfo>} element in XML.
      *
      * @param  cs  the grid geometry (related to the netCDF coordinate system).
+     * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE},
or other overflow occurs.
      */
     private void addSpatialRepresentationInfo(final GridGeometry cs) throws IOException,
DataStoreException {
         final Axis[] axes = cs.getAxes();
@@ -1014,6 +1015,7 @@ split:  while ((start = CharSequences.skipLeadingWhitespaces(value,
start, lengt
      * @return the ISO metadata object.
      * @throws IOException if an I/O operation was necessary but failed.
      * @throws DataStoreException if a logical error occurred.
+     * @throws ArithmeticException if the size of an axis exceeds {@link Integer#MAX_VALUE},
or other overflow occurs.
      */
     public Metadata read() throws IOException, DataStoreException {
         addResourceScope(ScopeCode.DATASET, null);
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
index 9af51ca..8176dca 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
@@ -181,7 +181,7 @@ public class NetcdfStore extends DataStore implements Aggregate {
             if (metadata instanceof ModifiableMetadata) {
                 ((ModifiableMetadata) metadata).transition(ModifiableMetadata.State.FINAL);
             }
-        } catch (IOException e) {
+        } catch (IOException | ArithmeticException e) {
             throw new DataStoreException(e);
         }
         return metadata;
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/Region.java
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/Region.java
index aba124d..a6e5bd5 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/Region.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/Region.java
@@ -81,6 +81,8 @@ public final class Region {
      * @param regionLower   index of the first value to read or write along each dimension.
      * @param regionUpper   index after the last value to read or write along each dimension.
      * @param subsamplings  sub-sampling along each dimension. Shall be greater than zero.
+     * @throws ArithmeticException if the size of the region to read exceeds {@link Integer#MAX_VALUE},
+     *                             or the total hyper-cube size exceeds {@link Long#MAX_VALUE}.
      */
     public Region(final long[] size, final long[] regionLower, final long[] regionUpper,
final int[] subsamplings) {
         final int dimension = size.length;


Mime
View raw message