fix null pointer in PortLock#lock (#6941)

java.lang.NullPointerException:
  at com.daml.ports.PortLock$Locked.unlock(PortLock.scala:55)
  at com.daml.ports.PortLock$.lock(PortLock.scala:41)
  at com.daml.ports.LockedFreePort$.find(LockedFreePort.scala:15)
  at com.daml.lf.engine.trigger.TriggerServiceFixture$.$anonfun$withTriggerService$1(TriggerServiceFixture.scala:65)

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Stephen Compall 2020-07-31 10:59:39 -04:00 committed by GitHub
parent e972872128
commit 3a0a3228ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,14 +33,13 @@ object PortLock {
val file = new RandomAccessFile(portLockFile.toFile, "rw")
val channel = file.getChannel
try {
val lock = channel.tryLock()
val locked = new Locked(port, lock, channel, file)
if (lock != null) {
Right(locked)
} else {
locked.unlock()
Left(FailedToLock(port))
}
Option(channel.tryLock())
.map(lock => new Locked(port, lock, channel, file))
.toRight {
channel.close()
file.close()
FailedToLock(port)
}
} catch {
case _: OverlappingFileLockException =>
channel.close()