提交 5ec1d140 编写于 作者: B bagiras

8035622: [parfait] JNI exception pending in...

8035622: [parfait] JNI exception pending in jdk/src/windows/native/sun/windows/awt_DesktopProperties.cpp
Reviewed-by: pchelko, serb
上级 6b1302d8
/* /*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -83,13 +83,19 @@ void AwtDesktopProperties::GetSystemProperties() { ...@@ -83,13 +83,19 @@ void AwtDesktopProperties::GetSystemProperties() {
HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL); HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
if (dc != NULL) { if (dc != NULL) {
SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font")); try {
SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font")); SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font"));
SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font")); SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font"));
SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font")); SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font"));
SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font")); SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font"));
SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font")); SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font"));
SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font")); SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font"));
SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font"));
}
catch (std::bad_alloc&) {
DeleteDC(dc);
throw;
}
DeleteDC(dc); DeleteDC(dc);
} }
} }
...@@ -206,24 +212,35 @@ void AwtDesktopProperties::GetXPStyleProperties() { ...@@ -206,24 +212,35 @@ void AwtDesktopProperties::GetXPStyleProperties() {
LPTSTR value; LPTSTR value;
value = getXPStylePropFromReg(TEXT("ThemeActive")); value = getXPStylePropFromReg(TEXT("ThemeActive"));
SetBooleanProperty(TEXT("win.xpstyle.themeActive"), (value != NULL && *value == _T('1'))); try {
if (value != NULL) { SetBooleanProperty(TEXT("win.xpstyle.themeActive"), (value != NULL && *value == _T('1')));
free(value); if (value != NULL) {
} free(value);
value = getXPStylePropFromReg(TEXT("DllName")); value = NULL;
if (value != NULL) { }
SetStringProperty(TEXT("win.xpstyle.dllName"), value); value = getXPStylePropFromReg(TEXT("DllName"));
free(value); if (value != NULL) {
} SetStringProperty(TEXT("win.xpstyle.dllName"), value);
value = getXPStylePropFromReg(TEXT("SizeName")); free(value);
if (value != NULL) { value = NULL;
SetStringProperty(TEXT("win.xpstyle.sizeName"), value); }
free(value); value = getXPStylePropFromReg(TEXT("SizeName"));
if (value != NULL) {
SetStringProperty(TEXT("win.xpstyle.sizeName"), value);
free(value);
value = NULL;
}
value = getXPStylePropFromReg(TEXT("ColorName"));
if (value != NULL) {
SetStringProperty(TEXT("win.xpstyle.colorName"), value);
free(value);
}
} }
value = getXPStylePropFromReg(TEXT("ColorName")); catch (std::bad_alloc&) {
if (value != NULL) { if (value != NULL) {
SetStringProperty(TEXT("win.xpstyle.colorName"), value); free(value);
free(value); }
throw;
} }
} }
...@@ -564,27 +581,37 @@ void AwtDesktopProperties::GetOtherParameters() { ...@@ -564,27 +581,37 @@ void AwtDesktopProperties::GetOtherParameters() {
// Shell Icon BPP - only honored on platforms before XP // Shell Icon BPP - only honored on platforms before XP
value = getWindowsPropFromReg(TEXT("Control Panel\\Desktop\\WindowMetrics"), value = getWindowsPropFromReg(TEXT("Control Panel\\Desktop\\WindowMetrics"),
TEXT("Shell Icon BPP"), &valueType); TEXT("Shell Icon BPP"), &valueType);
if (value != NULL) {
if (valueType == REG_SZ) { try {
SetStringProperty(TEXT("win.icon.shellIconBPP"), value); if (value != NULL) {
if (valueType == REG_SZ) {
SetStringProperty(TEXT("win.icon.shellIconBPP"), value);
}
free(value);
value = NULL;
} }
free(value);
}
// The following registry settings control the file chooser places bar // The following registry settings control the file chooser places bar
// under the Windows L&F. These settings are not present by default, but // under the Windows L&F. These settings are not present by default, but
// can be enabled using the TweakUI tool from Microsoft. For more info, // can be enabled using the TweakUI tool from Microsoft. For more info,
// see http://msdn.microsoft.com/msdnmag/issues/1100/Registry/ // see http://msdn.microsoft.com/msdnmag/issues/1100/Registry/
// NoPlacesBar is a REG_DWORD, with values 0 or 1 // NoPlacesBar is a REG_DWORD, with values 0 or 1
value = getWindowsPropFromReg(TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\comdlg32"), value = getWindowsPropFromReg(TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\comdlg32"),
TEXT("NoPlacesBar"), &valueType); TEXT("NoPlacesBar"), &valueType);
if (value != NULL) { if (value != NULL) {
if (valueType == REG_DWORD) { if (valueType == REG_DWORD) {
SetBooleanProperty(TEXT("win.comdlg.noPlacesBar"), (BOOL)((int)*value != 0)); SetBooleanProperty(TEXT("win.comdlg.noPlacesBar"), (BOOL)((int)*value != 0));
}
free(value);
} }
free(value); }
catch (std::bad_alloc&) {
if (value != NULL) {
free(value);
}
throw;
} }
LPTSTR valueName = TEXT("PlaceN"); LPTSTR valueName = TEXT("PlaceN");
...@@ -592,7 +619,15 @@ void AwtDesktopProperties::GetOtherParameters() { ...@@ -592,7 +619,15 @@ void AwtDesktopProperties::GetOtherParameters() {
lstrcpy(valueNameBuf, valueName); lstrcpy(valueNameBuf, valueName);
LPTSTR propKey = TEXT("win.comdlg.placesBarPlaceN"); LPTSTR propKey = TEXT("win.comdlg.placesBarPlaceN");
LPTSTR propKeyBuf = (LPTSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, (lstrlen(propKey) + 1), sizeof(TCHAR));
LPTSTR propKeyBuf;
try {
propKeyBuf = (LPTSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, (lstrlen(propKey) + 1), sizeof(TCHAR));
}
catch (std::bad_alloc&) {
free(valueNameBuf);
throw;
}
lstrcpy(propKeyBuf, propKey); lstrcpy(propKeyBuf, propKey);
int i = 0; int i = 0;
...@@ -601,20 +636,31 @@ void AwtDesktopProperties::GetOtherParameters() { ...@@ -601,20 +636,31 @@ void AwtDesktopProperties::GetOtherParameters() {
propKeyBuf[25] = valueNameBuf[5]; propKeyBuf[25] = valueNameBuf[5];
LPTSTR key = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\comdlg32\\PlacesBar"); LPTSTR key = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\comdlg32\\PlacesBar");
if ((value = getWindowsPropFromReg(key, valueNameBuf, &valueType)) != NULL) { try {
if (valueType == REG_DWORD) { value = NULL;
// Value is a CSIDL if ((value = getWindowsPropFromReg(key, valueNameBuf, &valueType)) != NULL) {
SetIntegerProperty(propKeyBuf, (int)*value); if (valueType == REG_DWORD) {
} else { // Value is a CSIDL
// Value is a path SetIntegerProperty(propKeyBuf, (int)*value);
SetStringProperty(propKeyBuf, value); } else {
// Value is a path
SetStringProperty(propKeyBuf, value);
}
free(value);
} }
free(value); }
catch (std::bad_alloc&) {
if (value != NULL) {
free(value);
}
free(propKeyBuf);
free(valueNameBuf);
throw;
} }
} while (value != NULL); } while (value != NULL);
free(valueNameBuf);
free(propKeyBuf); free(propKeyBuf);
free(valueNameBuf);
} }
void AwtDesktopProperties::GetSoundEvents() { void AwtDesktopProperties::GetSoundEvents() {
...@@ -656,14 +702,26 @@ UINT AwtDesktopProperties::GetIntegerParameter(UINT spi) { ...@@ -656,14 +702,26 @@ UINT AwtDesktopProperties::GetIntegerParameter(UINT spi) {
void AwtDesktopProperties::SetStringProperty(LPCTSTR propName, LPTSTR value) { void AwtDesktopProperties::SetStringProperty(LPCTSTR propName, LPTSTR value) {
jstring key = JNU_NewStringPlatform(GetEnv(), propName); jstring key = JNU_NewStringPlatform(GetEnv(), propName);
if (key == NULL) {
throw std::bad_alloc();
}
jstring jValue = JNU_NewStringPlatform(GetEnv(), value);
if (jValue == NULL) {
GetEnv()->DeleteLocalRef(key);
throw std::bad_alloc();
}
GetEnv()->CallVoidMethod(self, GetEnv()->CallVoidMethod(self,
AwtDesktopProperties::setStringPropertyID, AwtDesktopProperties::setStringPropertyID,
key, JNU_NewStringPlatform(GetEnv(), value)); key, jValue);
GetEnv()->DeleteLocalRef(jValue);
GetEnv()->DeleteLocalRef(key); GetEnv()->DeleteLocalRef(key);
} }
void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) { void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) {
jstring key = JNU_NewStringPlatform(GetEnv(), propName); jstring key = JNU_NewStringPlatform(GetEnv(), propName);
if (key == NULL) {
throw std::bad_alloc();
}
GetEnv()->CallVoidMethod(self, GetEnv()->CallVoidMethod(self,
AwtDesktopProperties::setIntegerPropertyID, AwtDesktopProperties::setIntegerPropertyID,
key, (jint)value); key, (jint)value);
...@@ -672,6 +730,9 @@ void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) { ...@@ -672,6 +730,9 @@ void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) {
void AwtDesktopProperties::SetBooleanProperty(LPCTSTR propName, BOOL value) { void AwtDesktopProperties::SetBooleanProperty(LPCTSTR propName, BOOL value) {
jstring key = JNU_NewStringPlatform(GetEnv(), propName); jstring key = JNU_NewStringPlatform(GetEnv(), propName);
if (key == NULL) {
throw std::bad_alloc();
}
GetEnv()->CallVoidMethod(self, GetEnv()->CallVoidMethod(self,
AwtDesktopProperties::setBooleanPropertyID, AwtDesktopProperties::setBooleanPropertyID,
key, value ? JNI_TRUE : JNI_FALSE); key, value ? JNI_TRUE : JNI_FALSE);
...@@ -680,6 +741,9 @@ void AwtDesktopProperties::SetBooleanProperty(LPCTSTR propName, BOOL value) { ...@@ -680,6 +741,9 @@ void AwtDesktopProperties::SetBooleanProperty(LPCTSTR propName, BOOL value) {
void AwtDesktopProperties::SetColorProperty(LPCTSTR propName, DWORD value) { void AwtDesktopProperties::SetColorProperty(LPCTSTR propName, DWORD value) {
jstring key = JNU_NewStringPlatform(GetEnv(), propName); jstring key = JNU_NewStringPlatform(GetEnv(), propName);
if (key == NULL) {
throw std::bad_alloc();
}
GetEnv()->CallVoidMethod(self, GetEnv()->CallVoidMethod(self,
AwtDesktopProperties::setColorPropertyID, AwtDesktopProperties::setColorPropertyID,
key, GetRValue(value), GetGValue(value), key, GetRValue(value), GetGValue(value),
...@@ -720,6 +784,11 @@ void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID, ...@@ -720,6 +784,11 @@ void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID,
else { else {
fontName = JNU_NewStringPlatform(GetEnv(), face); fontName = JNU_NewStringPlatform(GetEnv(), face);
} }
if (fontName == NULL) {
delete[] face;
throw std::bad_alloc();
}
jint pointSize = metrics.tmHeight - jint pointSize = metrics.tmHeight -
metrics.tmInternalLeading; metrics.tmInternalLeading;
jint style = java_awt_Font_PLAIN; jint style = java_awt_Font_PLAIN;
...@@ -732,11 +801,16 @@ void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID, ...@@ -732,11 +801,16 @@ void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID,
} }
jstring key = JNU_NewStringPlatform(GetEnv(), propName); jstring key = JNU_NewStringPlatform(GetEnv(), propName);
if (key == NULL) {
GetEnv()->DeleteLocalRef(fontName);
delete[] face;
throw std::bad_alloc();
}
GetEnv()->CallVoidMethod(self, GetEnv()->CallVoidMethod(self,
AwtDesktopProperties::setFontPropertyID, AwtDesktopProperties::setFontPropertyID,
key, fontName, style, pointSize); key, fontName, style, pointSize);
GetEnv()->DeleteLocalRef(fontName);
GetEnv()->DeleteLocalRef(key); GetEnv()->DeleteLocalRef(key);
GetEnv()->DeleteLocalRef(fontName);
} }
} }
delete[] face; delete[] face;
...@@ -750,7 +824,9 @@ void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & fon ...@@ -750,7 +824,9 @@ void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & fon
jint style; jint style;
fontName = JNU_NewStringPlatform(GetEnv(), font.lfFaceName); fontName = JNU_NewStringPlatform(GetEnv(), font.lfFaceName);
if (fontName == NULL) {
throw std::bad_alloc();
}
#if 0 #if 0
HDC hdc; HDC hdc;
int pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY); int pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
...@@ -773,22 +849,31 @@ void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & fon ...@@ -773,22 +849,31 @@ void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & fon
} }
jstring key = JNU_NewStringPlatform(GetEnv(), propName); jstring key = JNU_NewStringPlatform(GetEnv(), propName);
if (key == NULL) {
GetEnv()->DeleteLocalRef(fontName);
throw std::bad_alloc();
}
GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setFontPropertyID, GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setFontPropertyID,
key, fontName, style, pointSize); key, fontName, style, pointSize);
GetEnv()->DeleteLocalRef(fontName);
GetEnv()->DeleteLocalRef(key); GetEnv()->DeleteLocalRef(key);
GetEnv()->DeleteLocalRef(fontName);
} }
void AwtDesktopProperties::SetSoundProperty(LPCTSTR propName, LPCTSTR winEventName) { void AwtDesktopProperties::SetSoundProperty(LPCTSTR propName, LPCTSTR winEventName) {
jstring key = JNU_NewStringPlatform(GetEnv(), propName); jstring key = JNU_NewStringPlatform(GetEnv(), propName);
if (key == NULL) {
throw std::bad_alloc();
}
jstring event = JNU_NewStringPlatform(GetEnv(), winEventName); jstring event = JNU_NewStringPlatform(GetEnv(), winEventName);
if (event == NULL) {
GetEnv()->DeleteLocalRef(key);
throw std::bad_alloc();
}
GetEnv()->CallVoidMethod(self, GetEnv()->CallVoidMethod(self,
AwtDesktopProperties::setSoundPropertyID, AwtDesktopProperties::setSoundPropertyID,
key, event); key, event);
GetEnv()->DeleteLocalRef(key);
GetEnv()->DeleteLocalRef(event); GetEnv()->DeleteLocalRef(event);
GetEnv()->DeleteLocalRef(key);
} }
void AwtDesktopProperties::PlayWindowsSound(LPCTSTR event) { void AwtDesktopProperties::PlayWindowsSound(LPCTSTR event) {
...@@ -814,24 +899,37 @@ Java_sun_awt_windows_WDesktopProperties_initIDs(JNIEnv *env, jclass cls) { ...@@ -814,24 +899,37 @@ Java_sun_awt_windows_WDesktopProperties_initIDs(JNIEnv *env, jclass cls) {
AwtDesktopProperties::pDataID = env->GetFieldID(cls, "pData", "J"); AwtDesktopProperties::pDataID = env->GetFieldID(cls, "pData", "J");
DASSERT(AwtDesktopProperties::pDataID != 0); DASSERT(AwtDesktopProperties::pDataID != 0);
CHECK_NULL(AwtDesktopProperties::pDataID);
AwtDesktopProperties::setBooleanPropertyID = env->GetMethodID(cls, "setBooleanProperty", "(Ljava/lang/String;Z)V"); AwtDesktopProperties::setBooleanPropertyID =
env->GetMethodID(cls, "setBooleanProperty", "(Ljava/lang/String;Z)V");
DASSERT(AwtDesktopProperties::setBooleanPropertyID != 0); DASSERT(AwtDesktopProperties::setBooleanPropertyID != 0);
CHECK_NULL(AwtDesktopProperties::setBooleanPropertyID);
AwtDesktopProperties::setIntegerPropertyID = env->GetMethodID(cls, "setIntegerProperty", "(Ljava/lang/String;I)V"); AwtDesktopProperties::setIntegerPropertyID =
env->GetMethodID(cls, "setIntegerProperty", "(Ljava/lang/String;I)V");
DASSERT(AwtDesktopProperties::setIntegerPropertyID != 0); DASSERT(AwtDesktopProperties::setIntegerPropertyID != 0);
CHECK_NULL(AwtDesktopProperties::setIntegerPropertyID);
AwtDesktopProperties::setStringPropertyID = env->GetMethodID(cls, "setStringProperty", "(Ljava/lang/String;Ljava/lang/String;)V"); AwtDesktopProperties::setStringPropertyID =
env->GetMethodID(cls, "setStringProperty", "(Ljava/lang/String;Ljava/lang/String;)V");
DASSERT(AwtDesktopProperties::setStringPropertyID != 0); DASSERT(AwtDesktopProperties::setStringPropertyID != 0);
CHECK_NULL(AwtDesktopProperties::setStringPropertyID);
AwtDesktopProperties::setColorPropertyID = env->GetMethodID(cls, "setColorProperty", "(Ljava/lang/String;III)V"); AwtDesktopProperties::setColorPropertyID =
env->GetMethodID(cls, "setColorProperty", "(Ljava/lang/String;III)V");
DASSERT(AwtDesktopProperties::setColorPropertyID != 0); DASSERT(AwtDesktopProperties::setColorPropertyID != 0);
CHECK_NULL(AwtDesktopProperties::setColorPropertyID);
AwtDesktopProperties::setFontPropertyID = env->GetMethodID(cls, "setFontProperty", "(Ljava/lang/String;Ljava/lang/String;II)V"); AwtDesktopProperties::setFontPropertyID =
env->GetMethodID(cls, "setFontProperty", "(Ljava/lang/String;Ljava/lang/String;II)V");
DASSERT(AwtDesktopProperties::setFontPropertyID != 0); DASSERT(AwtDesktopProperties::setFontPropertyID != 0);
CHECK_NULL(AwtDesktopProperties::setFontPropertyID);
AwtDesktopProperties::setSoundPropertyID = env->GetMethodID(cls, "setSoundProperty", "(Ljava/lang/String;Ljava/lang/String;)V"); AwtDesktopProperties::setSoundPropertyID =
env->GetMethodID(cls, "setSoundProperty", "(Ljava/lang/String;Ljava/lang/String;)V");
DASSERT(AwtDesktopProperties::setSoundPropertyID != 0); DASSERT(AwtDesktopProperties::setSoundPropertyID != 0);
CHECK_NULL(AwtDesktopProperties::setSoundPropertyID);
CATCH_BAD_ALLOC; CATCH_BAD_ALLOC;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册