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

commit d30a19d7f49d95b9170228d1986ac8ca6a463c3c
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Wed Feb 2 15:43:12 2022 +0100

    Remove workarounds that are no longer needed when building with JDK 17 
(even if the compilation result still target Java 8).
    Add workaround for https://bugs.openjdk.java.net/browse/JDK-8166038
---
 .../apache/sis/coverage/grid/GridCoverage2D.java   |  9 +++----
 .../sis/internal/coverage/j2d/TilePlaceholder.java | 21 +++++++++-------
 .../sis/coverage/grid/GridCoverage2DTest.java      | 28 +++-------------------
 .../sis/internal/storage/TiledGridCoverage.java    |  3 +++
 .../internal/storage/MemoryGridResourceTest.java   |  8 ++-----
 5 files changed, 26 insertions(+), 43 deletions(-)

diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
 
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
index a30f75f..80e895b 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage2D.java
@@ -632,11 +632,12 @@ public class GridCoverage2D extends GridCoverage {
                      * Workaround for 
https://bugs.openjdk.java.net/browse/JDK-8166038
                      * If BufferedImage can not be used, fallback on 
ReshapedImage
                      * at the cost of returning an image larger than necessary.
-                     *
-                     * See also GridCoverage2DTest.PENDING_JDK_FIX
+                     * This workaround can be removed on JDK17.
                      */
-                    if (result.getTileGridXOffset() == ix && 
result.getTileGridYOffset() == iy) {
-                        return result;
+                    if 
(org.apache.sis.internal.coverage.j2d.TilePlaceholder.PENDING_JDK_FIX) {
+                        if (result.getTileGridXOffset() == ix && 
result.getTileGridYOffset() == iy) {
+                            return result;
+                        }
                     }
                 }
             }
diff --git 
a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TilePlaceholder.java
 
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TilePlaceholder.java
index d32cc1d..45d4411 100644
--- 
a/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TilePlaceholder.java
+++ 
b/core/sis-feature/src/main/java/org/apache/sis/internal/coverage/j2d/TilePlaceholder.java
@@ -46,10 +46,16 @@ import 
org.apache.sis.internal.system.ReferenceQueueConsumer;
  */
 public class TilePlaceholder {
     /**
-     * Identifies workaround for a JDK bug: call to {@code 
Graphics2D.drawRenderedImage(…)}
-     * fails if the image contains more than one tile (or a single tile not 
located at 0,0)
-     * and the tiles are not instances of {@link WritableRaster} (i.e. are 
instances of the
-     * read-only {@link Raster} parent class). The exception thrown is:
+     * Identifies workaround for two JDK bugs.
+     *
+     * <p><a 
href="https://bugs.openjdk.java.net/browse/JDK-8166038";>JDK-8166038</a>:
+     * If {@link BufferedImage} can not be used, fallback on {@link 
ReshapedImage} at the cost of an image
+     * larger than necessary. In such case, the tests need to specify the 
sub-region of pixels to verify.</p>
+     *
+     * <p><a 
href="https://bugs.openjdk.java.net/browse/JDK-8275345";>JDK-8275345</a>:
+     * call to {@code Graphics2D.drawRenderedImage(…)} fails if the image 
contains more than one tile
+     * (or a single tile not located at 0,0) and the tiles are not instances 
of {@link WritableRaster}
+     * (i.e. are instances of the read-only {@link Raster} parent class). The 
exception thrown is:
      *
      * {@preformat text
      *   Exception in thread "main" java.awt.image.RasterFormatException: 
(parentX + width) is outside raster
@@ -57,11 +63,10 @@ public class TilePlaceholder {
      *       at 
java.desktop/sun.java2d.SunGraphics2D.drawTranslatedRenderedImage(SunGraphics2D.java:2852)
      *       at 
java.desktop/sun.java2d.SunGraphics2D.drawRenderedImage(SunGraphics2D.java:2711)
      * }
-     *
-     * @see <a 
href="https://bugs.openjdk.java.net/browse/JDK-8275345";>JDK-8275345</a>
+     * </p>
      */
     @Workaround(library="JDK", version="17")
-    private static final boolean PENDING_JDK_FIX = false;
+    public static final boolean PENDING_JDK_FIX = true;
 
     /**
      * Cache of empty tiles for different sample models.
@@ -188,7 +193,7 @@ public class TilePlaceholder {
                 // Else prefer read-only tile (created below) if we do not 
need to draw anything.
             }
         }
-        if (!PENDING_JDK_FIX) {
+        if (PENDING_JDK_FIX) {
             return Raster.createWritableRaster(model, buffer, location);
         }
         // Reuse same `DataBuffer` with only a different location.
diff --git 
a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverage2DTest.java
 
b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverage2DTest.java
index f2bf359..6a8be0a 100644
--- 
a/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverage2DTest.java
+++ 
b/core/sis-feature/src/test/java/org/apache/sis/coverage/grid/GridCoverage2DTest.java
@@ -37,7 +37,6 @@ import org.apache.sis.measure.NumberRange;
 import org.apache.sis.measure.Units;
 import org.apache.sis.referencing.crs.HardCodedCRS;
 import org.apache.sis.referencing.operation.transform.MathTransforms;
-import org.apache.sis.util.Workaround;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
@@ -51,23 +50,12 @@ import static org.apache.sis.test.FeatureAssert.*;
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Alexis Manin (Geomatys)
- * @version 1.1
+ * @version 1.2
  * @since   1.1
  * @module
  */
 public strictfp class GridCoverage2DTest extends TestCase {
     /**
-     * Disables tests that are pending <a 
href="https://bugs.openjdk.java.net/browse/JDK-8166038";>JDK-8166038</a> fix.
-     * If {@link BufferedImage} can not be used, fallback on {@link 
ReshapedImage} at the cost of an image larger than
-     * necessary. In such case, the tests need to specify the sub-region of 
pixels to verify.
-     *
-     * <p>If JDK-8166038 is fixed, remove the {@code if 
(result.getTileGridXOffset() == ix && ...)} test in
-     * {@link GridCoverage2D#render(GridExtent)}.</p>
-     */
-    @Workaround(library="JDK", version="14", fixed="16")
-    private static final boolean PENDING_JDK_FIX = false;
-
-    /**
      * Width and height of the grid tested in this class.
      */
     protected static final int GRID_SIZE = 2;
@@ -244,13 +232,8 @@ public strictfp class GridCoverage2DTest extends TestCase {
          */
         final GridExtent singleRow = new GridExtent(GRID_SIZE, 1).translate(0, 
1);
         result = coverage.render(singleRow);
-        if (PENDING_JDK_FIX) {
             assertInstanceOf("render", BufferedImage.class, result);
             assertPixelsEqual(coverage.render(null), new Rectangle(0, 1, 
GRID_SIZE, 1), result, null);
-        } else {
-            assertPixelsEqual(coverage.render(null), new Rectangle(0, 1, 
GRID_SIZE, 1),
-                                             result, new Rectangle(0, 0, 
GRID_SIZE, 1));
-        }
         /*
          * Column extraction:
          *   - Expected size (1,2) is verified by `assertPixelsEqual(…)`.
@@ -260,13 +243,8 @@ public strictfp class GridCoverage2DTest extends TestCase {
          */
         final GridExtent singleCol = new GridExtent(1, GRID_SIZE).translate(1, 
0);
         result = coverage.render(singleCol);
-        if (PENDING_JDK_FIX) {
-            assertInstanceOf("render", BufferedImage.class, result);
-            assertPixelsEqual(coverage.render(null), new Rectangle(1, 0, 1, 
GRID_SIZE), result, null);
-        } else {
-            assertPixelsEqual(coverage.render(null), new Rectangle(1, 0, 1, 
GRID_SIZE),
-                                             result, new Rectangle(0, 0, 1, 
GRID_SIZE));
-        }
+        assertInstanceOf("render", BufferedImage.class, result);
+        assertPixelsEqual(coverage.render(null), new Rectangle(1, 0, 1, 
GRID_SIZE), result, null);
     }
 
     /**
diff --git 
a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/TiledGridCoverage.java
 
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/TiledGridCoverage.java
index 05a4ed6..8dcd8dd 100644
--- 
a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/TiledGridCoverage.java
+++ 
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/TiledGridCoverage.java
@@ -620,6 +620,9 @@ public abstract class TiledGridCoverage extends 
GridCoverage {
                      * a view created by 
`SampleModel.createSubsetSampleModel(int[] bands)`.
                      * Bands can also be in a different order and still share 
the same buffer.
                      */
+                    if 
(org.apache.sis.internal.coverage.j2d.TilePlaceholder.PENDING_JDK_FIX) {
+                        return Raster.createWritableRaster(model, 
tile.getDataBuffer(), new Point(x, y));
+                    }
                     return Raster.createRaster(model, tile.getDataBuffer(), 
new Point(x, y));
                 }
             }
diff --git 
a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryGridResourceTest.java
 
b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryGridResourceTest.java
index 13ad1fb..2a6ab36 100644
--- 
a/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryGridResourceTest.java
+++ 
b/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/MemoryGridResourceTest.java
@@ -36,7 +36,7 @@ import static org.apache.sis.test.Assert.*;
  * Tests {@link MemoryGridResource}.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.1
+ * @version 1.2
  * @since   1.1
  * @module
  */
@@ -92,13 +92,9 @@ public final strictfp class MemoryGridResourceTest extends 
TestCase {
         final GridGeometry request  = createSubGrid();
         final GridCoverage coverage = resource.read(request);
         /*
-         * PENDING_JDK_FIX: remove the following lines after we request JDK16 
for building.
+         * Note: following lines work only with JDK 16 or above.
          * https://bugs.openjdk.java.net/browse/JDK-8166038
          */
-        if (resource.getGridGeometry().equals(coverage.getGridGeometry())) {
-            return;
-        }
-        // End of PENDING_JDK_FIX. Following line assumes JDK16.
         assertEqualsIgnoreMetadata(request, coverage.getGridGeometry());
         assertInstanceOf("render(null)", BufferedImage.class, 
coverage.render(null));
     }

Reply via email to