[8u] RFR 8183349: Better cleanup for jdk/test/javax/imageio/plugins/shared/CanWriteSequence.java and WriteAfterAbort.java
Andrew Hughes
gnu.andrew at redhat.com
Tue Jun 16 23:43:54 UTC 2020
On 16/06/2020 22:09, Zhengyu Gu wrote:
> Please review this backport for parity with Oracle 8u271.
>
> The original patch does not apply cleanly. The conflicts are minor, as
> 8u version of CanWriteSequence.test() method format is slightly off.
>
> Original bug: https://bugs.openjdk.java.net/browse/JDK-8183349
> Original patch: http://hg.openjdk.java.net/jdk10/jdk10/jdk/rev/93b7bd25273e
>
> 8u weberv: http://cr.openjdk.java.net/~zgu/JDK-8183349-8u/webrev.00/
>
> Test:
> Passed both tests on Linux x86_64
>
>
> Thanks,
>
> -Zhengyu
>
Where are the indentation differences coming from in this patch? The
only difference between the 8u and 10u version of this file prior to the
patch is the latter has a newline at the end.
The attached is what I get from backporting the 11u changeset to 8u. It
is nearly identical to the 11u version.
Thanks,
--
Andrew :)
Senior Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)
PGP Key: ed25519/0xCFDA0F9B35964222 (hkp://keys.gnupg.net)
Fingerprint = 5132 579D D154 0ED2 3E04 C5A0 CFDA 0F9B 3596 4222
-------------- next part --------------
diff --git a/test/javax/imageio/plugins/shared/CanWriteSequence.java b/test/javax/imageio/plugins/shared/CanWriteSequence.java
--- a/test/javax/imageio/plugins/shared/CanWriteSequence.java
+++ b/test/javax/imageio/plugins/shared/CanWriteSequence.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,6 +23,7 @@
import java.io.File;
import java.io.FileOutputStream;
+import java.nio.file.Files;
import java.util.Iterator;
import javax.imageio.ImageIO;
@@ -34,11 +35,18 @@
/**
* @test
- * @bug 4958064
- * @author Sergey Bylokhov
+ * @bug 4958064 8183349
+ * @summary Test verifies that when we try to forcefully run
+ * prepareWriteSequence() where it is not supported
+ * will ImageIO throws an UnsupportedOperationException
+ * or not.
+ * @run main CanWriteSequence
*/
public final class CanWriteSequence {
+ private static File file;
+ private static FileOutputStream fos;
+
public static void main(final String[] args) throws Exception {
final IIORegistry registry = IIORegistry.getDefaultInstance();
final Iterator<ImageWriterSpi> iter =
@@ -54,25 +62,32 @@
}
private static void test(final ImageWriter writer) throws Exception {
- final File file = File.createTempFile("temp", ".img");
- file.deleteOnExit();
- final FileOutputStream fos = new FileOutputStream(file);
- final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
- writer.setOutput(ios);
- final IIOMetadata data = writer.getDefaultStreamMetadata(null);
+ try {
+ file = File.createTempFile("temp", ".img");
+ fos = new FileOutputStream(file);
+ final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
+ writer.setOutput(ios);
+ final IIOMetadata data = writer.getDefaultStreamMetadata(null);
- if (writer.canWriteSequence()) {
- writer.prepareWriteSequence(data);
- } else {
- try {
+ if (writer.canWriteSequence()) {
writer.prepareWriteSequence(data);
- throw new RuntimeException(
- "UnsupportedOperationException was not thrown");
- } catch (final UnsupportedOperationException ignored) {
+ } else {
+ try {
+ writer.prepareWriteSequence(data);
+ throw new RuntimeException(
+ "UnsupportedOperationException was not thrown");
+ } catch (final UnsupportedOperationException ignored) {
// expected
+ }
+ }
+ } finally {
+ writer.dispose();
+ if (file != null) {
+ if (fos != null) {
+ fos.close();
+ }
+ Files.delete(file.toPath());
}
}
- writer.dispose();
- ios.close();
}
-}
\ No newline at end of file
+}
diff --git a/test/javax/imageio/plugins/shared/WriteAfterAbort.java b/test/javax/imageio/plugins/shared/WriteAfterAbort.java
--- a/test/javax/imageio/plugins/shared/WriteAfterAbort.java
+++ b/test/javax/imageio/plugins/shared/WriteAfterAbort.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -29,6 +29,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
+import java.nio.file.Files;
import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
@@ -41,9 +42,9 @@
/**
* @test
- * @bug 4952954
+ * @bug 4952954 8183349
* @summary abortFlag must be cleared for every ImageWriter.write operation
- * @author Sergey Bylokhov
+ * @run main WriteAfterAbort
*/
public final class WriteAfterAbort implements IIOWriteProgressListener {
@@ -54,73 +55,85 @@
private volatile boolean isStartedCalled;
private static final int WIDTH = 100;
private static final int HEIGHT = 100;
+ private static FileOutputStream fos;
+ private static File file;
private void test(final ImageWriter writer) throws IOException {
- // Image initialization
- final BufferedImage imageWrite = new BufferedImage(WIDTH, HEIGHT,
- TYPE_BYTE_BINARY);
- final Graphics2D g = imageWrite.createGraphics();
- g.setColor(Color.WHITE);
- g.fillRect(0, 0, WIDTH, HEIGHT);
- g.dispose();
+ try {
+ // Image initialization
+ final BufferedImage imageWrite =
+ new BufferedImage(WIDTH, HEIGHT, TYPE_BYTE_BINARY);
+ final Graphics2D g = imageWrite.createGraphics();
+ g.setColor(Color.WHITE);
+ g.fillRect(0, 0, WIDTH, HEIGHT);
+ g.dispose();
+
+ // File initialization
+ file = File.createTempFile("temp", ".img");
+ fos = new SkipWriteOnAbortOutputStream(file);
+ final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
+ writer.setOutput(ios);
+ writer.addIIOWriteProgressListener(this);
- // File initialization
- final File file = File.createTempFile("temp", ".img");
- file.deleteOnExit();
- final FileOutputStream fos = new SkipWriteOnAbortOutputStream(file);
- final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
- writer.setOutput(ios);
- writer.addIIOWriteProgressListener(this);
+ // This write will be aborted, and file will not be touched
+ writer.write(imageWrite);
+ if (!isStartedCalled) {
+ throw new RuntimeException("Started should be called");
+ }
+ if (!isProgressCalled) {
+ throw new RuntimeException("Progress should be called");
+ }
+ if (!isAbortCalled) {
+ throw new RuntimeException("Abort should be called");
+ }
+ if (isCompleteCalled) {
+ throw new RuntimeException("Complete should not be called");
+ }
+ // Flush aborted data
+ ios.flush();
- // This write will be aborted, and file will not be touched
- writer.write(imageWrite);
- if (!isStartedCalled) {
- throw new RuntimeException("Started should be called");
- }
- if (!isProgressCalled) {
- throw new RuntimeException("Progress should be called");
- }
- if (!isAbortCalled) {
- throw new RuntimeException("Abort should be called");
- }
- if (isCompleteCalled) {
- throw new RuntimeException("Complete should not be called");
- }
- // Flush aborted data
- ios.flush();
+ /*
+ * This write should be completed successfully and the file should
+ * contain correct image data.
+ */
+ abortFlag = false;
+ isAbortCalled = false;
+ isCompleteCalled = false;
+ isProgressCalled = false;
+ isStartedCalled = false;
+ writer.write(imageWrite);
- // This write should be completed successfully and the file should
- // contain correct image data.
- abortFlag = false;
- isAbortCalled = false;
- isCompleteCalled = false;
- isProgressCalled = false;
- isStartedCalled = false;
- writer.write(imageWrite);
+ if (!isStartedCalled) {
+ throw new RuntimeException("Started should be called");
+ }
+ if (!isProgressCalled) {
+ throw new RuntimeException("Progress should be called");
+ }
+ if (isAbortCalled) {
+ throw new RuntimeException("Abort should not be called");
+ }
+ if (!isCompleteCalled) {
+ throw new RuntimeException("Complete should be called");
+ }
+ ios.close();
- if (!isStartedCalled) {
- throw new RuntimeException("Started should be called");
- }
- if (!isProgressCalled) {
- throw new RuntimeException("Progress should be called");
- }
- if (isAbortCalled) {
- throw new RuntimeException("Abort should not be called");
- }
- if (!isCompleteCalled) {
- throw new RuntimeException("Complete should be called");
- }
- writer.dispose();
- ios.close();
-
- // Validates content of the file.
- final BufferedImage imageRead = ImageIO.read(file);
- for (int x = 0; x < WIDTH; ++x) {
- for (int y = 0; y < HEIGHT; ++y) {
- if (imageRead.getRGB(x, y) != imageWrite.getRGB(x, y)) {
- throw new RuntimeException("Test failed.");
+ // Validates content of the file.
+ final BufferedImage imageRead = ImageIO.read(file);
+ for (int x = 0; x < WIDTH; ++x) {
+ for (int y = 0; y < HEIGHT; ++y) {
+ if (imageRead.getRGB(x, y) != imageWrite.getRGB(x, y)) {
+ throw new RuntimeException("Test failed.");
+ }
}
}
+ } finally {
+ writer.dispose();
+ if (file != null) {
+ if (fos != null) {
+ fos.close();
+ }
+ Files.delete(file.toPath());
+ }
}
}
More information about the jdk8u-dev
mailing list