Skip to content

Conversation

@basilevs
Copy link
Contributor

@basilevs basilevs commented Nov 26, 2025

IFile.getContents(false) does thread unsafe existence checks, resulting in random exceptions.

/** like {@link #readAllBytes()} **/
@Override
public InputStream getContents(boolean force) throws CoreException {
ResourceInfo info = getResourceInfo(false, false);
int flags = getFlags(info);
checkAccessible(flags);
checkLocal(flags, DEPTH_ZERO);
return getLocalManager().read(this, force, null);
}

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)

Ideally, read operations should be synchronized with write operations, but that might break backward compatibility.

This PR works around one of such exceptions by adding an explicit null check.

Error handling is copied from thread-unsafe check:

/**
* Checks that this resource exists.
* If checkType is true, the type of this resource and the one in the tree must match.
*
* @exception CoreException if this resource does not exist
*/
public void checkExists(int flags, boolean checkType) throws CoreException {
if (!exists(flags, checkType)) {
String message = NLS.bind(Messages.resources_mustExist, getFullPath());
throw new ResourceException(IResourceStatus.RESOURCE_NOT_FOUND, getFullPath(), message, null);
}
}

Fixes #2290

@basilevs basilevs force-pushed the issue_2290_contentsnpe branch from bceb85e to 8c49f31 Compare November 26, 2025 17:28
@github-actions
Copy link
Contributor

github-actions bot commented Nov 26, 2025

Test Results

 1 953 files  ±0   1 953 suites  ±0   1h 28m 10s ⏱️ - 1m 28s
 4 745 tests +1   4 721 ✅ +1   24 💤 ±0  0 ❌ ±0 
14 235 runs  +3  14 053 ✅ +3  182 💤 ±0  0 ❌ ±0 

Results for commit 5e2a755. ± Comparison against base commit 0edd6a1.

♻️ This comment has been updated with latest results.

@basilevs basilevs marked this pull request as draft November 26, 2025 18:09
@basilevs basilevs force-pushed the issue_2290_contentsnpe branch 2 times, most recently from 4e38707 to fc411ce Compare November 26, 2025 18:32
@basilevs basilevs marked this pull request as ready for review November 26, 2025 19:51
@basilevs basilevs force-pushed the issue_2290_contentsnpe branch from fc411ce to a5d5f6c Compare December 1, 2025 14:11
@eclipse-platform-bot
Copy link
Contributor

This pull request changes some projects for the first time in this development cycle.
Therefore the following files need a version increment:

resources/bundles/org.eclipse.core.resources/META-INF/MANIFEST.MF
resources/tests/org.eclipse.core.tests.resources/META-INF/MANIFEST.MF
resources/tests/org.eclipse.core.tests.resources/pom.xml

An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch.

Git patch
From 5084df88122db08c0f31b3a56707a9085d339ed1 Mon Sep 17 00:00:00 2001
From: Eclipse Platform Bot <platform-bot@eclipse.org>
Date: Mon, 1 Dec 2025 14:19:58 +0000
Subject: [PATCH] Version bump(s) for 4.39 stream


diff --git a/resources/bundles/org.eclipse.core.resources/META-INF/MANIFEST.MF b/resources/bundles/org.eclipse.core.resources/META-INF/MANIFEST.MF
index 82730f0630..f089e0fbcc 100644
--- a/resources/bundles/org.eclipse.core.resources/META-INF/MANIFEST.MF
+++ b/resources/bundles/org.eclipse.core.resources/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.core.resources; singleton:=true
-Bundle-Version: 3.23.100.qualifier
+Bundle-Version: 3.23.200.qualifier
 Bundle-Activator: org.eclipse.core.resources.ResourcesPlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/resources/tests/org.eclipse.core.tests.resources/META-INF/MANIFEST.MF b/resources/tests/org.eclipse.core.tests.resources/META-INF/MANIFEST.MF
index 0af9e7d8aa..ca13fe1630 100644
--- a/resources/tests/org.eclipse.core.tests.resources/META-INF/MANIFEST.MF
+++ b/resources/tests/org.eclipse.core.tests.resources/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: Eclipse Core Tests Resources
 Bundle-SymbolicName: org.eclipse.core.tests.resources; singleton:=true
-Bundle-Version: 3.11.1100.qualifier
+Bundle-Version: 3.11.1200.qualifier
 Bundle-Vendor: Eclipse.org
 Export-Package: org.eclipse.core.tests.filesystem,
  org.eclipse.core.tests.internal.alias,
diff --git a/resources/tests/org.eclipse.core.tests.resources/pom.xml b/resources/tests/org.eclipse.core.tests.resources/pom.xml
index 8ae4d950ae..8e86a6785a 100644
--- a/resources/tests/org.eclipse.core.tests.resources/pom.xml
+++ b/resources/tests/org.eclipse.core.tests.resources/pom.xml
@@ -18,7 +18,7 @@
     <version>4.39.0-SNAPSHOT</version>
   </parent>
   <artifactId>org.eclipse.core.tests.resources</artifactId>
-  <version>3.11.1100-SNAPSHOT</version>
+  <version>3.11.1200-SNAPSHOT</version>
   <packaging>eclipse-test-plugin</packaging>
 
   <properties>
-- 
2.51.2

Further information are available in Common Build Issues - Missing version increments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NPE when reading a non-existent File

2 participants