Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
8241370: Crash in JPEGImageLoader after fix for JDK-8212034
Reviewed-by: kcr
- Loading branch information
Showing
3 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
tests/system/src/test/java/test/com/sun/javafx/iio/LoadCorruptJPEGTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright (c) 2020, 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package test.com.sun.javafx.iio; | ||
|
||
import javafx.application.Application; | ||
import javafx.application.Platform; | ||
import javafx.scene.image.Image; | ||
import javafx.scene.image.ImageView; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.Scene; | ||
import javafx.stage.Stage; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.FileNotFoundException; | ||
import java.net.URL; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.junit.After; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import static org.junit.Assert.fail; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import test.util.Util; | ||
|
||
public class LoadCorruptJPEGTest { | ||
static CountDownLatch startupLatch; | ||
static HBox root; | ||
static volatile Scene scene; | ||
static volatile Stage stage; | ||
static final int SCENE_WIDTH = 200; | ||
static final int SCENE_HEIGHT = 200; | ||
|
||
@Test | ||
public void testCorruptJPEGImage() { | ||
Util.runAndWait(() -> { | ||
URL resource = LoadCorruptJPEGTest.class.getResource("corrupt.jpg"); | ||
FileInputStream input = null; | ||
try { | ||
input = new FileInputStream(resource.getFile()); | ||
} catch (FileNotFoundException e) { | ||
fail("File not found: corrupt.jpg"); | ||
} | ||
Image image = new Image(input); | ||
ImageView iv = new ImageView(image); | ||
root.getChildren().add(iv); | ||
}); | ||
} | ||
|
||
public static class TestApp extends Application { | ||
@Override | ||
public void start(Stage primaryStage) { | ||
stage = primaryStage; | ||
root = new HBox(); | ||
scene = new Scene(root, SCENE_WIDTH, SCENE_HEIGHT); | ||
stage.setScene(scene); | ||
stage.setOnShown(l -> { | ||
Platform.runLater(() -> startupLatch.countDown()); | ||
}); | ||
stage.show(); | ||
} | ||
} | ||
|
||
@BeforeClass | ||
public static void initFX() throws Exception { | ||
startupLatch = new CountDownLatch(1); | ||
new Thread(() -> Application.launch(TestApp.class, (String[])null)).start(); | ||
assertTrue("Timeout waiting for FX runtime to start", | ||
startupLatch.await(15, TimeUnit.SECONDS)); | ||
} | ||
|
||
@AfterClass | ||
public static void exit() { | ||
Util.runAndWait(() -> { | ||
stage.hide(); | ||
}); | ||
Platform.exit(); | ||
} | ||
|
||
@After | ||
public void resetTest() { | ||
Util.runAndWait(() -> { | ||
root.getChildren().clear(); | ||
}); | ||
} | ||
} |
Binary file added
BIN
+372 Bytes
tests/system/src/test/resources/test/com/sun/javafx/iio/corrupt.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.