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: Fix a NullPointerException when building a `GridCoverage2D` with domain set to `GridGeometry.UNDEFINED`.
Date Wed, 22 Apr 2020 10:23:38 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 bd836fa  Fix a NullPointerException when building a `GridCoverage2D` with domain
set to `GridGeometry.UNDEFINED`.
bd836fa is described below

commit bd836fa8ecdf76e4a3d87ef35868d5fa079a1b88
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Apr 22 12:22:10 2020 +0200

    Fix a NullPointerException when building a `GridCoverage2D` with domain set to `GridGeometry.UNDEFINED`.
---
 .../org/apache/sis/coverage/grid/GridCoverageBuilder.java  |  2 +-
 .../java/org/apache/sis/coverage/grid/GridGeometry.java    |  7 +++++--
 .../apache/sis/coverage/grid/GridCoverageBuilderTest.java  | 14 ++++++++++++++
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
index 42dfc46..ad15613 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverageBuilder.java
@@ -175,7 +175,7 @@ public class GridCoverageBuilder {
      * @return {@code this} for method invocation chaining.
      */
     public GridCoverageBuilder setDomain(final GridGeometry grid) {
-        domain = grid;
+        domain = (grid != GridGeometry.UNDEFINED) ? grid : null;
         return this;
     }
 
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
index c96e82c..e33ff78 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
@@ -797,13 +797,16 @@ public class GridGeometry implements LenientComparable, Serializable
{
             return extent.getDimension();       // Most reliable source since that method
is final.
         } else if (gridToCRS != null) {
             return gridToCRS.getSourceDimensions();
-        } else {
+        } else if (envelope != null) {
             /*
              * Last resort only since we have no guarantee that the envelope dimension is
the same
              * than the grid dimension (see above javadoc). The envelope should never be
null at
-             * this point since the constructor verified that at least one argument was non-null.
+             * this point since the constructor verified that at least one argument was non-null,
+             * except if this method is invoked on UNDEFINED.
              */
             return envelope.getDimension();
+        } else {
+            throw incomplete(EXTENT, Resources.Keys.UnspecifiedGridExtent);
         }
     }
 
diff --git a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverageBuilderTest.java
b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverageBuilderTest.java
index da71047..6a2a7f7 100644
--- a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverageBuilderTest.java
+++ b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverageBuilderTest.java
@@ -209,4 +209,18 @@ public final strictfp class GridCoverageBuilderTest extends TestCase
{
             assertEquals(new AffineTransform2D(10, 0, 0, -10, -175, 85), gridToCRS);
         }
     }
+
+    /**
+     * Tests constructions of a grid coverage with {@link GridGeometry#UNDEFINED} domain.
+     */
+    @Test
+    public void testUndefinedDomain() {
+        final GridCoverageBuilder builder = new GridCoverageBuilder();
+        assertSame(builder, builder.setDomain(GridGeometry.UNDEFINED));
+        assertSame(builder, builder.setValues(new BufferedImage(3, 4, BufferedImage.TYPE_BYTE_GRAY)));
+        final GridCoverage coverage = builder.build();
+        final GridExtent extent = coverage.getGridGeometry().getExtent();
+        GridExtentTest.assertExtentEquals(extent, 0, 0, 2);
+        GridExtentTest.assertExtentEquals(extent, 1, 0, 3);
+    }
 }


Mime
View raw message