[IO-707] Add optional postcondition checks with assert#192
[IO-707] Add optional postcondition checks with assert#192boris-unckel wants to merge 1 commit intoapache:masterfrom
Conversation
|
Hi @boris-unckel |
|
Hm... it seems to me that any file operation in an app (through Commons IO or otherwise) is always at risk of being "out-of-sync" or simply subverted by another process or user doing some operations on disk, so this is going to be confusing at best. For example, let's say I perform some Commons IO file operation, then the JVM or GC pauses my thread for a "long" time, during which something happens on disk which violates my app's expectations once it wakes up... now what? |
| </classpathDependencyExcludes> | ||
| <forkCount>1</forkCount> | ||
| <reuseForks>false</reuseForks> | ||
| <enableAssertions>true</enableAssertions> |
There was a problem hiding this 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?
There was a problem hiding this comment.
Thanks for taking time to review this. Yes, assertions are not intended to be used in production. Especially AssertionErrors (assert does throw an error, not an exception) should not be used for application logic.
| Files.delete(file.toPath()); | ||
| Path path = file.toPath(); | ||
| Files.delete(path); | ||
| assert Files.notExists(path, PathUtils.NOFOLLOW_LINK_OPTION_ARRAY) : "File still exists " + path; |
There was a problem hiding this 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).
There was a problem hiding this comment.
@kinow Please find my feedback below. It addresses tests (not production) for a file system constellation which can be reproduced with extended attributes.
|
@garydgregory Thank you for your time to review and place it for public review.
The use case you're describing is not improved by the assert or just slightly. I'm thinking more about cases where the underlying file system in combination with the JRE does not behave as expected: For /tmp it says "IOCTL not matching to read flags of /tmp". Working with commons-io 2.5 I had no trouble to build WildFly-Core, with 2.8.0 it fails. The first fixes I already provided (former PRs not this one), but it is not over. A workaround is to set java.io.temp to a directory with "--------------e-----" attributes. The asserts help to find the original place of fail and not the top level one (like "delete fails due to directory is not empty"). |
|
Hi @boris-unckel and All: |
|
https://issues.apache.org/jira/browse/IO-725 is related to this. As long as only Ubuntu (with a different file system) is accepted as prove for bugs, this here is not useful. |
Fixes https://issues.apache.org/jira/browse/IO-707