Wrong behavior of standard IO library when interacting with Samba (very serious)

Alan Bateman Alan.Bateman at oracle.com
Mon Mar 7 08:28:29 UTC 2022


On 07/03/2022 05:33, Glavo wrote:
> I am a Java application developer. I noticed that when my program runs on
> Windows in a samba shared folder (mounted as a drive, or accessed via a UNC
> path), the Java standard IO library has some unusual behavior.
> Note that these issues only occur when accessing a folder shared by
> *Samba*, but not for the folder shared via SMB by another Windows host.
>
> One of the bugs was reported years ago (JDK-8154915): `Files.isWritable`
> always returns false for files shared by samba. It's worth noting for this
> question that `File::canWrite()`'s behavior is normal.
> (So in my program I pass `!Files.isWritable(p) && p.toFile().canWrite()` to
> detect if it's shared by samba and give the user a warning)
> This problem keeps showing up on several of my devices, so it should be
> fine to reproduce. The reason it wasn't resolved seems to be that the
> OpenJDK maintainers didn't understand that it came up when interacting with
> Samba (not just SMB).
Testing if a file is writable, without side effects, can be complicated 
on Windows. File.canXXX only looks at the DOS attribute so can't give an 
accurate result. Files.isWritable examines the DACL, the legacy DOS 
attribute, and whether the volume is read-only, so there is more to go 
wrong. We've looked at many Windows <--> SAMBA interop issues over the 
years and it's always been that the Windows calls were failing or 
returning results that suggested the file had a DACL with 0 entries. I 
can't tell from your mail where the issue is but some of the behavior 
you report in your mail is very unusual. The JDK does not cache results 
so if you are saying that it requires restarting the JDK then it 
suggests an issue at a lower level.

-Alan


More information about the core-libs-dev mailing list