Wrong behavior of standard IO library when interacting with Samba (very serious)
Glavo
zjx001202 at gmail.com
Tue Mar 8 06:20:08 UTC 2022
Regarding the issue with isWritable, I came across this post after
investigating:
https://devblogs.microsoft.com/oldnewthing/20060202-00/?p=32413
This does seem to be a Windows `AccessCheck` problem, and there is almost
no solution.
For this reason, isWritable is not very useful. While you may not be able
to fix it, I request an update to isWritable's Javadoc describing the
limitations of this method.
Its actual function is easily misunderstood, and I feel that users should
be told in the documentation that it is recommended to try writing directly
instead of checking with this method first.
In addition to the problems mentioned here, I've also encountered some
rarer problems, such as the bizarre AccessDeniedException.
These issues don't seem to be reproducible on all machines, I'll
investigate them further.
If anyone is interested in these issues, I can provide a reproduction
environment to help you test, thank you.
On Mon, Mar 7, 2022 at 4:28 PM Alan Bateman <Alan.Bateman at oracle.com> wrote:
> 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