[ 
https://issues.apache.org/jira/browse/IO-707?focusedWorklogId=543122&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-543122
 ]

ASF GitHub Bot logged work on IO-707:
-------------------------------------

                Author: ASF GitHub Bot
            Created on: 27/Jan/21 21:53
            Start Date: 27/Jan/21 21:53
    Worklog Time Spent: 10m 
      Work Description: kinow commented on a change in pull request #192:
URL: https://github.com/apache/commons-io/pull/192#discussion_r565660147



##########
File path: src/main/java/org/apache/commons/io/FileUtils.java
##########
@@ -1168,7 +1169,9 @@ static String decodeUrl(final String url) {
      */
     public static File delete(final File file) throws IOException {
         Objects.requireNonNull(file, "file");
-        Files.delete(file.toPath());
+        Path path = file.toPath();
+        Files.delete(path);
+        assert Files.notExists(path, PathUtils.NOFOLLOW_LINK_OPTION_ARRAY) : 
"File still exists " + path;

Review comment:
       I'm not sure if that's really necessary to have in this method? From the 
docs for this file, it used to be a useful alternative for `File#delete` that 
returned a boolean. But now with the JVM (from 8 I think?) `Files#delete` they 
both have similar behaviour.
   
   So if the file cannot be deleted, an exception is thrown. If the JVM 
implementation (or underlying OS libraries, or maybe a NFS or virtual file 
system) reported the file as deleted, but the file still exists, then both 
`Files#delete` and this method will behave the same way.
   
   I'm not sure if having an assertion error here would be helpful to users of 
these platforms. They'd probably have to rely on the JVM, or have their code to 
check for the file still existing (they could be using the JVM `Files#delete` 
somewhere else in the code).

##########
File path: pom.xml
##########
@@ -394,6 +394,7 @@ file comparators, endian transformation classes, and much 
more.
           </classpathDependencyExcludes>
           <forkCount>1</forkCount>
           <reuseForks>false</reuseForks>
+          <enableAssertions>true</enableAssertions>

Review comment:
       I haven't used ­or read about assertions in Java in a while. Unless 
something changed in recent releases, I think this enables the `-ea` flag for 
build time. But users of the API would still have it disabled by default in 
OpenJDK/Oracle JVM's.
   
   So the new code with assertions wouldn't be used, and I think using 
assertions in production code (not in tests) used to be discouraged?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 543122)
    Time Spent: 40m  (was: 0.5h)

> Add optional early error detection as postcondition check
> ---------------------------------------------------------
>
>                 Key: IO-707
>                 URL: https://issues.apache.org/jira/browse/IO-707
>             Project: Commons IO
>          Issue Type: Improvement
>          Components: Utilities
>    Affects Versions: 2.8.0
>            Reporter: Boris Unckel
>            Priority: Major
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> The current version does not include an optional way to detect errors with 
> the underlying filesystem and/or logic early.
> Due to performance reason and/or design decision, the result of delete or 
> create directories/files does not include a check wheter the delete or create 
> was successful. It "only" relies on trust to the underlying operations of the 
> JDK and/or the completeness of own unit tests.
> To have the option to check things, without having additional commons-io 
> proprietary options and without a performance impact for regular operations 
> the Java 1.4 keyword "assert" should be used.
> Current project profits in case of detail analysis. Downstream projects 
> having own unit tests for IO will profit.
> PR with proposal will follow.



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

Reply via email to