Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 320524

Summary: a call to swing UIManager.setLookAndFeel makes SWT freeze (proof with MessageBox) under linux/gtk
Product: [Eclipse Project] Platform Reporter: SamThiriot <samuel.thiriot.tmp20100720>
Component: SWTAssignee: Silenio Quarti <Silenio_Quarti>
Status: RESOLVED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: pwebster, remy.suen, samuel.thiriot.tmp20100720
Version: 3.5.2   
Target Milestone: ---   
Hardware: PC   
OS: Linux-GTK   
Whiteboard:
Attachments:
Description Flags
java testcase none

Description SamThiriot CLA 2010-07-21 11:52:28 EDT
Build Identifier: Build id: M20070212-1330 (Ubuntu version: 3.2.2-5ubuntu2)

The purpose is to melt swing and SWT (even if a bad idea, it is sometimes mandatory). The main dialog is a SWT one. After calling the Swing method UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()), many SWT dialogs freeze; for instance, closing a MessageBox illustrates the problem. 

Some first insights: 
- a call to UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel") does NOT create problem; in practice, this javax.swing.UIManagerClass.setLookAndFeel to avoid reflection by instanciating a new javax.swing.plaf.metal.MetalLookAndFeel()
- a call to UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()), which in my case resolves to "com.sun.java.swing.plaf.gtk.GTKLookAndFeel", DOES create a problem; in this case javax.swing.UIManagerClass.setLookAndFeel loads the case from the gtk library.

Problem found using :
- swt-3.5.2-gtk-linux-x86.zip, which comes with libswt-(atk,awt,cairo,pi,-xulrunner[...])-gtk-3557.so
- system is linux ubuntu intrepid 8.10 with recent distribution updates
- window manager is Gnome 2.24.1

- 

Reproducible: Always

Steps to Reproduce:
1. create a SWT Shell
2. UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()) 
3. display a MessageBox; on close, the application hangs
Comment 1 SamThiriot CLA 2010-07-21 11:58:58 EDT
Created attachment 174875 [details]
java testcase 

Add SWT native libraries and Java classes in classpath 

java -Djava.library.path=<pathToNative> -classpath .:swt.jar test1.TestLock
Comment 2 SamThiriot CLA 2010-07-21 12:05:42 EDT
About the java testcase added: 
- (1) check that MessageBox behaves without problem before calling UIManage
- (2) clic the second button to call UIManager.setLookAndFeel
- (3) problem occurs when clicking again the first button for displaying the message box; application freeze when closing the messagebox

Problem occurs in my configuration (linux ubuntu intrepid / gtk) with 
- java-6-sun-1.6.0.14
- java-1.5.0-gcj-4.3-1.5.0.0

No problem observed using java-1.5.0-sun-1.5.0.19 because gtk don't even tries to load the relevant look and feel, and dies with "/usr/share/themes/Human/gtk-2.0/gtkrc:43: error: lexical error or unexpected token, expected valid token", which is a side error without interest at first look.
Comment 3 SamThiriot CLA 2010-07-21 12:13:34 EDT
Similar problem submitted by someone else in another website 
http://java.itags.org/java-swing/13590/
Comment 4 Silenio Quarti CLA 2011-04-04 10:28:42 EDT
This problem happens because AWT/Swing initializes GTK threads by calling gdk_threads_init() when the GTK look and feel is used.  The lock use by GTK is not reentrant. See bug#280649 for more info.

*** This bug has been marked as a duplicate of bug 280649 ***