8293862: javax/swing/JFileChooser/8046391/bug8046391.java failed with 'Cannot invoke "java.awt.Image.getWidth(java.awt.image.ImageObserver)" because "retVal" is null'

Co-authored-by: Tejesh R <tr@openjdk.org>
Reviewed-by: prr, serb
This commit is contained in:
Alexey Ivanov 2023-01-19 13:00:09 +00:00
parent e326b86d37
commit 2e4a3c47e2
4 changed files with 27 additions and 12 deletions
src/java.desktop/windows
classes/sun/awt/shell
native/libawt/windows
test/jdk
ProblemList.txt
javax/swing/JFileChooser/8046391

@ -1130,6 +1130,14 @@ final class Win32ShellFolder2 extends ShellFolder {
return icon;
}
/**
* The data is not available yet.
* @see
* <a href="https://learn.microsoft.com/en-us/windows/win32/com/com-error-codes-1">COM
* Error Codes</a>.
*/
private static final long E_PENDING = 0x8000000AL;
/**
* @return The icon image of specified size used to display this shell folder
*/
@ -1155,10 +1163,10 @@ final class Win32ShellFolder2 extends ShellFolder {
getRelativePIDL(), s, false);
// E_PENDING: loading can take time so get the default
if (hIcon <= 0) {
if (hIcon == E_PENDING || hIcon == 0) {
hIcon = extractIcon(getParentIShellFolder(),
getRelativePIDL(), s, true);
if (hIcon <= 0) {
if (hIcon == 0) {
if (isDirectory()) {
newIcon = getShell32Icon(FOLDER_ICON_ID, size);
} else {
@ -1395,11 +1403,14 @@ final class Win32ShellFolder2 extends ShellFolder {
final Map<Integer, Image> resolutionVariants = new HashMap<>();
public MultiResolutionIconImage(int baseSize, Map<Integer, Image> resolutionVariants) {
assert !resolutionVariants.containsValue(null)
: "There are null icons in the MRI variants map";
this.baseSize = baseSize;
this.resolutionVariants.putAll(resolutionVariants);
}
public MultiResolutionIconImage(int baseSize, Image image) {
assert image != null : "Null icon passed as the base image for MRI";
this.baseSize = baseSize;
this.resolutionVariants.put(baseSize, image);
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, 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
@ -974,7 +974,7 @@ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_extractIcon
return 0;
}
HICON hIcon = NULL;
HICON hIcon;
HRESULT hres;
IExtractIconW* pIcon;
@ -995,15 +995,21 @@ JNIEXPORT jlong JNICALL Java_sun_awt_shell_Win32ShellFolder2_extractIcon
iconSize = (16 << 16) + size;
}
hres = pIcon->Extract(szBuf, index, &hIcon, &hIconSmall, iconSize);
if (size < 24) {
fn_DestroyIcon((HICON)hIcon);
hIcon = hIconSmall;
if (SUCCEEDED(hres)) {
if (size < 24) {
fn_DestroyIcon((HICON)hIcon);
hIcon = hIconSmall;
} else {
fn_DestroyIcon((HICON)hIconSmall);
}
} else {
fn_DestroyIcon((HICON)hIconSmall);
hIcon = NULL;
}
} else if (hres == E_PENDING) {
pIcon->Release();
return E_PENDING;
return (unsigned) E_PENDING;
} else {
hIcon = NULL;
}
pIcon->Release();
}

@ -671,8 +671,6 @@ java/awt/image/multiresolution/MultiResolutionJOptionPaneIconTest.java 8274106 m
javax/swing/JFrame/8175301/ScaledFrameBackgroundTest.java 8274106 macosx-aarch64
java/awt/Mouse/EnterExitEvents/DragWindowTest.java 8298823 macosx-all
javax/swing/JFileChooser/8046391/bug8046391.java 8293862 windows-x64
javax/swing/JFileChooser/4847375/bug4847375.java 8293862 windows-x64
java/awt/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java 8280392 windows-x64
java/awt/Mixing/AWT_Mixing/OpaqueOverlapping.java 8294264 windows-x64
java/awt/Mixing/AWT_Mixing/ViewportOverlapping.java 8253184,8295813 windows-x64

@ -23,7 +23,7 @@
/*
* @test
* @bug 8046391
* @bug 8046391 8293862
* @requires (os.family == "windows")
* @summary JFileChooser hangs if displayed in Windows L&F
* @author Alexey Ivanov