From d37105b86741e804745048004bc75a73b927461d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kubitz?= Date: Mon, 9 Dec 2024 09:19:05 +0100 Subject: [PATCH] Improve DeltaProcessor file change detection #3036 Try to fix BuildpathTests.testChangeZIPArchive1() on linux. Small changes in file length and timeStamp could have produced hash collisions due to simple hash function. https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3036 --- .../org/eclipse/jdt/core/tests/builder/BuildpathTests.java | 4 ++-- .../model/org/eclipse/jdt/internal/core/DeltaProcessor.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java index bc9b6bf4d54..c612a3dd9ad 100644 --- a/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java +++ b/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java @@ -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, ""); @@ -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); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java index f62651f5ecf..d21fd3a5d00 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java @@ -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; } /*