Out of sync error in Eclipse

Problem

Eclipse has a strange behavior that I have not seen in any other editor or IDE. Assume that a file belonging to a project in the workspace has been modified outside of Eclipse. If you now open that file in Eclipse, it does not open it, but shows this error:

Resource is out of sync with the file system: '/src/foo.cpp'.
Press 'F5' or select File > Refresh to refresh the file.

You can press F5 and the file will be displayed.

Solution

I cannot imagine a scenario in practice where I would not want to keep the updated file. To make this out of sync error go away by refreshing files automatically, you have two options:

You can make Eclipse refresh the file automatically when it is opened. To do this enable Windows -> Preferences -> General -> Workspace -> Refresh on access.

You can make Eclipse refresh the file by being signaled by the filesystem (this is efficient) or polling the filesystem (this is inefficient). This is efficient only on Windows. To do this enable Windows -> Preferences -> General -> Workspace -> Refresh using native hooks or polling.