You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ofbiz.apache.org by "Jacques Le Roux (Jira)" <ji...@apache.org> on 2020/11/24 17:36:00 UTC

[jira] [Updated] (OFBIZ-12063) Replace java.io.File::renameTo by java.nio.file.Files::move

     [ https://issues.apache.org/jira/browse/OFBIZ-12063?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jacques Le Roux updated OFBIZ-12063:
------------------------------------
    Description: 
This is a bug because the behaviour is not assured on Windows for instance. So it's impossible to correctly develop and test.

As explained at https://docs.oracle.com/javase/8/docs/api/java/io/File.html#renameTo-java.io.File-
{quote}
Renames the file denoted by this abstract pathname.

Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful.

Note that the Files class defines the move method to move or rename a file in a platform independent manner.
{quote}

The expression
{code:java}
file.renameTo(file1)
{code}
is used in 5 Application Product Groovy scripts.

It can be easily replaced by
{code:java}
Path source = file.toPath()
Files.move(source, source.resolveSibling(filenameToUse))
{code}
that is working on all platforms as explained at https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#move-java.nio.file.Path-java.nio.file.Path-java.nio.file.CopyOption...-

  was:
As explained at https://docs.oracle.com/javase/8/docs/api/java/io/File.html#renameTo-java.io.File-
{quote}
Renames the file denoted by this abstract pathname.

Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful.

Note that the Files class defines the move method to move or rename a file in a platform independent manner.
{quote}

The expression
{code:java}
file.renameTo(file1)
{code}
is used in 5 Application Product Groovy scripts.

It can be easily replaced by
{code:java}
Path source = file.toPath()
Files.move(source, source.resolveSibling(filenameToUse))
{code}
that is working on all platforms as explained at https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#move-java.nio.file.Path-java.nio.file.Path-java.nio.file.CopyOption...-

     Issue Type: Bug  (was: Improvement)

> Replace java.io.File::renameTo by java.nio.file.Files::move
> -----------------------------------------------------------
>
>                 Key: OFBIZ-12063
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-12063
>             Project: OFBiz
>          Issue Type: Bug
>          Components: product/catalog
>    Affects Versions: Trunk
>            Reporter: Jacques Le Roux
>            Assignee: Jacques Le Roux
>            Priority: Major
>
> This is a bug because the behaviour is not assured on Windows for instance. So it's impossible to correctly develop and test.
> As explained at https://docs.oracle.com/javase/8/docs/api/java/io/File.html#renameTo-java.io.File-
> {quote}
> Renames the file denoted by this abstract pathname.
> Many aspects of the behavior of this method are inherently platform-dependent: The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful.
> Note that the Files class defines the move method to move or rename a file in a platform independent manner.
> {quote}
> The expression
> {code:java}
> file.renameTo(file1)
> {code}
> is used in 5 Application Product Groovy scripts.
> It can be easily replaced by
> {code:java}
> Path source = file.toPath()
> Files.move(source, source.resolveSibling(filenameToUse))
> {code}
> that is working on all platforms as explained at https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#move-java.nio.file.Path-java.nio.file.Path-java.nio.file.CopyOption...-



--
This message was sent by Atlassian Jira
(v8.3.4#803005)