Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions src/java.desktop/windows/native/libawt/windows/awt_Window.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2025, 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
Expand Down Expand Up @@ -2110,20 +2110,49 @@ HICON CreateIconFromRaster(JNIEnv* env, jintArray iconRaster, jint w, jint h)
void AwtWindow::SetIconData(JNIEnv* env, jintArray iconRaster, jint w, jint h,
jintArray smallIconRaster, jint smw, jint smh)
{
HICON hNewIcon = NULL;
HICON hNewIconSm = NULL;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume we know for sure there's no exception pending when we enter ?
Looking at the only caller, it seems probable.

Copy link
Member Author

@rajamah rajamah Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting we add a JNU_CHECK_EXCEPTION the beginning of the function? , as I don't think we know for sure there is an exception pending or not at this point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume we know for sure there's no exception pending when we enter ?
Looking at the only caller, it seems probable.

There can't be a pending exception when AwtWindow::SetIconData starts.

The chain starts with JNI method Java_sun_awt_windows_WWindowPeer_setIconImagesData which calls AwtWindow::_SetIconImagesData wrapped in SyncCall.

No Java code is called before execution gets into SetIconData where CreateIconFromRaster is called.

…I don't think we know for sure there is an exception pending or not at this point.

I'm sure there's no pending exception on the entry to AwtWindow::SetIconData.

try {
hNewIcon = CreateIconFromRaster(env, iconRaster, w, h);
if (env->ExceptionCheck()) {
if (hNewIcon != NULL) {
DestroyIcon(hNewIcon);
}
return;
}

hNewIconSm = CreateIconFromRaster(env, smallIconRaster, smw, smh);
if (env->ExceptionCheck()) {
if (hNewIcon != NULL) {
DestroyIcon(hNewIcon);
}
if (hNewIconSm != NULL) {
DestroyIcon(hNewIconSm);
}
return;
}
} catch (...) {
if (hNewIcon != NULL) {
DestroyIcon(hNewIcon);
}
if (hNewIconSm != NULL) {
DestroyIcon(hNewIconSm);
}
return;
}

HICON hOldIcon = NULL;
HICON hOldIconSm = NULL;
//Destroy previous icon if it isn't inherited
if ((m_hIcon != NULL) && !m_iconInherited) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why the check for NULL is needed .. but it is OK.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? That it could've been just if ((m_hIcon) && !m_iconInherited)?

This line is unchanged.
In the majority of cases the surrounding code uses explicit != NULL in if-statements.

hOldIcon = m_hIcon;
}
m_hIcon = NULL;
if ((m_hIconSm != NULL) && !m_iconInherited) {
hOldIconSm = m_hIconSm;
}
m_hIconSm = NULL;
m_hIcon = CreateIconFromRaster(env, iconRaster, w, h);
JNU_CHECK_EXCEPTION(env);
m_hIconSm = CreateIconFromRaster(env, smallIconRaster, smw, smh);

m_hIcon = hNewIcon;
m_hIconSm = hNewIconSm;

m_iconInherited = (m_hIcon == NULL);
if (m_iconInherited) {
Expand All @@ -2136,8 +2165,11 @@ void AwtWindow::SetIconData(JNIEnv* env, jintArray iconRaster, jint w, jint h,
m_iconInherited = FALSE;
}
}

DoUpdateIcon();
EnumThreadWindows(AwtToolkit::MainThread(), UpdateOwnedIconCallback, (LPARAM)this);

// Destroy previous icons if they were not inherited
if (hOldIcon != NULL) {
DestroyIcon(hOldIcon);
}
Expand Down