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: More checks against null pointers.
Date Wed, 29 Jul 2020 16:47:46 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 5fe1072  More checks against null pointers.
5fe1072 is described below

commit 5fe10720d898fd7cc35654fdcaaa2a7d0ff16316
Author: Martin Desruisseaux <martin.desruisseaux@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());
         }
     }


Mime
View raw message