Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-12063

Replace java.io.File::renameTo by java.nio.file.Files::move

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • Trunk
    • None
    • product/catalog
    • None

    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-

      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.

      So the expression

      file.renameTo(file1)
      

      used in 5 Application Product Groovy scripts, can be easily replaced by

      Path source = file.toPath()
      Files.move(source, source.resolveSibling(filenameToUse))
      

      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...-

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            jleroux Jacques Le Roux
            jleroux Jacques Le Roux
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment