Close

Intellij changes file creation date when modified within the IDE

[Last Updated: Dec 7, 2016]

Intellij IDE 

The background and issue

We are working on a project 'A' with a lot of source Java files. Another projects 'B' is web based JSF project which reads the Java files from project 'A' and dynamically display them to our corporate website. Besides showing the Java file's creation date on the web pages, we also also do sorting based on the creation date. We use BasicFileAttributes to read creation date of each file. We are using Intellij IDEA version 15.0.2 We soon realized the creation date was modified whenever we modify the Java source file. That means creation date was actually behaving as update date.


The cause of the issue

After spending couple of hours debugging our application to figure out the issue, we did a little test and found out that file modified outside IntelliJ IDEA don't have this problem. We read the Intellij docs and soon found out this option:

We modified the above screenshot to indicate the issue with red font.

According to Intellij System Settings doc:

Use "safe write" (save changes to a temporary file first):

If this check box is selected, a changed file is first saved in a temporary file. If the save operation succeeds, the file being saved is replaced with the saved file. (Technically, the original file is deleted and the temporary file is renamed.)

Also, the ownership of such file changes.

If this check box is not selected, the ownership of a file does not change, but all the advantages of safe write will be lost.


The fix

Uncheck the last option "Use "safe write" (save changes to a temporary file first)" under Appearance and Behavior | System Settings.

By default it's checked.


See Also