Bug 156005 - AWT peer not found when executing Java code
AWT peer not found when executing Java code
Status: CLOSED RAWHIDE
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
4
x86_64 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
: 163671 (view as bug list)
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2005-04-26 12:03 EDT by Dave Atkinson
Modified: 2007-11-30 17:11 EST (History)
4 users (show)

See Also:
Fixed In Version: 4.0.0-13
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-06-25 15:39:29 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Output from strace -f -v -o java.output java --cp $(pwd) HelloAWT (223.61 KB, text/plain)
2005-04-30 07:31 EDT, Dave Atkinson
no flags Details

  None (edit)
Description Dave Atkinson 2005-04-26 12:03:07 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.7) Gecko/20050416 Fedora/1.0.3-2 Firefox/1.0.3

Description of problem:
Same as Bug 150453 - but I'm running fc4test2, either with or with the latest from development, I get an AWTError.  The workaround supplied in the aforementioned closed bug works too.

Version-Release number of selected component (if applicable):
gcc-4.0.0-1

How reproducible:
Always

Steps to Reproduce:
1. Try to run AWT based java program


Actual Results:  
[user@computer ~]$ java -cp `pwd` HelloAWT
Exception in thread "main" java.awt.AWTError: Cannot load AWT toolkit: gnu.java.awt.peer.gtk.GtkToolkit
   at java.awt.Toolkit.getDefaultToolkit() (/usr/lib64/libgcj.so.6.0.0)
   at java.awt.EventQueue.invokeLater(java.lang.Runnable) (/usr/lib64/libgcj.so.6.0.0)
...

Expected Results:  [user@computer ~]$ java -cp `pwd` HelloAWT
[user@computer ~]$ 

Additional info:
Comment 1 Jakub Jelinek 2005-04-26 12:19:05 EDT
Are you sure you are using libgcj-4.0.0-1?
With that and java-1.4.2-gcj-compat-1.4.2.0-40jpp_18rh it works just fine for me:
import java.awt.*;
import java.awt.event.*;

class HelloAWT extends Frame {

   private static String message = "Hello AWT!";

   HelloAWT() {
      super(message);
   }

   public void paint(Graphics g) {
      // get the windows width and height
      Dimension d = getSize();
      // get the internal margins
      Insets i = getInsets();
      // calculate the center point
      int cx = i.left + (d.width - i.left - i.right) / 2;
      int cy = i.top + (d.height - i.top - i.bottom) / 2;
      // get the attributes of the text
      FontMetrics fm = g.getFontMetrics();
      // get the width of the message
      int width = fm.stringWidth(message);
      int height = fm.getHeight();
      // draw the string
      g.drawString(message, cx - width / 2, cy + height / 2);
   }

   public static void main(String[] args) {
      // create the window
      Frame f = new HelloAWT();
      // insert event handler for exiting the application
      f.addWindowListener(
         new WindowAdapter(){
            public void windowClosing(WindowEvent e) {
               System.exit(0);
            }
         });
      f.setBounds(50, 50, 200, 200);
      f.show();
   }
}

rpm -q gcc libgcj java-1.4.2-gcj-compat; java -cp `pwd` HelloAWT
gcc-4.0.0-1
libgcj-4.0.0-1
java-1.4.2-gcj-compat-1.4.2.0-40jpp_18rh

(.:16278): Gtk-WARNING **: cannot open display:

(this is without X running, but from strace the Gtk peers are clearly loaded).
gcc-4.0.0-1 certainly has the patch mentioned in 150453.
Comment 2 Dave Atkinson 2005-04-27 10:07:40 EDT
As sure as I can be...

[user@computer ~]$ date
Wed Apr 27 15:01:54 BST 2005
[user@computer ~]$ yum -e gcc
   (snip...)
[user@computer ~]$ yum install gcc libgcj java-1.4.2-gcj-compat-devel
   (snip...)
[user@computer ~]$ rpm -q gcc libgcj java-1.4.2-gcj-compat
gcc-4.0.0-1
libgcj-4.0.0-1
java-1.4.2-gcj-compat-1.4.2.0-40jpp_18rh
[user@computer ~]$ javac HelloAWT.java && java -cp `pwd` HelloAWT
----------
1. WARNING in HelloAWT.java
 (at line 4)
        class HelloAWT extends Frame {
              ^^^^^^^^
The serializable class HelloAWT does not declare a static final serialVersionUID
field of type long
----------
1 problem (1 warning)Exception in thread "main" java.awt.AWTError: Cannot load
AWT toolkit: gnu.java.awt.peer.gtk.GtkToolkit
   at java.awt.Toolkit.getDefaultToolkit() (/usr/lib64/libgcj.so.6.0.0)
   at java.awt.Window.getToolkit() (/usr/lib64/libgcj.so.6.0.0)
   at java.awt.Frame.addNotify() (/usr/lib64/libgcj.so.6.0.0)
   at java.awt.Window.show() (/usr/lib64/libgcj.so.6.0.0)
   at HelloAWT.main(java.lang.String[]) (Unknown Source)
   at .main (/usr/lib64/libgij.so.6.0.0)
   at .__libc_start_main (/lib64/libc-2.3.5.so)
Caused by: java.lang.ClassNotFoundException: gnu.java.awt.peer.gtk.GtkToolkit
not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:/home/da/],
parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
   at java.net.URLClassLoader.findClass(java.lang.String)
(/usr/lib64/libgcj.so.6.0.0)
   at java.lang.ClassLoader.loadClass(java.lang.String, boolean)
(/usr/lib64/libgcj.so.6.0.0)
   at java.lang.ClassLoader.loadClass(java.lang.String) (/usr/lib64/libgcj.so.6.0.0)
   at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader)
(/usr/lib64/libgcj.so.6.0.0)
   at java.awt.Toolkit.getDefaultToolkit() (/usr/lib64/libgcj.so.6.0.0)
   ...6 more
[user@computer ~]$ export LD_LIBRARY_PATH=/usr/lib/gcc//x86_64-redhat-linux/4.0.0
[user@computer ~]$ java -cp `pwd` HelloAWT
   (success...)
Comment 3 Jakub Jelinek 2005-04-29 05:15:34 EDT
Can you post e.g. strace output?
I'm not alone who can't reproduce this problem.
Comment 4 Dave Atkinson 2005-04-30 07:31:48 EDT
Created attachment 113885 [details]
Output from strace -f -v -o java.output java --cp $(pwd) HelloAWT

Okay, attached is output from:

$ strace -f -v -o java.output java --cp $(pwd) HelloAWT
Comment 5 Dave Atkinson 2005-05-12 08:20:28 EDT
FWIW I just deleted the entire partition and installed FC4test3:

[da@testsys ~]$ rpm -q gcc libgcj java-1.4.2-gcj-compat
gcc-4.0.0-2
libgcj-4.0.0-2
libgcj-4.0.0-2
java-1.4.2-gcj-compat-1.4.2.0-40jpp_18rh

and I _still_ get the same problem.  Would you like an strace of that, too?
Comment 6 Thomas Fitzsimmons 2005-05-12 11:19:49 EDT
I think libgcj is looking in /usr/lib for lib-gnu-java-awt-peer-gtk.so, when it
should be looking in /usr/lib64.

Jakub, this should be fixable in the libgcj RPM, right?
Comment 7 Thomas J. Baker 2005-05-24 20:27:57 EDT
I'm seeing this type of problem with fc4t3 + may 23 updates.

neuromancer> java -jar bin/rmmlite.jar
Exception in thread "main" java.awt.AWTError: Cannot load AWT toolkit:
gnu.java.awt.peer.gtk.GtkToolkit
   at java.awt.Toolkit.getDefaultToolkit() (/usr/lib64/libgcj.so.6.0.0)
   at java.awt.EventQueue.invokeLater(java.lang.Runnable)
(/usr/lib64/libgcj.so.6.0.0)
   at javax.swing.SwingUtilities.invokeLater(java.lang.Runnable)
(/usr/lib64/libgcj.so.6.0.0)
   at javax.swing.RepaintManager.addInvalidComponent(javax.swing.JComponent)
(/usr/lib64/libgcj.so.6.0.0)
   at javax.swing.JComponent.revalidate() (/usr/lib64/libgcj.so.6.0.0)
   at javax.swing.JComponent.setOpaque(boolean) (/usr/lib64/libgcj.so.6.0.0)
   at javax.swing.JPanel.JPanel(java.awt.LayoutManager, boolean)
(/usr/lib64/libgcj.so.6.0.0)
   at javax.swing.JRootPane.createGlassPane() (/usr/lib64/libgcj.so.6.0.0)
   at javax.swing.JRootPane.getGlassPane() (/usr/lib64/libgcj.so.6.0.0)
   at javax.swing.JRootPane.JRootPane() (/usr/lib64/libgcj.so.6.0.0)
   at javax.swing.JFrame.createRootPane() (/usr/lib64/libgcj.so.6.0.0)
   at javax.swing.JFrame.getRootPane() (/usr/lib64/libgcj.so.6.0.0)
   at javax.swing.JFrame.frameInit() (/usr/lib64/libgcj.so.6.0.0)
   at javax.swing.JFrame.JFrame(java.lang.String) (/usr/lib64/libgcj.so.6.0.0)
   at com.rio.rmmlite.ChooseRmmlOrTaxi.main(java.lang.String[]) (Unknown Source)
  at .main (/usr/lib64/libgij.so.6.0.0)
   at .__libc_start_main (/lib64/libc-2.3.5.so)
Caused by: java.lang.ClassNotFoundException: gnu.java.awt.peer.gtk.GtkToolkit
not found in
gnu.gcj.runtime.SystemClassLoader{urls=[file:bin/rmmlite.jar,file:./],
parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
   at java.net.URLClassLoader.findClass(java.lang.String)
(/usr/lib64/libgcj.so.6.0.0)
   at java.lang.ClassLoader.loadClass(java.lang.String, boolean)
(/usr/lib64/libgcj.so.6.0.0)
   at java.lang.ClassLoader.loadClass(java.lang.String) (/usr/lib64/libgcj.so.6.0.0)
   at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader)
(/usr/lib64/libgcj.so.6.0.0)
   at java.awt.Toolkit.getDefaultToolkit() (/usr/lib64/libgcj.so.6.0.0)
   ...16 more
neuromancer>
Comment 8 Ryo Dairiki 2005-06-23 12:33:50 EDT
I got the same error as you.
But now I can compile and run java awt program after I ran this command:
ln -s gcc/x86_64-redhat-linux/4.0.0/lib-gnu-java-awt-peer-gtk.so /usr/lib/
Will this could be a hint?

os: fc4 x86-64
gcc(gcj): 4.0.0-8
Comment 9 Dave Atkinson 2005-06-25 13:03:59 EDT
I deleted FC4test3 and install FC4 as released, installed on a fresh partition.
 I get the same problem,
$ rpm -q gcc libgcj java-1.4.2-gcj-compat
gcc-4.0.0-8
libgcj-4.0.0-8
libgcj-4.0.0-8
java-1.4.2-gcj-compat-1.4.2.0-40jpp_31rh

I did another strace -f, it appears to me that when it comes to opening
lib-gnu-java-awt-peer-gtk.so, it is looking in /usr/lib, and trying to load the
32-bit version, then failing.  Successfully loaded libs are being looked for in
/usr/lib64...  Here's an excerpt from the trace, if it helps:
6907  access("/usr/lib/lib-gnu-java-awt-peer-gtk.so.6", R_OK) = 0
6907  access("/usr/lib/lib-gnu-java-awt-peer-gtk.so.6", R_OK) = 0
6907  open("/usr/lib/lib-gnu-java-awt-peer-gtk.so.6", O_RDONLY) = 13
6907  read(13, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0000y\3\000"...,
640) = 640
6907  close(13)                         = 0 6907 
open("/lib/lib-gnu-java-awt-peer.la", O_RDONLY) = -1 ENOENT (No such file or
directory)

This seems to be where the trouble starts.
Comment 10 Jakub Jelinek 2005-06-25 15:39:29 EDT
Should be fixed in libgcj-4.0.0-13 in rawhide.
As a workaround, you can run the Java programs with LD_LIBRARY_PATH=/usr/lib64
Comment 11 Jakub Jelinek 2005-07-20 03:10:34 EDT
*** Bug 163671 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.