[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] NPE when calling RepositoryCache.FileKey.isGitRepository on a relative path

Hello Matthias,
it does fail for me (though I tried to run it not from JGit but posted the code to the dependent project).

The stack trace is

java.lang.NullPointerException
	at org.eclipse.jgit.util.FS$FileStoreAttributeCache.getFsTimestampResolution(FS.java:205)
	at org.eclipse.jgit.util.FS.getFsTimerResolution(FS.java:323)
	at org.eclipse.jgit.internal.storage.file.FileSnapshot.<init>(FileSnapshot.java:186)
	at org.eclipse.jgit.internal.storage.file.FileSnapshot.save(FileSnapshot.java:122)
	at org.eclipse.jgit.storage.file.FileBasedConfig.load(FileBasedConfig.java:159)
	at org.eclipse.jgit.lib.BaseRepositoryBuilder.loadConfig(BaseRepositoryBuilder.java:771)
	at org.eclipse.jgit.lib.BaseRepositoryBuilder.getConfig(BaseRepositoryBuilder.java:748)
	at org.eclipse.jgit.lib.BaseRepositoryBuilder.guessWorkTreeOrFail(BaseRepositoryBuilder.java:784)
	at org.eclipse.jgit.lib.BaseRepositoryBuilder.setupWorkTree(BaseRepositoryBuilder.java:709)
	at org.eclipse.jgit.lib.BaseRepositoryBuilder.setup(BaseRepositoryBuilder.java:624)
	at org.eclipse.jgit.lib.RepositoryCache$FileKey.getGitRepository(RepositoryCache.java:519)
	at org.eclipse.jgit.lib.RepositoryCache$FileKey.isGitRepository(RepositoryCache.java:500)

I wonder how does

        new File("repo.git").toPath().getParent()

line evaluate in your environment?

I've attached several screenshots of my debugger, the last one shows why the NPE happens.
-- 
Dmitry Pavlenko,
TMate Software,
http://subgit.com/ - git-svn bridge

> On Wed, Jun 26, 2019 at 11:21 PM Dmitry Pavlenko <pavlenko@xxxxxxxxxxxxx>
> 
> wrote:
> > Hello,
> > 
> > I can reproduce the NPE with a single line:
> >   RepositoryCache.FileKey.isGitRepository(new File("repo.git"),
> > 
> > FS.DETECTED)
> > 
> > if the relative path "repo.git" doesn't exist yet.
> > 
> > It's a regression, the previous (File-based, not Path-based) JGit versions
> > worked fine in this situation.
> > 
> > The problem happens because
> > 
> >   new File("repo.git").toPath().getParent()
> > 
> > evaluates to null in
> > 
> >   FS.FileStoreAttributeCache.getFsTimestampResolution()
> > 
> > (The corresponding line is:  Path dir = Files.isDirectory(file) ? file :
> > file.getParent();  )
> > 
> > The documentation doesn't mention whether the path can or cannot be
> > relative.
> > 
> > So I wonder whether this is expected behaviour, and I should use the
> > absolute path or is it a bug in JGit and it should work with relative
> > paths
> > as well?
> 
> I added a test with your example but it doesn't fail on Mac:
> https://git.eclipse.org/r/#/c/144960/
> 
> Can you try that in your environment?
> 
> -Matthias

Attachment: screenshot1.png
Description: PNG image

Attachment: screenshot2.png
Description: PNG image

Attachment: screenshot3.png
Description: PNG image

Attachment: screenshot4.png
Description: PNG image

Attachment: screenshot5.png
Description: PNG image