You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2020/07/29 16:47:46 UTC

[sis] branch geoapi-4.0 updated: More checks against null pointers.

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 5fe1072  More checks against null pointers.
5fe1072 is described below

commit 5fe10720d898fd7cc35654fdcaaa2a7d0ff16316
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Wed Jul 29 18:39:16 2020 +0200

    More checks against null pointers.
---
 .../src/main/java/org/apache/sis/coverage/CategoryList.java  | 12 ++++++++++++
 .../src/main/java/org/apache/sis/image/Transferer.java       |  8 ++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/CategoryList.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/CategoryList.java
index 4f3f8de..d395e2c 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/CategoryList.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/CategoryList.java
@@ -638,11 +638,20 @@ main:   for (int peekOff = srcOff; /* numPts >= 0 */; peekOff += direction) {
     }
 
     /**
+     * Ensures that the given arrays are non-null.
+     */
+    private static void ensureNonNull(final Object srcPts, final Object dstPts) {
+        ArgumentChecks.ensureNonNull("srcPts", srcPts);
+        ArgumentChecks.ensureNonNull("dstPts", dstPts);
+    }
+
+    /**
      * Transforms a list of coordinate point ordinal values. This method can be invoked only if {@link #categories}
      * contains at least two elements, otherwise a {@code MathTransform} implementation from another package is used.
      */
     @Override
     public final void transform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) throws TransformException {
+        ensureNonNull(srcPts, dstPts);
         transform(srcPts, null, srcOff, dstPts, null, dstOff, numPts);
     }
 
@@ -652,6 +661,7 @@ main:   for (int peekOff = srcOff; /* numPts >= 0 */; peekOff += direction) {
      */
     @Override
     public final void transform(float[] srcPts, int srcOff, float[] dstPts, int dstOff, int numPts) throws TransformException {
+        ensureNonNull(srcPts, dstPts);
         transform(null, srcPts, srcOff, null, dstPts, dstOff, numPts);
     }
 
@@ -661,6 +671,7 @@ main:   for (int peekOff = srcOff; /* numPts >= 0 */; peekOff += direction) {
      */
     @Override
     public final void transform(float[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) throws TransformException {
+        ensureNonNull(srcPts, dstPts);
         transform(null, srcPts, srcOff, dstPts, null, dstOff, numPts);
     }
 
@@ -670,6 +681,7 @@ main:   for (int peekOff = srcOff; /* numPts >= 0 */; peekOff += direction) {
      */
     @Override
     public final void transform(double[] srcPts, int srcOff, float[] dstPts, int dstOff, int numPts) throws TransformException {
+        ensureNonNull(srcPts, dstPts);
         transform(srcPts, null, srcOff, null, dstPts, dstOff, numPts);
     }
 
diff --git a/core/sis-feature/src/main/java/org/apache/sis/image/Transferer.java b/core/sis-feature/src/main/java/org/apache/sis/image/Transferer.java
index f0b1b32..6f196c2 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/image/Transferer.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/image/Transferer.java
@@ -168,8 +168,8 @@ abstract class Transferer {
 
         /** Copies source values directly in the target, then applies the conversion in-place. */
         @Override void computeStrip(final MathTransform1D converter) throws TransformException {
-            final double[] data = buffer.getData(band);
-            source.getSamples(region.x, region.y, region.width, region.height, band, data);
+            double[] data = buffer.getData(band);
+            data = source.getSamples(region.x, region.y, region.width, region.height, band, data);
             converter.transform(data, 0, data, 0, length());
         }
     }
@@ -194,8 +194,8 @@ abstract class Transferer {
 
         /** Copies source values directly in the target, then applies the conversion in-place. */
         @Override void computeStrip(final MathTransform1D converter) throws TransformException {
-            final float[] data = buffer.getData(band);
-            source.getSamples(region.x, region.y, region.width, region.height, band, data);
+            float[] data = buffer.getData(band);
+            data = source.getSamples(region.x, region.y, region.width, region.height, band, data);
             converter.transform(data, 0, data, 0, length());
         }
     }