From f368a0c12e0c51054fa89dfae8d4116fa535debf Mon Sep 17 00:00:00 2001 From: Rajat Mahajan Date: Mon, 15 Jan 2024 13:09:00 +0000 Subject: [PATCH] 8320328: Restore interrupted flag in ImageIcon.loadImage Reviewed-by: aivanov, serb --- .../share/classes/javax/swing/ImageIcon.java | 3 ++- test/jdk/javax/swing/ImageIcon/LoadInterruptTest.java | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/java.desktop/share/classes/javax/swing/ImageIcon.java b/src/java.desktop/share/classes/javax/swing/ImageIcon.java index be7179e6201..2eeac8961bc 100644 --- a/src/java.desktop/share/classes/javax/swing/ImageIcon.java +++ b/src/java.desktop/share/classes/javax/swing/ImageIcon.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2024, 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 @@ -330,6 +330,7 @@ public class ImageIcon implements Icon, Serializable, Accessible { mTracker.waitForID(id, 0); } catch (InterruptedException e) { interrupted = true; + Thread.currentThread().interrupt(); } loadStatus = mTracker.statusID(id, false); diff --git a/test/jdk/javax/swing/ImageIcon/LoadInterruptTest.java b/test/jdk/javax/swing/ImageIcon/LoadInterruptTest.java index b090662eba4..fd74378c584 100644 --- a/test/jdk/javax/swing/ImageIcon/LoadInterruptTest.java +++ b/test/jdk/javax/swing/ImageIcon/LoadInterruptTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -32,7 +32,7 @@ import java.nio.charset.StandardCharsets; /* * @test - * @bug 8236987 + * @bug 8236987 8320328 * @summary Verifies ImageIcon constructor produces no output when the * thread is interrupted * @run main LoadInterruptTest @@ -74,6 +74,8 @@ public class LoadInterruptTest { Thread.currentThread().interrupt(); ImageIcon i = new ImageIcon("https://openjdk.org/images/openjdk.png"); int status = i.getImageLoadStatus(); + boolean interrupted = Thread.currentThread().isInterrupted(); + System.out.flush(); String outString = testOut.toString(StandardCharsets.UTF_8); @@ -84,6 +86,9 @@ public class LoadInterruptTest { if (status == MediaTracker.LOADING) { throw new RuntimeException("Test Case Failed!!! LOADING... status!!!"); } + + if (!interrupted) { + throw new RuntimeException("Interrupted state of the thread is not preserved"); + } } } -