Skip to content

Commit 7210b97

Browse files
Satyen SubramaniamPaul Hohensee
authored andcommitted
8346887: DrawFocusRect() may cause an assertion failure
Reviewed-by: phh, serb Backport-of: 8eddf67c82a2af4d704c4063ad802640770b3c26
1 parent 84576a9 commit 7210b97

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

jdk/src/windows/native/sun/windows/awt_Button.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -242,7 +242,8 @@ AwtButton::OwnerDrawItem(UINT /*ctrlId*/, DRAWITEMSTRUCT& drawInfo)
242242
RECT focusRect;
243243
VERIFY(::CopyRect(&focusRect, &rect));
244244
VERIFY(::InflateRect(&focusRect,-inf,-inf));
245-
VERIFY(::DrawFocusRect(hDC, &focusRect));
245+
if (!::IsRectEmpty(&focusRect) && (::DrawFocusRect(hDC, &focusRect) == 0))
246+
VERIFY(::GetLastError() == 0);
246247
}
247248

248249
/* Notify any subclasses */

jdk/src/windows/native/sun/windows/awt_Checkbox.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -290,12 +290,14 @@ AwtCheckbox::OwnerDrawItem(UINT /*ctrlId*/, DRAWITEMSTRUCT& drawInfo)
290290
if ((drawInfo.itemState & ODS_FOCUS) &&
291291
((drawInfo.itemAction & ODA_FOCUS)||
292292
(drawInfo.itemAction &ODA_DRAWENTIRE))) {
293-
VERIFY(::DrawFocusRect(hDC, &focusRect));
293+
if (!::IsRectEmpty(&focusRect) && (::DrawFocusRect(hDC, &focusRect) == 0))
294+
VERIFY(::GetLastError() == 0);
294295
}
295296
/* erase focus rect */
296297
else if (!(drawInfo.itemState & ODS_FOCUS) &&
297298
(drawInfo.itemAction & ODA_FOCUS)) {
298-
VERIFY(::DrawFocusRect(hDC, &focusRect));
299+
if (!::IsRectEmpty(&focusRect) && (::DrawFocusRect(hDC, &focusRect) == 0))
300+
VERIFY(::GetLastError() == 0);
299301
}
300302

301303
/* Notify any subclasses */

jdk/src/windows/native/sun/windows/awt_Component.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -4446,7 +4446,8 @@ void AwtComponent::DrawListItem(JNIEnv *env, DRAWITEMSTRUCT &drawInfo)
44464446
if ((drawInfo.itemState & ODS_FOCUS) &&
44474447
(drawInfo.itemAction & (ODA_FOCUS | ODA_DRAWENTIRE))) {
44484448
if (!unfocusableChoice){
4449-
VERIFY(::DrawFocusRect(hDC, &rect));
4449+
if (!::IsRectEmpty(&rect) && (::DrawFocusRect(hDC, &rect) == 0))
4450+
VERIFY(::GetLastError() == 0);
44504451
}
44514452
}
44524453
env->DeleteLocalRef(target);

0 commit comments

Comments
 (0)