7024749: JDK7 b131---a crash in: Java_sun_awt_windows_ThemeReader_isGetThemeTransitionDurationDefined+0x75
Reviewed-by: art, ant
--- a/jdk/src/windows/native/sun/windows/awt_Component.cpp Tue Jun 26 13:46:09 2012 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_Component.cpp Tue Jun 26 16:46:00 2012 +0400
@@ -1474,9 +1474,7 @@
::GetClientRect( GetHWnd(), &r );
mr = WmSize(static_cast<UINT>(wParam), r.right - r.left, r.bottom - r.top);
//mr = WmSize(wParam, LOWORD(lParam), HIWORD(lParam));
- if (ImmGetContext() != NULL) {
- SetCompositionWindow(r);
- }
+ SetCompositionWindow(r);
break;
}
case WM_SIZING:
@@ -1535,7 +1533,10 @@
// When the window is deactivated, send WM_IME_ENDCOMPOSITION
// message to deactivate the composition window so that
// it won't receive keyboard input focus.
- if (ImmGetContext() != NULL) {
+ HIMC hIMC;
+ HWND hwnd = ImmGetHWnd();
+ if ((hIMC = ImmGetContext(hwnd)) != NULL) {
+ ImmReleaseContext(hwnd, hIMC);
DefWindowProc(WM_IME_ENDCOMPOSITION, 0, 0);
}
}
@@ -1718,11 +1719,9 @@
case WM_IME_SETCONTEXT:
// lParam is passed as pointer and it can be modified.
mr = WmImeSetContext(static_cast<BOOL>(wParam), &lParam);
- CallProxyDefWindowProc(message, wParam, lParam, retValue, mr);
break;
case WM_IME_NOTIFY:
mr = WmImeNotify(wParam, lParam);
- CallProxyDefWindowProc(message, wParam, lParam, retValue, mr);
break;
case WM_IME_STARTCOMPOSITION:
mr = WmImeStartComposition();
@@ -3723,12 +3722,14 @@
// support IME Composition messages
void AwtComponent::SetCompositionWindow(RECT& r)
{
- HIMC hIMC = ImmGetContext();
+ HWND hwnd = ImmGetHWnd();
+ HIMC hIMC = ImmGetContext(hwnd);
if (hIMC == NULL) {
return;
}
COMPOSITIONFORM cf = {CFS_DEFAULT, {0, 0}, {0, 0, 0, 0}};
ImmSetCompositionWindow(hIMC, &cf);
+ ImmReleaseContext(hwnd, hIMC);
}
void AwtComponent::OpenCandidateWindow(int x, int y)
@@ -3742,16 +3743,16 @@
SetCandidateWindow(iCandType, x-rc.left, y-rc.top);
}
if (m_bitsCandType != 0) {
- HWND proxy = GetProxyFocusOwner();
// REMIND: is there any chance GetProxyFocusOwner() returns NULL here?
- ::DefWindowProc((proxy != NULL) ? proxy : GetHWnd(),
+ ::DefWindowProc(ImmGetHWnd(),
WM_IME_NOTIFY, IMN_OPENCANDIDATE, m_bitsCandType);
}
}
void AwtComponent::SetCandidateWindow(int iCandType, int x, int y)
{
- HIMC hIMC = ImmGetContext();
+ HWND hwnd = ImmGetHWnd();
+ HIMC hIMC = ImmGetContext(hwnd);
CANDIDATEFORM cf;
cf.dwIndex = iCandType;
cf.dwStyle = CFS_CANDIDATEPOS;
@@ -3759,17 +3760,20 @@
cf.ptCurrentPos.y = y;
ImmSetCandidateWindow(hIMC, &cf);
+ ImmReleaseContext(hwnd, hIMC);
}
MsgRouting AwtComponent::WmImeSetContext(BOOL fSet, LPARAM *lplParam)
{
// If the Windows input context is disabled, do not let Windows
// display any UIs.
- HIMC hIMC = ImmGetContext();
+ HWND hwnd = ImmGetHWnd();
+ HIMC hIMC = ImmGetContext(hwnd);
if (hIMC == NULL) {
*lplParam = 0;
return mrDoDefault;
}
+ ImmReleaseContext(hwnd, hIMC);
if (fSet) {
LPARAM lParam = *lplParam;
@@ -3824,11 +3828,13 @@
AwtInputTextInfor* textInfor = NULL;
try {
- HIMC hIMC = ImmGetContext();
+ HWND hwnd = ImmGetHWnd();
+ HIMC hIMC = ImmGetContext(hwnd);
DASSERT(hIMC!=0);
textInfor = new AwtInputTextInfor;
textInfor->GetContextData(hIMC, flags);
+ ImmReleaseContext(hwnd, hIMC);
jstring jtextString = textInfor->GetText();
/* The conditions to send the input method event to AWT EDT are:
@@ -4012,16 +4018,15 @@
DASSERT(!safe_ExceptionOccurred(env));
}
-HIMC AwtComponent::ImmGetContext()
+HWND AwtComponent::ImmGetHWnd()
{
HWND proxy = GetProxyFocusOwner();
- return ::ImmGetContext((proxy != NULL) ? proxy : GetHWnd());
+ return (proxy != NULL) ? proxy : GetHWnd();
}
HIMC AwtComponent::ImmAssociateContext(HIMC himc)
{
- HWND proxy = GetProxyFocusOwner();
- return ::ImmAssociateContext((proxy != NULL) ? proxy : GetHWnd(), himc);
+ return ::ImmAssociateContext(ImmGetHWnd(), himc);
}
HWND AwtComponent::GetProxyFocusOwner()
--- a/jdk/src/windows/native/sun/windows/awt_Component.h Tue Jun 26 13:46:09 2012 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_Component.h Tue Jun 26 16:46:00 2012 +0400
@@ -464,7 +464,7 @@
int caretPos, int visiblePos);
void InquireCandidatePosition();
INLINE LPARAM GetCandidateType() { return m_bitsCandType; }
- HIMC ImmGetContext();
+ HWND ImmGetHWnd();
HIMC ImmAssociateContext(HIMC himc);
HWND GetProxyFocusOwner();
--- a/jdk/src/windows/native/sun/windows/awt_FileDialog.cpp Tue Jun 26 13:46:09 2012 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_FileDialog.cpp Tue Jun 26 16:46:00 2012 +0400
@@ -156,6 +156,7 @@
HIMC hIMC = ::ImmGetContext(hdlg);
if (hIMC != NULL) {
::ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
+ ::ImmReleaseContext(hdlg, hIMC);
}
WNDPROC lpfnWndProc = (WNDPROC)(::GetProp(parent, NativeDialogWndProcProp));
--- a/jdk/src/windows/native/sun/windows/awt_Frame.cpp Tue Jun 26 13:46:09 2012 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_Frame.cpp Tue Jun 26 16:46:00 2012 +0400
@@ -319,8 +319,6 @@
case WM_IME_STARTCOMPOSITION:
case WM_IME_ENDCOMPOSITION:
case WM_IME_COMPOSITION:
- case WM_IME_SETCONTEXT:
- case WM_IME_NOTIFY:
case WM_IME_CONTROL:
case WM_IME_COMPOSITIONFULL:
case WM_IME_SELECT:
--- a/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp Tue Jun 26 13:46:09 2012 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp Tue Jun 26 16:46:00 2012 +0400
@@ -336,7 +336,8 @@
//im --- override to over the spot composition
void AwtTextComponent::SetCompositionWindow(RECT& rc)
{
- HIMC hIMC = ImmGetContext();
+ HWND hwnd = ImmGetHWnd();
+ HIMC hIMC = ImmGetContext(hwnd);
// rc is not used for text component.
COMPOSITIONFORM cf = { CFS_FORCE_POSITION, {0,0}, {0,0,0,0} };
GetCaretPos(&(cf.ptCurrentPos));
@@ -348,6 +349,7 @@
LOGFONT lf;
GetObject(m_hFont, sizeof(LOGFONT), &lf);
ImmSetCompositionFont(hIMC, &lf);
+ ImmReleaseContext(hwnd, hIMC);
}
//im --- end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Frame/7024749/bug7024749.java Tue Jun 26 16:46:00 2012 +0400
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2012, 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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7024749
+ * @summary JDK7 b131---a crash in: Java_sun_awt_windows_ThemeReader_isGetThemeTransitionDurationDefined+0x75
+ * @library ../../../regtesthelpers
+ * @build Util
+ * @author Oleg Pekhovskiy: area=awt.toplevel
+ @run main bug7024749
+ */
+
+import java.awt.*;
+import test.java.awt.regtesthelpers.Util;
+
+public class bug7024749 {
+ public static void main(String[] args) {
+ final Frame f = new Frame("F");
+ f.setBounds(0,0,200,200);
+ f.setEnabled(false); // <- disable the top-level
+ f.setVisible(true);
+
+ Window w = new Window(f);
+ w.setBounds(300,300,300,300);
+ w.add(new TextField(20));
+ w.setVisible(true);
+
+ Robot robot = Util.createRobot();
+ robot.setAutoDelay(1000);
+ Util.waitForIdle(robot);
+ robot.delay(1000);
+ Util.clickOnTitle(f, robot);
+ Util.waitForIdle(robot);
+
+ f.dispose();
+ System.out.println("Test passed!");
+ }
+}