Buggy code:
static final Object [ ] [ ] NO_PARTICIPANTS = new Object [ 0 ] [ ] ; public class CompilationParticipants { private final int MAX_SOURCE_LEVEL = 6 ; private Object [ ] [ ] registeredParticipants = null ; public CompilationParticipant [ ] getCompilationParticipants ( IJavaProject project ) { } private Object [ ] [ ] getRegisteredParticipants ( ) { } private int indexForSourceLevel ( String sourceLevel ) { } private int sortParticipants ( ArrayList group , IConfigurationElement [ ] configElements , int index ) { } } public final JavaModelManager . CompilationParticipants compilationParticipants = new JavaModelManager . CompilationParticipants ( ) ; public static boolean conflictsWithOutputLocation ( IPath folderPath , JavaProject project ) { } public synchronized IClasspathContainer containerGet ( IJavaProject project , IPath containerPath ) { } private synchronized Map containerClone ( IJavaProject project ) { } private HashSet containerInitializationInProgress ( IJavaProject project ) { } public synchronized void containerPut ( IJavaProject project , IPath containerPath , IClasspathContainer container ) { } public boolean containerPutIfInitializingWithSameEntries ( IPath containerPath , IJavaProject [ ] projects , IClasspathContainer [ ] respectiveContainers ) { } private void containerRemoveInitializationInProgress ( IJavaProject project , IPath containerPath ) { } private synchronized void containersReset ( String [ ] containerIDs ) { } public static IJavaElement create ( IResource resource , IJavaProject project ) { } public static IJavaElement create ( IFile file , IJavaProject project ) { } public static IJavaElement create ( IFolder folder , IJavaProject project ) { } public static IClassFile createClassFileFrom ( IFile file , IJavaProject project ) { } public static ICompilationUnit createCompilationUnitFrom ( IFile file , IJavaProject project ) { } public static IPackageFragmentRoot createJarPackageFragmentRootFrom ( IFile file , IJavaProject project ) { } public static IJavaElement determineIfOnClasspath ( IResource resource , IJavaProject project ) { } private static JavaModelManager MANAGER = new JavaModelManager ( ) ; private JavaModelCache cache ; private ThreadLocal temporaryCache = new ThreadLocal ( ) ; protected HashSet elementsOutOfSynchWithBuffers = new HashSet ( 11 ) ; public DeltaProcessingState deltaState = new DeltaProcessingState ( ) ; public IndexManager indexManager = new IndexManager ( ) ; protected Map perProjectInfos = new HashMap ( 5 ) ; protected Map perWorkingCopyInfos = new HashMap ( 5 ) ; protected WeakHashMap searchScopes = new WeakHashMap ( ) ; public static class PerProjectInfo { private static final int JAVADOC_CACHE_INITIAL_SIZE = 10 ; public IProject project ; public Object savedState ; public boolean triedRead ; public IClasspathEntry [ ] rawClasspath ; public IClasspathEntry [ ] resolvedClasspath ; public Map resolvedPathToRawEntries ; public IPath outputLocation ; public IEclipsePreferences preferences ; public Hashtable options ; public Hashtable secondaryTypes ; public LRUCache javadocCache ; public PerProjectInfo ( IProject project ) { } public void rememberExternalLibTimestamps ( ) { } public synchronized void updateClasspathInformation ( IClasspathEntry [ ] newRawClasspath ) { } public String toString ( ) { } } public static class PerWorkingCopyInfo implements IProblemRequestor { int useCount = 0 ; IProblemRequestor problemRequestor ; ICompilationUnit workingCopy ; public PerWorkingCopyInfo ( ICompilationUnit workingCopy , IProblemRequestor problemRequestor ) { } public void acceptProblem ( IProblem problem ) { } public void beginReporting ( ) { } public void endReporting ( ) { } public ICompilationUnit getWorkingCopy ( ) { } public boolean isActive ( ) { } public String toString ( ) { } } public static boolean VERBOSE = false ; public static boolean CP_RESOLVE_VERBOSE = false ; public static boolean ZIP_ACCESS_VERBOSE = false ; private ThreadLocal zipFiles = new ThreadLocal ( ) ; public static class EclipsePreferencesListener implements IEclipsePreferences . IPreferenceChangeListener { public void preferenceChange ( IEclipsePreferences . PreferenceChangeEvent event ) { } } private JavaModelManager ( ) { } private void addDeprecatedOptions ( Hashtable options ) { } public void cacheZipFiles ( ) { } public void closeZipFile ( ZipFile zipFile ) { } public void configurePluginDebugOptions ( ) { } public int discardPerWorkingCopyInfo ( CompilationUnit workingCopy ) throws JavaModelException { JavaElementDeltaBuilder deltaBuilder = null ; <START_BUG> if ( workingCopy . isPrimary ( ) ) { <END_BUG> deltaBuilder = new JavaElementDeltaBuilder ( workingCopy ) ; } JavaModelManager . PerWorkingCopyInfo info = null ; synchronized ( this . perWorkingCopyInfos ) { WorkingCopyOwner owner = workingCopy . owner ; Map workingCopyToInfos = ( ( Map ) ( this . perWorkingCopyInfos . get ( owner ) ) ) ; if ( workingCopyToInfos == null ) return - 1 ; info = ( ( JavaModelManager . PerWorkingCopyInfo ) ( workingCopyToInfos . get ( workingCopy ) ) ) ; if ( info == null ) return - 1 ; if ( ( -- ( info . useCount ) ) == 0 ) { workingCopyToInfos . remove ( workingCopy ) ; if ( workingCopyToInfos . isEmpty ( ) ) { this . perWorkingCopyInfos . remove ( owner ) ; } } } if ( ( info . useCount ) == 0 ) { removeInfoAndChildren ( workingCopy ) ; workingCopy . closeBuffer ( ) ; if ( deltaBuilder != null ) { deltaBuilder . buildDeltas ( ) ; if ( ( ( deltaBuilder . delta ) != null ) && ( ( deltaBuilder . delta . getAffectedChildren ( ) . length ) > 0 ) ) { getDeltaProcessor ( ) . registerJavaModelDelta ( deltaBuilder . delta ) ; } } } return info . useCount ; } public void doneSaving ( ISaveContext context ) { } public void flushZipFiles ( ) { } public IClasspathContainer getClasspathContainer ( IPath containerPath , IJavaProject project ) throws JavaModelException { } public DeltaProcessor getDeltaProcessor ( ) { } protected HashSet getElementsOutOfSynchWithBuffers ( ) { } public IndexManager getIndexManager ( ) { } public synchronized Object getInfo ( IJavaElement element ) { } public IEclipsePreferences getInstancePreferences ( ) { } public Hashtable getDefaultOptions ( ) { } public IEclipsePreferences getDefaultPreferences ( ) { } public final JavaModel getJavaModel ( ) { } public static final JavaModelManager getJavaModelManager ( ) { } public Object getLastBuiltState ( IProject project , IProgressMonitor monitor ) { } public String getOption ( String optionName ) { }

Fix:
if ( ( workingCopy . isPrimary ( ) ) && ( workingCopy . hasUnsavedChanges ( ) ) ) {