diff --git a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/EclipsePreferences.java b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/EclipsePreferences.java index 761b1dbe8eb..8a71f2c2ccf 100644 --- a/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/EclipsePreferences.java +++ b/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/EclipsePreferences.java @@ -19,9 +19,8 @@ import java.io.*; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; +import java.nio.file.*; import java.nio.file.Path; -import java.nio.file.StandardCopyOption; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.core.internal.runtime.RuntimeLog; @@ -271,7 +270,7 @@ protected static void convertFromProperties(EclipsePreferences node, Properties } } - private final Object writeLock = new Object(); + private static final Object WRITE_LOCK = new Object(); /* * Helper method to persist a Properties object to the filesystem. We use this @@ -287,13 +286,19 @@ private void write(Properties props, IPath location) throws BackingStoreExceptio try { Files.createDirectories(parentFile); String fileContent = removeTimestampFromTable(props); - synchronized (writeLock) { + synchronized (WRITE_LOCK) { if (Files.exists(preferenceFile)) { // Write new file content to a temporary file first to not loose the old content // in case of a failure. If everything goes OK, it is moved to the right place. Path tmp = preferenceFile.resolveSibling(preferenceFile.getFileName() + BACKUP_FILE_EXTENSION); Files.writeString(tmp, fileContent, StandardCharsets.UTF_8); - Files.move(tmp, preferenceFile, StandardCopyOption.REPLACE_EXISTING); + try { + Files.move(tmp, preferenceFile, StandardCopyOption.REPLACE_EXISTING); + } catch (NoSuchFileException e) { + // workaround for JDK-8325302 throws Exception if file is deleted in parallel. + // retry: + Files.move(tmp, preferenceFile, StandardCopyOption.REPLACE_EXISTING); + } } else { Files.writeString(preferenceFile, fileContent, StandardCharsets.UTF_8); }