Bug 581603 - NPE while sharing a Project caused by generating the gitignore file
Summary: NPE while sharing a Project caused by generating the gitignore file
Status: RESOLVED FIXED
Alias: None
Product: EGit
Classification: Technology
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: 6.5   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-27 06:01 EST by Stefan Fussenegger CLA
Modified: 2023-02-28 05:58 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Fussenegger CLA 2023-02-27 06:01:51 EST
1) Created a (custom) project
2) Project is containing a virtual Folder and file
3) Choose in Context menu: Teams->Share Project...
4) Chose git
5) Create a local repo
6) Click finish

The project has a folder {MyProject}/.internal which is a Virtual IRessources which is derived.

In org.eclipse.egit.core.op.ConnectProviderOperation.connectProject() the method autoIgnoreDerivedResources() is called which is parsing the project tree for derived folders and trying to get the path of it. It's for creating the .gitignore file. But for Virtual folders there is no path so the exception is thrown.

Could be solved by  ConnectProviderOperation.findDerivedResources() and add a check to skip virtual IRessources like:

private List<IPath> findDerivedResources(IContainer c)
			throws CoreException {
		List<IPath> derived = new ArrayList<IPath>();
		IResource[] members = c.members(IContainer.INCLUDE_HIDDEN);
		for (IResource r : members) {
			if (r.isDerived() && !r.isVirtual())
				derived.add(r.getLocation());
			else if (r instanceof IContainer && !r.isVirtual())
				derived.addAll(findDerivedResources((IContainer) r));
		}
		return derived;
	}


the thrown Exception:

java.lang.NullPointerException: undefined
     at org.eclipse.core.runtime.Path.isPrefixOf(Path.java:708)
     at org.eclipse.core.internal.localstore.FileSystemResourceManager.resourceForLocation(FileSystemResourceManager.java:307)
     at org.eclipse.core.internal.localstore.FileSystemResourceManager.fileForLocation(FileSystemResourceManager.java:487)
     at org.eclipse.core.internal.resources.WorkspaceRoot.getFileForLocation(WorkspaceRoot.java:115)
     at org.eclipse.egit.core.internal.util.ResourceUtil.getFileForLocation(ResourceUtil.java:128)
     at org.eclipse.egit.core.internal.util.ResourceUtil.getResourceForLocation(ResourceUtil.java:103)
     at org.eclipse.egit.core.internal.job.RuleUtil.getRuleForContainers(RuleUtil.java:108)
     at org.eclipse.egit.core.op.IgnoreOperation.calcSchedulingRule(IgnoreOperation.java:342)
     at org.eclipse.egit.core.op.IgnoreOperation.<init>(IgnoreOperation.java:76)
     at org.eclipse.egit.core.op.ConnectProviderOperation.autoIgnoreDerivedResources(ConnectProviderOperation.java:243)
     at org.eclipse.egit.core.op.ConnectProviderOperation.connectProject(ConnectProviderOperation.java:190)
     at org.eclipse.egit.core.op.ConnectProviderOperation.execute(ConnectProviderOperation.java:111)
     at org.eclipse.egit.ui.internal.sharing.SharingWizard$1.run(SharingWizard.java:133)
     at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:122)
Comment 1 Eclipse Genie CLA 2023-02-27 11:18:21 EST
New Gerrit change created: https://git.eclipse.org/r/c/egit/egit/+/200212
Comment 3 Stefan Fussenegger CLA 2023-02-28 02:54:22 EST
Wow, super fast. Thanks!
Comment 4 Matthias Sohn CLA 2023-02-28 05:58:59 EST
(In reply to Stefan Fussenegger from comment #3)
> Wow, super fast. Thanks!

This was easy since you provided the patch :-) 

Next time you can try pushing the fix to Gerrit yourself, see the contributor guide at https://wiki.eclipse.org/EGit/Contributor_Guide#Contributing_Patches