[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

your line numbers in FS are off by 2 lines

in FS line 202 dir evaluates toÂ/var/folders/16/nqvdxf5s45309nxkv4k4r20r0000gq/T/tmp_1112776041349876411
when debugging this test

I set a breakpoint in line 185 of FileSnapshot which isn't reached when running this test

On Thu, Jun 27, 2019 at 8:51 AM Dmitry Pavlenko <pavlenko@xxxxxxxxxxxxx> wrote:
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