Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] isOutdated() and lastModified()

Hello all,

I seems that FileBasedConfig (and loose-refs-related classes) relies on 
java.io.File.lastModified() call (at least in isOutdated() method).

For my Sun Java 1.6.0.22 and OpenJDK 1.6.0 (Debian squeeze/sid)
java.io.File.lastModified() can be the same after changes in the file.

I don't know is it expected, is it JDK bug, or JGit problem. Do you?

Yes, I've read at the main page that JGit promises to work on Java 5, but 
anyway I think this will be interesting for JGit developers.

The following piece of code outputs

lm1 = 1292082965000
lm2 = 1292082965000
They are equal!

If I set a breakpoint somewhere, and run line-by-line,  lm1 != lm2.

import java.io.*;
public class Last {
	public  static void main(String[] args) {
	try {
		File someFile = new File("someFile");

		FileWriter writer;
		
		writer = new FileWriter(someFile);
		try {
			writer.write("some contents");
		} finally {
			writer.close();
		}

		final long lm1 = someFile.lastModified();

		writer = new FileWriter(someFile);
		try {
			writer.write("some another contents");
		} finally {
			writer.close();
		}

		final long lm2 = someFile.lastModified();

		System.out.println("lm1 = " + lm1);
		System.out.println("lm2 = " + lm2);

		if (lm1 == lm2) {
			System.out.println("They are equal!");
		}
	} catch (IOException e) {
	}
	}
}


Back to the top