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

Bug 132868

Summary: PaletteViewer/DefaultPaletteViewerPreferences fails to initialize in certain case
Product: [Tools] GEF Reporter: Scott Barkley <scott.g.barkley>
Component: GEF-Legacy GEF (MVC)Assignee: Cherie Revells <crevells>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: scott.g.barkley
Version: 3.1.1   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Scott Barkley CLA 2006-03-22 12:14:50 EST
The issue described affects the classes:
org.eclipse.gef.ui.palette.PaletteViewer
org.eclipse.gef.ui.palette.DefaultPaletteViewerPreferences
in (at least) GEF 3.1.0, 3.1.1, and the currently commited files in 3.2.

PaletteViewer fails to initialize (with a java.lang.ExceptionInInitializerError) when it is accessed in an RCP application in which the GEF plug-in is not installed, but rather the GEF code is accessed via a jar in a common plug-in, as follows:

Plugin 'Common' shows 'org.eclipse.gef_3.1.1.jar' (with a plain jar icon) in the Libraries tab of the Java Build Path dialog, and also shows that jar as exported on the Order and Export tab.

Plugin 'x' shows 'Common' as a Required Plug-in on the Dependencies tab of its plug-in manifest, and can access all of the GEF code via 'Common'.


The cause of the problem is on line 88 of PaletteViewer:

private static final PaletteViewerPreferences PREFERENCE_STORE = new DefaultPaletteViewerPreferences();

In the default constructor to DefaultPaletteViewerPreferences, the call to GEFPlugin.getDefault().getPreferenceStore() fails because
1) GEFPlugin() has not been called to initialize the singleton, and if that
is remedied, then 
2) the call to AbstractUIPlugin.getPreferenceStore() fails because Plugin.getBundle() returns null.
(InternalGEFPlugin in the 3.2 builds will have the same problem)


Potential ways to resolve include:

1) Handling exception in DefaultPaletteViewerPreferences() to quietly initialize to useless if it can't get the preference store it wants.

2) Removing the definition of PREFERENCE_STORE as a constant in PaletteViewer.  That constant is only used once, to initialize a private field, which could be done elsewhere in such a way as to quietly initialize the field to null if needed.  This would be a nice, localized fix and easy for developers to work with due to the availability of the public PaletteViewer.setPaletteViewerPreferences(PaletteViewerPreferences) method.  Then, if a preference store has not been set and the default is unavailable, the developer can cleanly fix the problem with a preference store from elsewhere.
Comment 1 Steven R. Shaw CLA 2006-03-22 12:27:17 EST
Why wouldn't the GEF plug-in be installed in the RCP target?
Comment 2 Scott Barkley CLA 2006-03-22 14:07:39 EST
(In reply to comment #1)
> Why wouldn't the GEF plug-in be installed in the RCP target?

Because it is not generally necessary for GEF to exist _as a plug-in_ on the target system.  Access to the API is required, but not to any of the plug-in-ness of GEF.  Similar situation for a number of others (many needed in multiple application plug-ins), so the decision was made to pull the source into one common place and make it accessible from there.
Comment 3 Randy Hudson CLA 2006-03-25 13:27:36 EST
GEF can not be used outside of its plug-in.
Comment 4 Randy Hudson CLA 2006-03-25 13:29:15 EST
As you've found out, parts of the GEF API rely on it being a plug-in. The exception you've found would just be the first of many.