Buggy code:
private static final String HIERARCHY_DEBUG = ( JavaCore . PLUGIN_ID ) + "//debug//hierarchy" ; private static final String POST_ACTION_DEBUG = ( JavaCore . PLUGIN_ID ) + "//debug//postaction" ; private static final String BUILDER_DEBUG = ( JavaCore . PLUGIN_ID ) + "//debug//builder" ; private static final String COMPLETION_DEBUG = ( JavaCore . PLUGIN_ID ) + "//debug//completion" ; private static final String SELECTION_DEBUG = ( JavaCore . PLUGIN_ID ) + "//debug//selection" ; private static final String SEARCH_DEBUG = ( JavaCore . PLUGIN_ID ) + "//debug//search" ; public static final ICompilationUnit [ ] NoWorkingCopy = new ICompilationUnit [ 0 ] ; public void addElementChangedListener ( IElementChangedListener listener , int eventMask ) { } public static boolean conflictsWithOutputLocation ( IPath folderPath , JavaProject project ) { } public static IClasspathContainer containerGet ( IJavaProject project , IPath containerPath ) { } public static void containerPut ( IJavaProject project , IPath containerPath , IClasspathContainer container ) { } public static IJavaElement create ( IResource resource , IJavaProject project , WorkingCopyOwner owner ) { } public static IJavaElement create ( IFile file , IJavaProject project , WorkingCopyOwner owner ) { } public static IJavaElement create ( IFolder folder , IJavaProject project ) { } public static IClassFile createClassFileFrom ( IFile file , IJavaProject project ) { } public static ICompilationUnit createCompilationUnitFrom ( IFile file , IJavaProject project , WorkingCopyOwner owner ) { } public static IPackageFragmentRoot createJarPackageFragmentRootFrom ( IFile file , IJavaProject project ) { } public static IJavaElement determineIfOnClasspath ( IResource resource , IJavaProject project ) { } private static final JavaModelManager Manager = new JavaModelManager ( ) ; protected JavaModelCache cache = new JavaModelCache ( ) ; private PerThreadObject temporaryCache = new PerThreadObject ( ) ; protected Map elementsOutOfSynchWithBuffers = new HashMap ( 11 ) ; public final DeltaProcessor deltaProcessor = new DeltaProcessor ( this ) ; public IElementChangedListener [ ] elementChangedListeners = new IElementChangedListener [ 5 ] ; public int [ ] elementChangedListenerMasks = new int [ 5 ] ; public int elementChangedListenerCount = 0 ; public IJavaProject [ ] javaProjectsCache ; protected Map perProjectInfos = new HashMap ( 5 ) ; protected Map perWorkingCopyInfos = new HashMap ( 5 ) ; protected WeakHashMap searchScopes = new WeakHashMap ( ) ; public static class PerProjectInfo { public IProject project ; public Object savedState ; public boolean triedRead ; public IClasspathEntry [ ] rawClasspath ; public IClasspathEntry [ ] resolvedClasspath ; public Map resolvedPathToRawEntries ; public IPath outputLocation ; public Preferences preferences ; public PerProjectInfo ( IProject project ) { } public synchronized void updateClasspathInformation ( IClasspathEntry [ ] newRawClasspath ) { } } 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 static boolean VERBOSE = false ; public static boolean CP_RESOLVE_VERBOSE = false ; public static boolean ZIP_ACCESS_VERBOSE = false ; private PerThreadObject zipFiles = new PerThreadObject ( ) ; public static class PluginPreferencesListener implements Preferences . IPropertyChangeListener { public void propertyChange ( Preferences . PropertyChangeEvent event ) { } } private JavaModelManager ( ) { } public void cacheZipFiles ( ) { } public void closeZipFile ( ZipFile zipFile ) { } public void configurePluginDebugOptions ( ) { } public int discardPerWorkingCopyInfo ( CompilationUnit workingCopy ) throws JavaModelException { synchronized ( perWorkingCopyInfos ) { WorkingCopyOwner owner = workingCopy . owner ; Map pathToPerWorkingCopyInfos = ( ( Map ) ( this . perWorkingCopyInfos . get ( owner ) ) ) ; if ( pathToPerWorkingCopyInfos == null ) return - 1 ; IPath path = workingCopy . getPath ( ) ; JavaModelManager . PerWorkingCopyInfo info = ( ( JavaModelManager . PerWorkingCopyInfo ) ( pathToPerWorkingCopyInfos . get ( path ) ) ) ; if ( info == null ) return - 1 ; if ( ( -- ( info . useCount ) ) == 0 ) { <START_BUG> IJavaElement originalElement = workingCopy . getOriginalElement ( ) ; <END_BUG> pathToPerWorkingCopyInfos . remove ( path ) ; if ( pathToPerWorkingCopyInfos . isEmpty ( ) ) { this . perWorkingCopyInfos . remove ( owner ) ; } removeInfoAndChildren ( workingCopy ) ; workingCopy . closeBuffer ( ) ; if ( ! ( workingCopy . getParent ( ) . exists ( ) ) ) { ( ( CompilationUnit ) ( originalElement ) ) . close ( ) ; } } return info . useCount ; } } public void doneSaving ( ISaveContext context ) { } public void flushZipFiles ( ) { } protected Map getElementsOutOfSynchWithBuffers ( ) { } public IJavaElement getHandleFromMemento ( String memento , WorkingCopyOwner owner ) throws JavaModelException { } public IndexManager getIndexManager ( ) { } public synchronized Object getInfo ( IJavaElement element ) { } public final JavaModel getJavaModel ( ) { } public static final JavaModelManager getJavaModelManager ( ) { } public Object getLastBuiltState ( IProject project , IProgressMonitor monitor ) { } public JavaModelManager . PerProjectInfo getPerProjectInfo ( IProject project , boolean create ) { } public JavaModelManager . PerProjectInfo getPerProjectInfoCheckExistence ( IProject project ) throws JavaModelException { } public JavaModelManager . PerWorkingCopyInfo getPerWorkingCopyInfo ( CompilationUnit workingCopy , IPath path , boolean create , boolean recordUsage , IProblemRequestor problemRequestor ) { } public HashMap getTemporaryCache ( ) { } public static String [ ] getRegisteredVariableNames ( ) { } public static String [ ] getRegisteredContainerIDs ( ) { } private File getSerializationFile ( IProject project ) { } public ICompilationUnit [ ] getWorkingCopies ( WorkingCopyOwner owner , boolean addPrimary ) { } public ZipFile getZipFile ( IPath path ) throws CoreException { } public boolean hasTemporaryCache ( ) { } public void loadVariablesAndContainers ( ) throws CoreException { } protected synchronized Object peekAtInfo ( IJavaElement element ) { } public void prepareToSave ( ISaveContext context ) throws CoreException { }

Fix:
IJavaElement originalElement = workingCopy . getPrimary ( ) ;