JFrame called Ghost doesn't show

P

Paul Hamaker

Just found out that a JFrame called Ghost won't show. Inside joke,
easter egg?
 
C

Chris Uppal

Paul said:
Just found out that a JFrame called Ghost won't show. Inside joke,
easter egg?

Works for me with 1.5.0 on WinXP. What JDK/OS are you using ?

-- chris
 
P

Paul Hamaker

I really wasn't kidding, what's up what this, no harm in trying it
yourself :

public class Ghost extends javax.swing.JFrame {
public static void main(String[] args) {
Ghost app=new Ghost();
app.setSize(400,300);
app.setVisible(true);
}
}

I ran it on WinXP home Java1.5.0_06.
 
L

Luke Webber

Paul said:
I really wasn't kidding, what's up what this, no harm in trying it
yourself :

public class Ghost extends javax.swing.JFrame {
public static void main(String[] args) {
Ghost app=new Ghost();
app.setSize(400,300);
app.setVisible(true);
}
}

I ran it on WinXP home Java1.5.0_06.

Hey, you're right. Spooky! <g>

Luke
 
A

Andrew T.

Paul said:
I really wasn't kidding,

Your initial post had me believing you were (and you had a
very strange sense of humor - not that that's a bad thing)
...what's up what this, no harm in trying it
yourself :

I prefer a self contained demo., which also tests the assertion
that the frame's title has something to do with it. That was
suggested in the Sun thread.

<sscce>
import java.awt.*;
import javax.swing.*;

class Ghost extends JFrame {
Ghost() {
setPreferredSize(new Dimension(200,200));
getContentPane().add( new JLabel("Boo!") );
pack();
}
}

class Spirit extends JFrame {
Spirit() {
setPreferredSize(new Dimension(200,200));
getContentPane().add( new JLabel("Drink!") );
pack();
}
}

class TestGhost {
public static void main(String[] args) {
Ghost ghost1 = new Ghost();
Ghost ghost2 = new Ghost();
ghost2.setTitle("Spirit");

ghost1.setVisible(true);
System.out.println( "ghost1: " + ghost1.getTitle() );
ghost2.setVisible(true);
System.out.println( "ghost2: " + ghost2.getTitle() );

Spirit ghost3 = new Spirit();
Spirit ghost4 = new Spirit();
ghost4.setTitle("Ghost");

ghost3.setVisible(true);
System.out.println( "ghost3: " + ghost3.getTitle() );
ghost4.setVisible(true);
System.out.println( "ghost4: " + ghost4.getTitle() );

JPanel p = new JPanel( new BorderLayout() );
JTextArea ta = new JTextArea();
ta.append(System.getProperty("java.version") + "\n");
ta.append(System.getProperty("os.name") + "\n") ;
ta.append( ghost1.isVisible() + " " ) ;
ta.append( ghost2.isVisible() + " " ) ;
ta.append( ghost3.isVisible() + " " ) ;
ta.append( ghost4.isVisible() + " " ) ;

JOptionPane.showMessageDialog( (Component)null, ta );
}
}
</sscce>

My results here are..
1.5.0-beta
Windows XP
true true true true

While only the two 'Spirit' class frames actually show.

Andrew T.
 
A

Andrew T.

Andrew said:
..only the two 'Spirit' class frames actually show.

This problem also affects any class called 'Ghost'
which extends java.awt.Frame. The problem does
not seem to affect a Window.

Andrew T.
 
P

PofN

Paul said:
Just found out that a JFrame called Ghost won't show. Inside joke,
easter egg?

Bug caused by a hack.

Dialogs always need a parent frame. If you don't provide one Java
creates an internal, empty and hidden one, a "Ghost". Such a frame
should never be shown. Some idiot at Sun descided to use the title as a
"never show" flag. How that got past Sun's QA? Well, Sun doesn't have a
QA.
 
A

Andrew T.

Andrew T. wrote:

If you further alter this source to extend Ghost..
<sscce>
import java.awt.*;
import javax.swing.*;

class Ghost extends JFrame {
Ghost() {
setPreferredSize(new Dimension(200,200));
getContentPane().add( new JLabel("Boo!") );
pack();
}
}

class GhostChild extends Ghost {
GhostChild() {
super();
}
}

......
class TestGhost {
public static void main(String[] args) {
Ghost ghost1 = new Ghost();

GhostChild ghost2 = new GhostChild();

....

GhostChild appears OK.

This problem seems very specific to sub-classes of
Frame/JFrame called 'Ghost', but not their children.

So far, we only have test results for Windows boxes
(AFAIU), I would be interested to hear any test results
for other OS's.

Andrew T.
 
A

Andrew T.

PofN said:
Bug caused by a hack.

Dialogs always need a parent frame. If you don't provide one Java
creates an internal, empty and hidden one, a "Ghost".

What leads to to that conclusion?

My investigations suggest otherwise.
1. This affects AWT as well as Swing, and the programmer
must specify an owner for AWT dialogs - without exception.
2. Tracing the JDialog source back suggests that when it is
constructed with no owner, it ends up with a SharedOwnerFrame
(extending Frame) defined in SwingUtilities.
3. The string 'ghost' only appears once in any source* within the
java or javax packages (and it is a non-relevant hit in a java.net
class)

* J2SDK 1.5.0 (an early version)

Did I miss something?

Andrew T.
 
C

Chris Uppal

Paul said:
Did you run something like this ? default package ?

public class Ghost extends javax.swing.JFrame {
public static void main(String[] args) {
new Ghost().setVisible(true);
}
}

No, I had understood you to be talking about the name of the frame, not the
name of the class it is an instance of.

Trying it (with AWT frames), I see exactly what you are seeing ;-)
Interesting...

It seems only to happen on Windows -- at least, a quick test with a 1.4 JVM on
Linux did not show the effect.

I spent some time trying to find the source of the effect in the code -- in
fact I wasted most of yesterday :-( Couldn't find it.

The string "Ghost" does not appear in JVM.DLL (case-insensitive). It appears
as a "utf8" constant pool entry in only two classes in rt.jar, neither of which
is relevant (the name of the constant static integer field,
sun.awt.shell.Win32ShellFolder2.ATTRIB_GHOSTED, and the method name
java.net.authenticator.requestingHost()).

At the implementation level (in case anyone's interested), the call to
setVisible(true) ends up in the peer's native method
sun.awt.windows.WComponentPeer.pShow(). The JNI implementation just sends a
custom Windows message with value 0x8004 to the real Windows window. That
message is ignored if the AWT frame's class is named "Ghost", and acted on
otherwise. There is no conditional code in the place where the message is
received. I can show/hide the Window by using the normal Win32 APIs directly
but not by using them to send the custom message. I'm pretty sure that's
because the Windows windows has not been set up with a WindProc, whereas all
other Frames have one. I haven't been able to find any conditional code to
cause that effect, however, and having spent too long getting that far, I just
gave up.

The fact that it /is/ so well hidden, suggests that the Easter egg theory may
be correct. Surely legitimate code (even /bad/ legitimate code as suggested by
"PofN") wouldn't actually be hidden...

-- chris
 
A

Andrew T.

Chris said:
Paul Hamaker wrote: ...
public class Ghost extends javax.swing.JFrame {
public static void main(String[] args) {
new Ghost().setVisible(true);
}
}
...
Interesting...

It seems only to happen on Windows -- at least, a quick test with a 1.4 JVM on
Linux did not show the effect.

I spent some time trying to find the source of the effect in the code --

(not resolved)
...
The fact that it /is/ so well hidden, suggests that the Easter egg theory may
be correct. Surely legitimate code (even /bad/ legitimate code as suggested by
"PofN") wouldn't actually be hidden...

Now that it is established as a bug specific to Windows,
do you intend to lodge a bug-report, Paul?

I think it's important it be 'findable' in the bug database,
even if only as a warning* to other developers.

* Assuming Sun decides it is not worth fixing.

Andrew T.
 
P

Paul Hamaker

Andrew T. schreef:
Where? I cannot see it amongst these results.
My report has been assigned an internal review ID of 745063, which is
NOT visible on the Sun Developer Network (SDN).
 
A

Andrew Thompson

Paul said:
Andrew T. schreef:
My report has been assigned an internal review ID of 745063, which is
NOT visible on the Sun Developer Network (SDN).

Maybe a bug mentioning the word 'ghost' suffers the
same fate as a Frame. ;-)

Andrew T.
 
T

Thomas Hawtin

Andrew said:
Maybe a bug mentioning the word 'ghost' suffers the
same fate as a Frame. ;-)

I've got an "incident review" without a bug ID involving Swing 'Timer'
not firing that must be two and a half years old. Mind you, I have
changed e-mail address in that period.

Tom Hawtin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top