Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 351543 - NPE in PullResult call()
Summary: NPE in PullResult call()
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 1.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 1.2   Edit
Assignee: Kevin Sawicki CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-08 06:54 EDT by ZFabrik Mising name CLA
Modified: 2011-11-29 20:50 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ZFabrik Mising name CLA 2011-07-08 06:54:38 EDT
Hi

issuing a pull command in jgit-1.0.0.201106090707-r leads to NPE:

Caused by: java.lang.NullPointerException
	at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:149)


The source is like this:

public PullResult call() throws WrongRepositoryStateException,
			InvalidConfigurationException, DetachedHeadException,
			InvalidRemoteException, CanceledException, RefNotFoundException {
	checkCallable();

	monitor.beginTask(JGitText.get().pullTaskName, 2);

	String branchName;
	try {
		String fullBranch = repo.getFullBranch();
[149]		if (!fullBranch.startsWith(Constants.R_HEADS)) {
                    ...

Let's look into method getFullBranch():

public String getFullBranch() throws IOException {
	Ref head = getRef(Constants.HEAD);
	if (head == null)
		return null;
	if (head.isSymbolic())
		return head.getTarget().getName();
	if (head.getObjectId() != null)
		return head.getObjectId().name();
	return null;
}

Obviously getFullBranch() can return null in which case fullBranch.startsWith() will throw a NPE.

Best Regards
Udo
Comment 1 ZFabrik Mising name CLA 2011-07-11 05:01:31 EDT
I think the exception is thrown when the Git object is created from a FileRepository instance that points to the work-dir folder instead of the .git folder inside.

So an illegal argument is causing this problem. But IMHO a better explanation would be helpful.

Regards
Udo
Comment 2 Kevin Sawicki CLA 2011-11-22 19:28:50 EST
Proposed fix pushed to: http://egit.eclipse.org/r/4668
Comment 3 Kevin Sawicki CLA 2011-11-29 20:49:47 EST
Merged to master as commit c3fe50bb18ed4e4e5e563172be4076fa5901a18a
Comment 4 Kevin Sawicki CLA 2011-11-29 20:50:04 EST
Marking fixed in 1.2.0