-
Notifications
You must be signed in to change notification settings - Fork 147
Open
Labels
bugSomething isn't workingSomething isn't working
Description
IFile.getContents(false) throws NPE in a race with deletion operation.
Steps to reproduce
Paste Junit test in git/eclipse.platform/resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/regression/IFileTest.java and run it
@Test
public void coreExceptionFromGetContentsForDeleted() throws CoreException {
IProject project = getWorkspace().getRoot().getProject("MyProject");
IFile subject = project.getFile("subject.txt");
Job noise = Job.create("Create/delete", monitor -> {
try {
while (!monitor.isCanceled()) {
createInWorkspace(subject);
subject.delete(true, null);
}
} catch (CoreException e) {
return e.getStatus();
}
return Status.OK_STATUS;
});
noise.setPriority(Job.INTERACTIVE);
long stop = currentTimeMillis() + 1000;
try {
noise.schedule();
while (currentTimeMillis() < stop) {
assertContentAccessibleOrNotFound(subject); // should not throw
}
} finally {
noise.cancel();
}
}
/**
* @param file
* - a resource to read
*/
private void assertContentAccessibleOrNotFound(IFile file) {
try (InputStream contents = file.getContents(false)) {
contents.transferTo(OutputStream.nullOutputStream());
} catch (IOException e) {
throw new AssertionError(e);
} catch (CoreException e) {
switch (e.getStatus().getCode()) {
case IResourceStatus.RESOURCE_NOT_LOCAL:
case IResourceStatus.RESOURCE_NOT_FOUND:
case IResourceStatus.FAILED_READ_LOCAL:
case IResourceStatus.OUT_OF_SYNC_LOCAL:
break;
default:
throw new AssertionError(e);
}
}
}
Alternatively pull the test from basilevs@c2ef43f
Expected result
CoreException is occasionally thrown
Actual result
java.lang.NullPointerException: Cannot invoke "org.eclipse.core.internal.resources.ResourceInfo.getLocalSyncInfo()" because "info" is null
at org.eclipse.core.internal.localstore.FileSystemResourceManager.getFileStore(FileSystemResourceManager.java:938)
at org.eclipse.core.internal.localstore.FileSystemResourceManager.read(FileSystemResourceManager.java:919)
at org.eclipse.core.internal.resources.File.getContents(File.java:361)
at org.eclipse.core.tests.resources.regression.IFileTest.assertContentAccessibleOrNotFound(IFileTest.java:166)
at org.eclipse.core.tests.resources.regression.IFileTest.coreExceptionFromGetContentsForDeleted(IFileTest.java:154)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Environment
Eclipse SDK
Version: 2025-12 (4.38)
Build id: I20251125-1800
OS: Mac OS X, v.12.7.6, aarch64 / cocoa
Java vendor: Oracle Corporation
Java runtime version: 25+36-3489
Java version: 25
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working