Skip to main content

Possible regression: Win32 class naming for AWT Windows

3 replies [Last post]
nielm
Offline
Joined: 2006-09-21
Points: 0

(caveat: I am not an AWT developer, but a beta-tester for an AWT application)

In JRE 1.5 and earlier, the Win32 Window class name for the top-level application window was inherited from the Java class name.

In JRE 1.6, the Win32 Window class name appears to be always set to SunAwtFrame.

(This is the window class name used by the Win32 functions: RegisterClassEx(), GetClassName(), FindWindowEx() etc)

This can break other applications that use the class name as an identifier of a program's existance -- eg remote control apps such as Girder.

Is this deliberate behaviour or a regression bug?

If deliberate, is there a way to set the Win32 class name? (I could not find one in the docs).

trivial test code:
run with JRE 1.5 Win32 Class name == "Hello"
run with JRE 1.6 Win32 Class name == "SunAwtFrame"
----------

import java.awt.*;</p>
<p>public class Hello extends Frame {<br />
  public static void main(String argv[])<br />
  {<br />
    new Hello();<br />
  }<br />
  Hello() {<br />
    Label hello =<br />
             new Label("Hello World");<br />
    add(hello, "Center");<br />
    setSize(200, 200);<br />
    setVisible(true);<br />
  }<br />
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
nielm
Offline
Joined: 2006-09-21
Points: 0

Ok, so I had a quick look at the JRE source code, and the change was obvious:

in j2se/src/windows/native/sun/windows:

RegisterClassEx in awt_Component.cpp calls the virtual function GetClassName()...

In JRE 1.5, awt_Frame gets the Windows class name from the Java class name (it was the only class that did this -- all the others used hardcoded names)

In JRE 1.6, GetClassName() in awt_Frame.cpp has been substantially changed from 1.5 to use a hardcoded class name...

I wonder why...

j2se/src/windows/native/sun/windows/awt_Frame.cpp:
[code]
JRE 1.5 ===>

LPCTSTR AwtFrame::GetClassName() {

if (m_windowClassName == NULL)
{
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
if (env->EnsureLocalCapacity(2) < 0) {
m_windowClassName = new TCHAR[_tcslen(AWT_FRAME_WINDOW_CLASS_NAME) + 1];
_tcscpy(m_windowClassName,AWT_FRAME_WINDOW_CLASS_NAME);
}
else
{
jobject frame = GetTarget(env);
jclass frameClass = env->GetObjectClass(frame);

JavaStringBuffer jsb = JavaStringBuffer(env,JVM_GetClassName(env,frameClass));

m_windowClassName = new TCHAR[_tcslen(jsb) + 1];
_tcscpy(m_windowClassName,jsb);

env->DeleteLocalRef(frameClass);
env->DeleteLocalRef(frame);

}
return m_windowClassName;
}
================
JRE 1.6 ===>

LPCTSTR AwtFrame::GetClassName() {
return AWT_FRAME_WINDOW_CLASS_NAME;
}

awt_Frame.h:
#define AWT_FRAME_WINDOW_CLASS_NAME TEXT("SunAwtFrame")
==================
[/code]

trembovetski
Offline
Joined: 2003-12-31
Points: 0

This is a result of the following fix in JDK6:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4846680

Thanks,
Dmitri

nielm
Offline
Joined: 2006-09-21
Points: 0

Thanks for the very quick response...

I am not sure if the bug fix is not going to create more bugs though...