JDK-6357599 : File.setLastModified(long) does not update 'last modified' time (win)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-12-01
  • Updated: 2010-04-02
  • Resolved: 2009-08-20
Description
FULL PRODUCT VERSION :
java version "1.4.2_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)
Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Does a file have to be closed to use setLastModified() to change its modification date?

I have a RandomAccessFile that I am writing to, but the modified time doesn't change when it is written to (is it supposed to?). I would like use setLastModified() to update the time, but it returns false unless I close the RandomAccessFile first. For example, the code below only works if I uncomment the close() below.
I am running this on WinXP, and it seems to work fine on Linux.

File file = new File("c:\\work\\", "FILETEST.txt");
file.createNewFile();
RandomAccessFile raf = new RandomAccessFile(file, "rw");
//raf.close();
System.out.println("Before=" + file.lastModified());
Thread.sleep(1000);
System.out.println(file.setLastModified(System.currentTimeMillis()));
System.out.println("After=" + file.lastModified());



REPRODUCIBILITY :
This bug can be reproduced always.

Comments
EVALUATION This bug no longer exists as of jdk7 b72 because the changes for 6595866 correct the sharing mode used when opening the file.
20-08-2009

EVALUATION The bug is that setLastModified opens the file without specifying a share mode. In the test case this will cause it to fail with a sharing violation. If the file is opened for read/write sharing then the method succeeed and the attribute is updated.
14-12-2006