<Swing Dev> [11][JDK-8196673] JFileChooser throws InvalidPathException when changing to directory with added space

Semyon Sadetsky semyon.sadetsky at oracle.com
Fri Feb 23 03:17:41 UTC 2018


On 2/22/2018 10:11 AM, Krishna Addepalli wrote:

> There was no regression as far as I understand.
>
> Java8 trims any spaces in the file path before creating/selecting the 
> folder/file. That behavior is consistent with the windows native file 
> dialog.
>
This is not true. I just created a folder with trailing space on my 
Windows 7 and I can easily change into it in the native Open/Save 
dialogs as well as use it in Windows Explorer which is the "shell" on 
Windows platform.
Windows Explorer trims the space only when creates the file/dir with 
trailing space but if it is already existing it allows to use it. This 
is much more consistent approach than we now have in Java where the dir 
with trailing space can be created but then cannot be used anyhow, 
especially, taking into account the fact that Java tries to be 
cross-platform and should support *at least* natively provided 
cross-platform compatibility.

So I propose to change the JFC behavior to allow navigation of the f/s 
tree in the same way as the native file dialog.

--Semyon
>
> Java10 produces an exception for the same case because of nio.
>
> The fix is to restore the behavior of Java8, which is consistent with 
> Windows platform.
>
> Thanks,
>
> Krishna
>
> *From:*Semyon Sadetsky
> *Sent:* Thursday, February 22, 2018 11:22 PM
> *To:* Krishna Addepalli <krishna.addepalli at oracle.com>; Philip Race 
> <philip.race at oracle.com>; swing-dev at openjdk.java.net
> *Subject:* Re: <Swing Dev> [11][JDK-8196673] JFileChooser throws 
> InvalidPathException when changing to directory with added space
>
> I have to repeat my question: How this may help to fix the regression? 
> Will it be possible to change to directory with trailing space after 
> the fix?
>
> --Semyon
>
> On 02/22/2018 08:48 AM, Krishna Addepalli wrote:
>
>     Hi Semyon,
>
>     While browsing through the api for File, I found the
>     “getCanonicalPath” function, which returns the OS specific path as
>     per the documentation:
>
>     Returns the canonical pathname string of this abstract pathname.
>
>     A canonical pathname is both absolute and unique. The precise
>     definition of canonical form is system-dependent. This method
>     first converts this pathname to absolute form if necessary, as if
>     by invoking the getAbsolutePath()
>     <https://docs.oracle.com/javase/7/docs/api/java/io/File.html#getAbsolutePath%28%29> method,
>     and then maps it to its unique form in a system-dependent way.
>     This typically involves removing redundant names such as "." and
>     ".." from the pathname, resolving symbolic links (on UNIX
>     platforms), and converting drive letters to a standard case (on
>     Microsoft Windows platforms).
>
>     Every pathname that denotes an existing file or directory has a
>     unique canonical form. Every pathname that denotes a nonexistent
>     file or directory also has a unique canonical form. The canonical
>     form of the pathname of a nonexistent file or directory may be
>     different from the canonical form of the same pathname after the
>     file or directory is created. Similarly, the canonical form of the
>     pathname of an existing file or directory may be different from
>     the canonical form of the same pathname after the file or
>     directory is deleted.
>
>     Here is the link:
>     https://docs.oracle.com/javase/7/docs/api/java/io/File.html#getCanonicalPath()
>     <https://docs.oracle.com/javase/7/docs/api/java/io/File.html#getCanonicalPath%28%29>
>
>     On Windows, this is removing the extra spaces in the path, so
>     seemed like a good function with minimal changes.
>
>     Thanks,
>
>     Krishna
>
>     *From:*Semyon Sadetsky
>     *Sent:* Thursday, February 22, 2018 9:56 PM
>     *To:* Krishna Addepalli <krishna.addepalli at oracle.com>
>     <mailto:krishna.addepalli at oracle.com>; Philip Race
>     <philip.race at oracle.com> <mailto:philip.race at oracle.com>;
>     swing-dev at openjdk.java.net <mailto:swing-dev at openjdk.java.net>
>     *Subject:* Re: <Swing Dev> [11][JDK-8196673] JFileChooser throws
>     InvalidPathException when changing to directory with added space
>
>     Hi Krishna,
>
>     I didn't get how your last version may fix the issue. Can you clarify?
>
>     My suggestion was to move Files.exists(...) to
>     ShellFolderManager.createShellFolder() so in Widows the FNF will
>     be caused by the native shell. Thus NIO can be avoided on Windows.
>     I didn't test this but it should fix the bug scenario on a first
>     glance.
>
>     --Semyon
>
>     On 02/22/2018 04:29 AM, Krishna Addepalli wrote:
>
>         Hi Semyon,
>
>         Thanks for the suggestion. I have made changes accordingly,
>         and here is the new webrev:
>
>         http://cr.openjdk.java.net/~kaddepalli/8196673/webrev01
>         <http://cr.openjdk.java.net/%7Ekaddepalli/8196673/webrev01>
>
>         Krishna
>
>         *From:*Semyon Sadetsky
>         *Sent:* Thursday, February 22, 2018 5:34 AM
>         *To:* Krishna Addepalli <krishna.addepalli at oracle.com>
>         <mailto:krishna.addepalli at oracle.com>; Philip Race
>         <philip.race at oracle.com> <mailto:philip.race at oracle.com>;
>         swing-dev at openjdk.java.net <mailto:swing-dev at openjdk.java.net>
>         *Subject:* Re: <Swing Dev> [11][JDK-8196673] JFileChooser
>         throws InvalidPathException when changing to directory with
>         added space
>
>         On 2/21/18 11:08 AM, Krishna Addepalli wrote:
>
>             Hi Semyon,
>
>             I can raise a bug, but Sergey suggested that nio is being
>             used because of following fix:
>
>             > in jdk9 nio api is used because of the fix for:
>
>             >
>             http://mail.openjdk.java.net/pipermail/jdk9-dev/2016-September/004953.
>
>             > html
>
>             > we should not break it.
>
>         This is what I meant above. It should be fixed differently
>         without usage of NIO.
>         I think Files.exists() may be omitted when ShellFolder is
>         queried by Windows shell API. The FNF exception could be
>         thrown when null is returned.
>
>         --Semyon
>
>
>
>             @Sergey, could you post the correct link to the mail,
>             since that link is not working?
>
>             Hence, I have made the fix which simply trims the path on
>             Windows, and doesnot alter the string on other platforms.
>
>             Thanks,
>
>             Krishna
>
>             *From:*Semyon Sadetsky
>             *Sent:* Tuesday, February 20, 2018 10:39 PM
>             *To:* Krishna Addepalli <krishna.addepalli at oracle.com>
>             <mailto:krishna.addepalli at oracle.com>; Philip Race
>             <philip.race at oracle.com> <mailto:philip.race at oracle.com>;
>             swing-dev at openjdk.java.net <mailto:swing-dev at openjdk.java.net>
>             *Subject:* Re: <Swing Dev> [11][JDK-8196673] JFileChooser
>             throws InvalidPathException when changing to directory
>             with added space
>
>             On 02/20/2018 07:35 AM, Krishna Addepalli wrote:
>
>                 I have added the necessary information to the bug.
>
>                 As for Sergey’s question, the native file dialog also
>                 trims the strings before creating/selecting a file/folder.
>
>                 So, now I’m not clear if we are going ahead with the
>                 fix or raise a new bug against nio, and wait for them
>                 to fix it?
>
>                 Phil, Semyon could you suggest?
>
>             I suggest to file the bug against NIO and try to re-fix
>             the 7067885 in a different way without usage of NIO.
>
>             --Semyon
>
>
>
>
>                 Thanks,
>
>                 Krishna
>
>                 *From:*Semyon Sadetsky
>                 *Sent:* Saturday, February 17, 2018 1:03 AM
>                 *To:* Phil Race <philip.race at oracle.com>
>                 <mailto:philip.race at oracle.com>; Krishna Addepalli
>                 <krishna.addepalli at oracle.com>
>                 <mailto:krishna.addepalli at oracle.com>;
>                 swing-dev at openjdk.java.net
>                 <mailto:swing-dev at openjdk.java.net>
>                 *Subject:* Re: <Swing Dev> [11][JDK-8196673]
>                 JFileChooser throws InvalidPathException when changing
>                 to directory with added space
>
>                 On 02/16/2018 10:36 AM, Phil Race wrote:
>
>                     Seems that was about 20 emails ago in another
>                     off-list thread about this bug.
>                     It hasn't been posted to this list or added to the
>                     bug evaluation as far as I can see.
>                     Add that and the links to the evaluation, not just
>                     here.
>
>                     Since nio did already close 6578565 as not an
>                     issue I doubt it will be re-considered
>                     despite the points Semyon raises about other use
>                     cases for nio.
>
>                 At least we should try to file a new bug against NIO.
>                 They might be confused by Windows documentation
>                 because default meaning of "shell" on Linux is not the
>                 same as on Windows.
>
>                 --Semyon
>
>
>
>
>
>                     So the closest to whatever 8 was doing is fine.
>                     Sergey asked what the native FileDialog does and
>                     that is likely worth checking
>                     and including in the bug evaluation .. which
>                     probably should be updated to
>                     explain the problem better. It is the shell + UI
>                     that does not support it, not the
>                     windows OS.
>
>                     I find it irksome we have so many tests that
>                     directly use sun.awt.shell.ShellFolder
>                     but that is another issue ..
>
>                     -phil.
>
>                     On 02/16/2018 10:18 AM, Krishna Addepalli wrote:
>
>                         Hi Phil,
>
>                         “Vagueness that it is an nio problem without
>                         pointing to why just makes me
>                         have to investigate it myself to see why ..
>                         I'd prefer that the bug owner do that :-)”
>
>
>
>
>
>
>                         I did provide a standalone program, that
>                         reproduces the exact exception reported in the
>                         bug. Just repeating it here again for reference:
>
>                         import java.nio.file.Paths;
>
>                         public class PathExceptionBug {
>
>                             public static void main(String args[])
>                         throws Exception {
>
>                         Paths.get("C:\\testspace  ");
>
>                             }
>
>                         }
>
>                         When Sergey pointed out the bug(JDK-6578565),
>                         and suggested that NIO may close it, then we
>                         discussed about fixing it in our code, instead
>                         of assigning it to them.
>
>                         Thanks,
>
>                         Krishna
>
>                         *From:*Phil Race
>                         *Sent:* Friday, February 16, 2018 10:38 PM
>                         *To:* Krishna Addepalli
>                         <krishna.addepalli at oracle.com>
>                         <mailto:krishna.addepalli at oracle.com>; Semyon
>                         Sadetsky <semyon.sadetsky at oracle.com>
>                         <mailto:semyon.sadetsky at oracle.com>;
>                         swing-dev at openjdk.java.net
>                         <mailto:swing-dev at openjdk.java.net>
>                         *Subject:* Re: <Swing Dev> [11][JDK-8196673]
>                         JFileChooser throws InvalidPathException when
>                         changing to directory with added space
>
>                         Right, what I said was that perhaps nio is
>                         behaving as specified in this case.
>                         If a standalone nio program can be written
>                         that shows nio contravening its spec.
>                         then a bug should be raised against nio. I did
>                         not verify what the case is there ..
>                         I just suggested that should be investigated.
>
>                         Vagueness that it is an nio problem without
>                         pointing to why just makes me
>                         have to investigate it myself to see why ..
>                         I'd prefer that the bug owner do that :-)
>
>                         But otherwise (no nio bug)  we'll have to deal
>                         with what nio specifies.
>                         If we can fix it locally *and* file a bug
>                         against nio then that is also an issue.
>                         Also nio may take a while to get to it ..
>
>                         -phil
>
>                         On 02/16/2018 08:56 AM, Krishna Addepalli wrote:
>
>                             Hi Semyon,
>
>                             I had a discussion with Sergey,Phil
>                             regarding this. While there was a similar
>                             bug filed against Core-libs
>                             (https://bugs.openjdk.java.net/browse/JDK-6578565)
>                             , it was closed out as not an issue.
>
>                             I have checked it on Java8, and it behaves
>                             correctly on Windows – it trims the paths
>                             and then creates/selects the folder.
>
>                             From Java9 onwards, the
>                             InvalidPathException is thrown, since
>                             ShellFolder.java file uses nio to get the
>                             path, and the nio throws the exception as
>                             reported in the bug.
>
>                             Phil suggested that, we should fix the bug
>                             at our level if we can, since nio may not
>                             consider this to be a problem at their level.
>
>                             Hence this suggested fix.
>
>                             Thanks,
>
>                             Krishna
>
>                             *From:*Semyon Sadetsky
>                             *Sent:* Friday, February 16, 2018 10:04 PM
>                             *To:* Krishna Addepalli
>                             <krishna.addepalli at oracle.com>
>                             <mailto:krishna.addepalli at oracle.com>;
>                             swing-dev at openjdk.java.net
>                             <mailto:swing-dev at openjdk.java.net>
>                             *Subject:* Re: <Swing Dev>
>                             [11][JDK-8196673] JFileChooser throws
>                             InvalidPathException when changing to
>                             directory with added space
>
>                             According to Pardeep Sharma comment the
>                             bug is reproducible since 6u45. Do you
>                             confirm this or it is a regression
>                             introduced in 9?
>
>                             From the stack trace it doesn't look as a
>                             client-libs issue but a NIO issue.
>
>                             --Semyon
>
>                             On 02/16/2018 04:40 AM, Krishna Addepalli
>                             wrote:
>
>                                 Hi Sergey, Phil
>
>                                 Please review a fix for JDK-8196673:
>                                 https://bugs.openjdk.java.net/browse/JDK-8196673
>
>                                 Webrev:
>                                 http://cr.openjdk.java.net/~kaddepalli/8196673/webrev00
>                                 <http://cr.openjdk.java.net/%7Ekaddepalli/8196673/webrev00>
>
>                                 The problem is in Java9 and later,
>                                 when a directory path that contains
>                                 leading/trailing space is provided, it
>                                 throws an InvalidPathException. As per
>                                 Phil’s recommendation, I have added a
>                                 simple fix, which will trim the path
>                                 for Windows, whereas for other
>                                 platforms, it keeps it as it is.
>
>                                 Thanks,
>
>                                 Krishna
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20180222/e21a9752/attachment.html>


More information about the swing-dev mailing list