### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/UserLibraryManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/UserLibraryManager.java,v retrieving revision 1.9 diff -u -r1.9 UserLibraryManager.java --- model/org/eclipse/jdt/internal/core/UserLibraryManager.java 10 May 2006 18:03:47 -0000 1.9 +++ model/org/eclipse/jdt/internal/core/UserLibraryManager.java 19 Mar 2007 07:42:33 -0000 @@ -42,6 +42,7 @@ public final static String CP_ENTRY_IGNORE = "####"; //$NON-NLS-1$ private static Map userLibraries; + private static boolean userLibrariesInitialized = false; private static final boolean logProblems= false; private static IEclipsePreferences.IPreferenceChangeListener listener= new IEclipsePreferences.IPreferenceChangeListener() { @@ -49,7 +50,7 @@ String key= event.getKey(); if (key.startsWith(CP_USERLIBRARY_PREFERENCES_PREFIX)) { try { - recreatePersistedUserLibraryEntry(key, (String) event.getNewValue(), false, true); + recreatePersistedUserLibraryEntry(key, (String) event.getNewValue(), false, true, true); } catch (JavaModelException e) { if (logProblems) { Util.log(e, "Exception while rebinding user library '"+ key.substring(CP_USERLIBRARY_PREFERENCES_PREFIX.length()) +"'."); //$NON-NLS-1$ //$NON-NLS-2$ @@ -74,6 +75,12 @@ return (String[]) set.toArray(new String[set.size()]); } + private static synchronized void allocateUserLibraries() { + if (userLibraries == null) { + userLibraries = new HashMap(); + } + } + /** * Gets the library for a given name or null if no such library exists. * @param name The name of the library @@ -102,7 +109,7 @@ try { int last= newNames.length - 1; for (int i= 0; i < newLibs.length; i++) { - internalSetUserLibrary(newNames[i], newLibs[i], i == last, true, new SubProgressMonitor(monitor, 1)); + internalSetUserLibrary(newNames[i], newLibs[i], i == last, true, true, new SubProgressMonitor(monitor, 1)); } } finally { monitor.done(); @@ -118,12 +125,13 @@ * @throws JavaModelException */ public static void setUserLibrary(String name, UserLibrary library, IProgressMonitor monitor) throws JavaModelException { - internalSetUserLibrary(name, library, true, true, monitor); + internalSetUserLibrary(name, library, true, true, true, monitor); } static Map getLibraryMap() { - if (userLibraries == null) { - userLibraries= new HashMap(); + if (! userLibrariesInitialized) { + allocateUserLibraries(); + // load variables and containers from preferences into cache IEclipsePreferences instancePreferences = JavaModelManager.getJavaModelManager().getInstancePreferences(); instancePreferences.addPreferenceChangeListener(listener); @@ -137,7 +145,7 @@ try { String propertyValue = instancePreferences.get(propertyName, null); if (propertyValue != null) - recreatePersistedUserLibraryEntry(propertyName,propertyValue, false, false); + recreatePersistedUserLibraryEntry(propertyName,propertyValue, false, false, false); } catch (JavaModelException e) { // won't happen: no rebinding } @@ -146,38 +154,46 @@ } catch (BackingStoreException e) { // nothing to do in this case } + userLibrariesInitialized = true; } return userLibraries; } - static void recreatePersistedUserLibraryEntry(String propertyName, String savedString, boolean save, boolean rebind) throws JavaModelException { + static void recreatePersistedUserLibraryEntry(String propertyName, String savedString, boolean save, boolean rebind, boolean getLibraryMap) throws JavaModelException { String libName= propertyName.substring(CP_USERLIBRARY_PREFERENCES_PREFIX.length()); if (savedString == null || savedString.equals(CP_ENTRY_IGNORE)) { - internalSetUserLibrary(libName, null, save, rebind, null); + internalSetUserLibrary(libName, null, save, rebind, getLibraryMap, null); } else { try { StringReader reader = new StringReader(savedString); UserLibrary library= UserLibrary.createFromString(reader); - internalSetUserLibrary(libName, library, save, rebind, null); + internalSetUserLibrary(libName, library, save, rebind, getLibraryMap, null); } catch (IOException e) { if (logProblems) { Util.log(e, "Exception while retrieving user library '"+ propertyName +"', library will be removed."); //$NON-NLS-1$ //$NON-NLS-2$ } - internalSetUserLibrary(libName, null, save, rebind, null); + internalSetUserLibrary(libName, null, save, rebind, getLibraryMap, null); } } } - static void internalSetUserLibrary(String name, UserLibrary library, boolean save, boolean rebind, IProgressMonitor monitor) throws JavaModelException { + static void internalSetUserLibrary(String name, UserLibrary library, boolean save, boolean rebind, boolean getLibraryMap, IProgressMonitor monitor) throws JavaModelException { + if (getLibraryMap) { + if (! userLibrariesInitialized) { + getLibraryMap(); + } + } else if (userLibraries == null) { // should not happen except on direct external call + allocateUserLibraries(); + } if (library == null) { - Object previous= getLibraryMap().remove(name); + Object previous= userLibraries.remove(name); if (previous == null) { return; // no change } } else { - Object previous= getLibraryMap().put(name, library); + Object previous= userLibraries.put(name, library); if (library.equals(previous)) { return; // no change }