From c6c5baa3ecd0901466f2c98c2af11d55890fc03d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Varga?= Date: Wed, 14 Aug 2024 11:37:18 +0200 Subject: [PATCH] fix: OverlappingFileLockException --- .../robolectric/internal/JUnit5MavenDependencyResolver.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5MavenDependencyResolver.kt b/robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5MavenDependencyResolver.kt index fce3b7b..747c92a 100644 --- a/robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5MavenDependencyResolver.kt +++ b/robolectric-extension/src/main/kotlin/tech/apter/junit/jupiter/robolectric/internal/JUnit5MavenDependencyResolver.kt @@ -14,7 +14,6 @@ import java.nio.channels.FileLock import java.nio.channels.OverlappingFileLockException import java.util.concurrent.ExecutorService - internal class JUnit5MavenDependencyResolver private constructor( repositoryUrl: String, repositoryId: String, @@ -82,11 +81,12 @@ internal class JUnit5MavenDependencyResolver private constructor( raf.channel.use { channel -> var lock: FileLock? = null while (lock == null) { + @Suppress("SwallowedException") try { lock = channel.tryLock() } catch (e: OverlappingFileLockException) { // Sleep for a while before retrying - Thread.sleep(100) + Thread.sleep(WAIT_MS_UNTIL_LOCK_FILE_RELEASED) } } runnable.run() @@ -101,6 +101,7 @@ internal class JUnit5MavenDependencyResolver private constructor( } private companion object { + private const val WAIT_MS_UNTIL_LOCK_FILE_RELEASED = 100L private const val SPECIAL_CHARACTERS_IN_FILE_NAME_REGEX = """[<>:"\\/|\?\*]""" } }