-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8u92
-
generic
-
windows_10
FULL PRODUCT VERSION :
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.14393]
A DESCRIPTION OF THE PROBLEM :
When saving a file to disk the last modified date is not always updating as it should. I have found threads of similar issues in several places, but no one has mentioned different file extensions.
Below is an Android bug that dates from 2011 with lots of upset developers. It sounds like a similar issue.
https://code.google.com/p/android/issues/detail?id=18624#c29
Through testing I found the issue is different for different file types. The test was simply to rewrite each file to contain only a timestamp, then compare it to the last modified date reported by Windows.
The results:
- only .txt, .xml, .pdf and .docx files updated the last modified date in Windows correctly
- .ss, .ns. .classpath and some other not well known extensions did not
I ran the test in eclipse, as a standalone jar and on another computer. The results were always identical.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Write bytes to a file
2) Close the FileOutputStream
3) Check the last modified date in Windows File Explorer
4) Repeat and test the file extensions mentioned above - at a minimum .txt and .ss
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After saving a file and closing the stream I expect the file's last modified date to always get updated in Windows.
ACTUAL -
It only updates the last modified date correctly for .txt, .xml, .pdf and .docx files.
I included methods for 2 workarounds that you can uncomment to try - neither worked for me.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
public class LastModTest_main {
public static void main(String[] args) {
Logger logger = Logger.getAnonymousLogger();
Path folder = Paths.get("C:\\temp");
//Windows 10 with Office and Java 8 installed
//these files update last modified date correctly
resaveFile("modtest.txt", folder, logger);
resaveFile("modtest.xml", folder, logger);
resaveFile("modtest.docx", folder, logger);
resaveFile("modtest.pdf", folder, logger);
//these files do not update last modified
resaveFile("modtest.project", folder, logger);
resaveFile("modtest.classpath", folder, logger);
resaveFile("modtest.ss", folder, logger);
resaveFile("modtest.ns", folder, logger);
resaveFile("modtest.nsp", folder, logger);
System.out.println("all files resaved");
}
private static void resaveFile(String fileName, Path folder, Logger logger) {
File file = folder.resolve(fileName).toFile();
FileOutputStream stream = null;
try {
stream = new FileOutputStream(file);
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
stream.write(timestamp.getBytes());
} catch (Exception e) {
logger.log(Level.SEVERE, "an error occurred writing file: " + file.getAbsolutePath(), e);
return;
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
logger.log(Level.SEVERE, "an error occurred closing file: " + file.getAbsolutePath(), e);
return;
}
}
}
//calling File.setLastModified() does not work
//workAround1(file, logger);
//using RandomAccessFile does not work
//workAround2(file, logger);
}
private static void workAround1(File file, Logger logger) {
file.setLastModified(new Date().getTime());
}
private static void workAround2(File file, Logger logger) {
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(file, "rw");
long length = raf.length();
raf.setLength(length + 1);
raf.setLength(length);
} catch (Exception e) {
logger.log(Level.SEVERE, "unable to update RandomAccessFile", e);
} finally {
try {
if (raf != null) {
raf.close();
}
} catch (IOException e) {
logger.log(Level.SEVERE, "unable to close RandomAccessFile", e);
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I cannot find a workaround. This is quite serious because it affects custom file extensions that our software uses. These associations are used to quick launch our software when double-clicked, so we can't reuse something like .xml.
Anyone who noticed this as a used would not trust our software. I would assume something is corrupt in the file saved.
I did find one link that said it might be a caching issue in NTFS, but that would not explain the Android bug I mentioned earlier.
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.14393]
A DESCRIPTION OF THE PROBLEM :
When saving a file to disk the last modified date is not always updating as it should. I have found threads of similar issues in several places, but no one has mentioned different file extensions.
Below is an Android bug that dates from 2011 with lots of upset developers. It sounds like a similar issue.
https://code.google.com/p/android/issues/detail?id=18624#c29
Through testing I found the issue is different for different file types. The test was simply to rewrite each file to contain only a timestamp, then compare it to the last modified date reported by Windows.
The results:
- only .txt, .xml, .pdf and .docx files updated the last modified date in Windows correctly
- .ss, .ns. .classpath and some other not well known extensions did not
I ran the test in eclipse, as a standalone jar and on another computer. The results were always identical.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Write bytes to a file
2) Close the FileOutputStream
3) Check the last modified date in Windows File Explorer
4) Repeat and test the file extensions mentioned above - at a minimum .txt and .ss
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
After saving a file and closing the stream I expect the file's last modified date to always get updated in Windows.
ACTUAL -
It only updates the last modified date correctly for .txt, .xml, .pdf and .docx files.
I included methods for 2 workarounds that you can uncomment to try - neither worked for me.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
public class LastModTest_main {
public static void main(String[] args) {
Logger logger = Logger.getAnonymousLogger();
Path folder = Paths.get("C:\\temp");
//Windows 10 with Office and Java 8 installed
//these files update last modified date correctly
resaveFile("modtest.txt", folder, logger);
resaveFile("modtest.xml", folder, logger);
resaveFile("modtest.docx", folder, logger);
resaveFile("modtest.pdf", folder, logger);
//these files do not update last modified
resaveFile("modtest.project", folder, logger);
resaveFile("modtest.classpath", folder, logger);
resaveFile("modtest.ss", folder, logger);
resaveFile("modtest.ns", folder, logger);
resaveFile("modtest.nsp", folder, logger);
System.out.println("all files resaved");
}
private static void resaveFile(String fileName, Path folder, Logger logger) {
File file = folder.resolve(fileName).toFile();
FileOutputStream stream = null;
try {
stream = new FileOutputStream(file);
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
stream.write(timestamp.getBytes());
} catch (Exception e) {
logger.log(Level.SEVERE, "an error occurred writing file: " + file.getAbsolutePath(), e);
return;
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
logger.log(Level.SEVERE, "an error occurred closing file: " + file.getAbsolutePath(), e);
return;
}
}
}
//calling File.setLastModified() does not work
//workAround1(file, logger);
//using RandomAccessFile does not work
//workAround2(file, logger);
}
private static void workAround1(File file, Logger logger) {
file.setLastModified(new Date().getTime());
}
private static void workAround2(File file, Logger logger) {
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(file, "rw");
long length = raf.length();
raf.setLength(length + 1);
raf.setLength(length);
} catch (Exception e) {
logger.log(Level.SEVERE, "unable to update RandomAccessFile", e);
} finally {
try {
if (raf != null) {
raf.close();
}
} catch (IOException e) {
logger.log(Level.SEVERE, "unable to close RandomAccessFile", e);
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I cannot find a workaround. This is quite serious because it affects custom file extensions that our software uses. These associations are used to quick launch our software when double-clicked, so we can't reuse something like .xml.
Anyone who noticed this as a used would not trust our software. I would assume something is corrupt in the file saved.
I did find one link that said it might be a caching issue in NTFS, but that would not explain the Android bug I mentioned earlier.