Buggy code:
public class PackageFragmentRoot extends Openable implements IPackageFragmentRoot { protected static final char ATTACHMENT_PROPERTY_DELIMITER = '*' ; public static final String NO_SOURCE_ATTACHMENT = "" ; protected IResource resource ; protected PackageFragmentRoot ( IResource resource , JavaProject project ) { } public void attachSource ( IPath sourcePath , IPath rootPath , IProgressMonitor monitor ) throws JavaModelException { } protected boolean buildStructure ( OpenableElementInfo info , IProgressMonitor pm , Map newElements , IResource underlyingResource ) throws JavaModelException { } SourceMapper createSourceMapper ( IPath sourcePath , IPath rootPath ) { } public void delete ( int updateResourceFlags , int updateModelFlags , IProgressMonitor monitor ) throws JavaModelException { } protected boolean computeChildren ( OpenableElementInfo info , IResource underlyingResource ) throws JavaModelException { } protected void computeFolderChildren ( IContainer folder , boolean isIncluded , String [ ] pkgName , ArrayList vChildren , char [ ] [ ] inclusionPatterns , char [ ] [ ] exclusionPatterns ) throws JavaModelException { } public void copy ( IPath destination , int updateResourceFlags , int updateModelFlags , IClasspathEntry sibling , IProgressMonitor monitor ) throws JavaModelException { } protected Object createElementInfo ( ) { } public IPackageFragment createPackageFragment ( String pkgName , boolean force , IProgressMonitor monitor ) throws JavaModelException { } protected int determineKind ( IResource underlyingResource ) throws JavaModelException { } public boolean equals ( Object o ) { } private IClasspathEntry findSourceAttachmentRecommendation ( ) { } public char [ ] [ ] fullExclusionPatternChars ( ) { } public char [ ] [ ] fullInclusionPatternChars ( ) { } public String getElementName ( ) { } public int getElementType ( ) { } protected char getHandleMementoDelimiter ( ) { } public IJavaElement getHandleFromMemento ( String token , MementoTokenizer memento , WorkingCopyOwner owner ) { } protected void getHandleMemento ( StringBuffer buff ) { IPath path ; <START_BUG> IResource underlyingResource = resource ( ) ; <END_BUG> if ( underlyingResource != null ) { if ( resource ( ) . getProject ( ) . equals ( getJavaProject ( ) . getProject ( ) ) ) { path = underlyingResource . getProjectRelativePath ( ) ; } else { path = underlyingResource . getFullPath ( ) ; } } else { path = getPath ( ) ; } ( ( JavaElement ) ( getParent ( ) ) ) . getHandleMemento ( buff ) ; buff . append ( getHandleMementoDelimiter ( ) ) ; escapeMementoName ( buff , path . toString ( ) ) ; } public int getKind ( ) throws JavaModelException { } int internalKind ( ) throws JavaModelException { } public Object [ ] getNonJavaResources ( ) throws JavaModelException { } public IPackageFragment getPackageFragment ( String packageName ) { } public PackageFragment getPackageFragment ( String [ ] pkgName ) { } protected String getPackageName ( IFolder folder ) { } public IPath getPath ( ) { } public IPath internalPath ( ) { } public IClasspathEntry getRawClasspathEntry ( ) throws JavaModelException { } public IResource resource ( ) { } public IResource resource ( PackageFragmentRoot root ) { } public IPath getSourceAttachmentPath ( ) throws JavaModelException { } public void setSourceMapper ( SourceMapper mapper ) throws JavaModelException { } public IPath getSourceAttachmentRootPath ( ) throws JavaModelException { } public SourceMapper getSourceMapper ( ) { } public IResource getUnderlyingResource ( ) throws JavaModelException { } public boolean hasChildren ( ) throws JavaModelException { } public int hashCode ( ) { } public boolean isArchive ( ) { } public boolean isExternal ( ) { } protected IStatus validateOnClasspath ( ) { } public void move ( IPath destination , int updateResourceFlags , int updateModelFlags , IClasspathEntry sibling , IProgressMonitor monitor ) throws JavaModelException { } protected void toStringInfo ( int tab , StringBuffer buffer , Object info , boolean showResolvedInfo ) { } protected IStatus validateExistence ( IResource underlyingResource ) { } protected void verifyAttachSource ( IPath sourcePath ) throws JavaModelException { } }

Fix:
IResource underlyingResource = getResource ( ) ;