From 9931c2f2b868b3256bb1f8707cd41ebc3b72655b Mon Sep 17 00:00:00 2001 From: Oleg Pekhovskiy Date: Tue, 26 Jun 2012 16:46:00 +0400 Subject: [PATCH] 7024749: JDK7 b131---a crash in: Java_sun_awt_windows_ThemeReader_isGetThemeTransitionDurationDefined+0x75 Reviewed-by: art, ant --- .../native/sun/windows/awt_Component.cpp | 37 +++++++----- .../native/sun/windows/awt_Component.h | 2 +- .../native/sun/windows/awt_FileDialog.cpp | 1 + .../windows/native/sun/windows/awt_Frame.cpp | 2 - .../native/sun/windows/awt_TextComponent.cpp | 4 +- .../java/awt/Frame/7024749/bug7024749.java | 59 +++++++++++++++++++ 6 files changed, 85 insertions(+), 20 deletions(-) create mode 100644 jdk/test/java/awt/Frame/7024749/bug7024749.java diff --git a/jdk/src/windows/native/sun/windows/awt_Component.cpp b/jdk/src/windows/native/sun/windows/awt_Component.cpp index 9cc2f76e90b..d7b265c44e3 100644 --- a/jdk/src/windows/native/sun/windows/awt_Component.cpp +++ b/jdk/src/windows/native/sun/windows/awt_Component.cpp @@ -1474,9 +1474,7 @@ LRESULT AwtComponent::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) ::GetClientRect( GetHWnd(), &r ); mr = WmSize(static_cast(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 @@ LRESULT AwtComponent::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) // 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 @@ LRESULT AwtComponent::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) case WM_IME_SETCONTEXT: // lParam is passed as pointer and it can be modified. mr = WmImeSetContext(static_cast(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 @@ MsgRouting AwtComponent::WmPaste() // 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 @@ void AwtComponent::OpenCandidateWindow(int x, int y) 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 @@ void AwtComponent::SetCandidateWindow(int iCandType, int x, int y) 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 @@ MsgRouting AwtComponent::WmImeComposition(WORD wChar, LPARAM flags) 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 @@ void AwtComponent::InquireCandidatePosition() 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() diff --git a/jdk/src/windows/native/sun/windows/awt_Component.h b/jdk/src/windows/native/sun/windows/awt_Component.h index 3257c517516..75c1b3c9384 100644 --- a/jdk/src/windows/native/sun/windows/awt_Component.h +++ b/jdk/src/windows/native/sun/windows/awt_Component.h @@ -464,7 +464,7 @@ public: int caretPos, int visiblePos); void InquireCandidatePosition(); INLINE LPARAM GetCandidateType() { return m_bitsCandType; } - HIMC ImmGetContext(); + HWND ImmGetHWnd(); HIMC ImmAssociateContext(HIMC himc); HWND GetProxyFocusOwner(); diff --git a/jdk/src/windows/native/sun/windows/awt_FileDialog.cpp b/jdk/src/windows/native/sun/windows/awt_FileDialog.cpp index abd6e120451..d60fbd329b1 100644 --- a/jdk/src/windows/native/sun/windows/awt_FileDialog.cpp +++ b/jdk/src/windows/native/sun/windows/awt_FileDialog.cpp @@ -156,6 +156,7 @@ FileDialogHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam) HIMC hIMC = ::ImmGetContext(hdlg); if (hIMC != NULL) { ::ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0); + ::ImmReleaseContext(hdlg, hIMC); } WNDPROC lpfnWndProc = (WNDPROC)(::GetProp(parent, NativeDialogWndProcProp)); diff --git a/jdk/src/windows/native/sun/windows/awt_Frame.cpp b/jdk/src/windows/native/sun/windows/awt_Frame.cpp index 76811dfec03..da1df839535 100644 --- a/jdk/src/windows/native/sun/windows/awt_Frame.cpp +++ b/jdk/src/windows/native/sun/windows/awt_Frame.cpp @@ -319,8 +319,6 @@ LRESULT AwtFrame::ProxyWindowProc(UINT message, WPARAM wParam, LPARAM lParam, Ms 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: diff --git a/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp b/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp index 17d7c68088c..5ba2efca861 100644 --- a/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp +++ b/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp @@ -336,7 +336,8 @@ AwtTextComponent::WmPaste() //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 @@ void AwtTextComponent::SetCompositionWindow(RECT& rc) LOGFONT lf; GetObject(m_hFont, sizeof(LOGFONT), &lf); ImmSetCompositionFont(hIMC, &lf); + ImmReleaseContext(hwnd, hIMC); } //im --- end diff --git a/jdk/test/java/awt/Frame/7024749/bug7024749.java b/jdk/test/java/awt/Frame/7024749/bug7024749.java new file mode 100644 index 00000000000..5eb28b6723d --- /dev/null +++ b/jdk/test/java/awt/Frame/7024749/bug7024749.java @@ -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!"); + } +}