NPE while automatic layout detection

It is possibly caused by a lock left in the repository for “refs/svn/history/layout/notes” reference.
As result the reference might not got updated so the commit corresponding to an SVN revision might not get layout as a note.

{code}
org.tmatesoft.translator.util.f:
at org.tmatesoft.translator.util.TsException.wrap(SourceFile:109)
at org.tmatesoft.translator.util.TsException.wrap(SourceFile:75)
at org.tmatesoft.translator.history.TsSubversionHistory.logDescending(SourceFile:300)
at org.tmatesoft.translator.history.TsSubversionHistory.log(SourceFile:221)
at org.tmatesoft.translator.history.generator.TsSubversionHistoryProvider.getAllBranchesWithin(SourceFile:36)
at org.tmatesoft.translator.history.generator.TsRepositoryLayoutGenerator.generate(SourceFile:53)
at org.tmatesoft.translator.history.generator.TsRepositoryLayoutGenerator.generate(SourceFile:41)
at org.tmatesoft.translator.history.generator.TsRepositoryConfigurationGenerator.generate(SourceFile:228)
at org.tmatesoft.translator.repository.proxy.TsProxyRepositoryConfigure.addAutoLocation(SourceFile:493)
at org.tmatesoft.translator.repository.proxy.TsProxyRepositoryConfigure.run(SourceFile:360)
at org.tmatesoft.subgit.stash.mirror.tasks.SgConfigureTask.runSecurely(SourceFile:92)
at org.tmatesoft.subgit.stash.mirror.tasks.SgMirrorTask.lambda$run$0(SourceFile:110)
at com.atlassian.stash.internal.user.DefaultEscalatedSecurityContext.call(DefaultEscalatedSecurityContext.java:58)
at org.tmatesoft.subgit.stash.mirror.tasks.SgMirrorTask.run(SourceFile:108)
at org.tmatesoft.subgit.stash.mirror.tasks.SgMirrorTask.run(SourceFile:22)
at org.tmatesoft.subgit.stash.mirror.scheduler.SgTaskScheduler$TaskWrapper.runTask(SourceFile:999)
at org.tmatesoft.subgit.stash.mirror.scheduler.SgTaskScheduler$TaskWrapper.run(SourceFile:961)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
at org.tmatesoft.translator.history.generator.TsSubversionHistoryProvider$UniqueBranchesCollector.handleLogEntry(SourceFile:107)
at org.tmatesoft.translator.history.TsSubversionHistory.logDescending(SourceFile:286)
Caused by: java.lang.NullPointerException: null
at org.tmatesoft.translator.history.generator.TsSubversionHistoryProvider$UniqueBranchesCollector.handleLogEntry(SourceFile:107)
at org.tmatesoft.translator.history.TsSubversionHistory.logDescending(SourceFile:286)
{code}

Originally reported by: Jozef Vandenmooter Jozef.Vandenmooter@perficient.com.

Some analysis: the problem happens at
{code}
final TsSubversionLayout layout = layoutManager.getLayout(entry);
if (!layout.equals(previousLayout)) { //<----- HERE THE NPE HAPPENS
collectBranches(layout);
}
{code}
So the layout is null. ‘entry’ cannot be null because it’s constructed with ‘new’ just before being passed as a parameter. So getLayout() returns null. The relevant piece of getLayout() code is:

{code}
final ObjectId layoutBlobId = readNote(NOTES_REF, logEntry.getGitCommit());
if (layoutBlobId != null) {
return TsSubversionLogMarshaller.readLayout(layoutBlobId, getRevWalk().getObjectReader());
}

return null;
{code}
TsSubversionLayout.readLayout() is never null by design. So ‘layoutBlobId == null’ is the only possibility. This means that NOTES_REF doesn’t contain a note for the relevant commit (‘logEntry.getGitCommit()’ also cannot be null because of the way the ‘logEntry’ is constructed).

I have only one idea why there’s no note on a commit: a presence of a lock made NOTES_REF update impossible starting from some point.

r4283 of trunk: lock-aware reference updating code is now used while automatic layout detection.