You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
File#flock raises NullPointerException on Windows when another process holds the lock #10085
Run jruby hold.rb, and once it prints holding, run jruby try.rb in another console. try.rb should print false.
Actual Behavior
try.rb raises:
Java::JavaLang::NullPointerException: Cannot invoke "jnr.constants.platform.Errno.ordinal()" because the return value of "org.jruby.util.i...
(My log cut the message off there.)
I think this came in with #9347, which made File#flock use the JDK's FileChannel locks on Windows. When another process holds the lock, FileChannel#tryLock returns null, and PosixShim#tryLock returns lockFailedReturn(...) without setting an errno:
Setting EWOULDBLOCK (or EAGAIN) in tryLock before it returns would make flock return false there, as RubyFile#flock already does for those errnos. From the same code, I think a shared lock that can't be taken (LOCK_SH | LOCK_NB) returns 0 instead, because lockFailedReturn returns 0 for LOCK_SH, so flock would say it got a lock it didn't. I haven't checked that one.
I'm working around it in Duel by taking a Java::JavaLang::NullPointerException from flock to mean the lock is held.
Activity
Return false from a failed non-blocking flock on Windows
headius commentedon Nov 17, 2026
Fixed by #10086!