Skip to content

Commit

Permalink
Improve DeltaProcessor file change detection #3036
Browse files Browse the repository at this point in the history
Try to fix BuildpathTests.testChangeZIPArchive1() on linux.

Small changes in file length and timeStamp could have produced hash
collisions due to simple hash function.

#3036
  • Loading branch information
EcljpseB0T authored and jukzi committed Dec 9, 2024
1 parent 922cbbb commit d37105b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public void testChangeZIPArchive1() throws Exception {

env.addExternalJars(projectPath, Util.getJavaClassLibs());
env.addExternalJars(projectPath, new String[] {externalLib});

long lastModified = new File(externalLib).lastModified();
IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$
env.setOutputFolder(projectPath, "");

Expand All @@ -394,7 +394,7 @@ public void testChangeZIPArchive1() throws Exception {
},
externalLib,
CompilerOptions.getFirstSupportedJavaVersion());

new File(externalLib).setLastModified(lastModified + 1000); // make sure lastModified has changed
IJavaProject p = env.getJavaProject(projectPath);
p.getJavaModel().refreshExternalArchives(new IJavaElement[] {p}, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public String toString() {
* Used for detecting external JAR changes
*/
public static long getTimeStamp(File file) {
return file.lastModified() + file.length();
return file.lastModified() + Long.hashCode(file.length()) * 31;
}

/*
Expand Down

0 comments on commit d37105b

Please sign in to comment.