Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 156005 - AWT peer not found when executing Java code
Summary: AWT peer not found when executing Java code
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: gcc
Version: 4
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
: 163671 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2005-04-26 16:03 UTC by Dave Atkinson
Modified: 2007-11-30 22:11 UTC (History)
4 users (show)

Fixed In Version: 4.0.0-13
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2005-06-25 19:39:29 UTC


Attachments (Terms of Use)
Output from strace -f -v -o java.output java --cp $(pwd) HelloAWT (deleted)
2005-04-30 11:31 UTC, Dave Atkinson
no flags Details

Description Dave Atkinson 2005-04-26 16:03:07 UTC
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 16:19:05 UTC
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 14:07:40 UTC
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 09:15:34 UTC
Can you post e.g. strace output?
I'm not alone who can't reproduce this problem.

Comment 4 Dave Atkinson 2005-04-30 11:31:48 UTC
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 12:20:28 UTC
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 15:19:49 UTC
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-25 00:27:57 UTC
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 16:33:50 UTC
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 17:03:59 UTC
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 19:39:29 UTC
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 07:10:34 UTC
*** 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.