3r1co / hg4j

Automatically exported from code.google.com/p/hg4j
GNU General Public License v2.0
0 stars 1 forks source link

NPE on status operation on repository created in the current user's directory. #2

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Exception in thread "main" java.lang.NullPointerException
    at org.tmatesoft.hg.repo.HgRepository.createWorkingDirWalker(HgRepository.java:211)
    at org.tmatesoft.hg.repo.HgWorkingCopyStatusCollector.<init>(HgWorkingCopyStatusCollector.java:56)
    at org.tmatesoft.hg.core.HgStatusCommand.execute(HgStatusCommand.java:178)
    at org.tmatesoft.hg.test.DisplayWorkingTreeStatus.main(DisplayWorkingTreeStatus.java:36)

HgRepository makes two assumptions:

1. Its location was specified as an absolute path
2. Its location is non-root directory

Both might be wrong. I suggest to convert File to absolute as early as possible 
and use only absolute File's internally.

Original issue reported on code.google.com by kit...@gmail.com on 24 Feb 2011 at 6:13

GoogleCodeExporter commented 8 years ago
HgRepository.java:211 is repoDir.getParentFile() call. repoDir points to '.hg/' 
folder, thus non-root assumption seems valid. As for (1) non-absolute path, the 
way HgLookup builds repository location makes me think File object supplied to 
HgRepository can be read, and as such won't yield errors like that. However, 
I've changed HgLookup to explicitly convert to absolute path right away just in 
case.

The only chance for HgRepository.repoDir to be null and cause this NPE is 
HgRepository.isInvalid == true, no repository was found in the specified 
location.

Original comment by tikhomir...@gmail.com on 24 Feb 2011 at 7:11