8320328: Restore interrupted flag in ImageIcon.loadImage

Reviewed-by: aivanov, serb
This commit is contained in:
Rajat Mahajan 2024-01-15 13:09:00 +00:00 committed by Alexey Ivanov
parent a45b5b4921
commit f368a0c12e
2 changed files with 10 additions and 4 deletions

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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); mTracker.waitForID(id, 0);
} catch (InterruptedException e) { } catch (InterruptedException e) {
interrupted = true; interrupted = true;
Thread.currentThread().interrupt();
} }
loadStatus = mTracker.statusID(id, false); loadStatus = mTracker.statusID(id, false);

View File

@ -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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -32,7 +32,7 @@ import java.nio.charset.StandardCharsets;
/* /*
* @test * @test
* @bug 8236987 * @bug 8236987 8320328
* @summary Verifies ImageIcon constructor produces no output when the * @summary Verifies ImageIcon constructor produces no output when the
* thread is interrupted * thread is interrupted
* @run main LoadInterruptTest * @run main LoadInterruptTest
@ -74,6 +74,8 @@ public class LoadInterruptTest {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
ImageIcon i = new ImageIcon("https://openjdk.org/images/openjdk.png"); ImageIcon i = new ImageIcon("https://openjdk.org/images/openjdk.png");
int status = i.getImageLoadStatus(); int status = i.getImageLoadStatus();
boolean interrupted = Thread.currentThread().isInterrupted();
System.out.flush(); System.out.flush();
String outString = testOut.toString(StandardCharsets.UTF_8); String outString = testOut.toString(StandardCharsets.UTF_8);
@ -84,6 +86,9 @@ public class LoadInterruptTest {
if (status == MediaTracker.LOADING) { if (status == MediaTracker.LOADING) {
throw new RuntimeException("Test Case Failed!!! LOADING... status!!!"); throw new RuntimeException("Test Case Failed!!! LOADING... status!!!");
} }
if (!interrupted) {
throw new RuntimeException("Interrupted state of the thread is not preserved");
}
} }
} }