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 29m 49s ⏱️ + 3m 44s
 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 706f2f6. ± Comparison against base commit 2605191.

♻️ 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.

@basilevs basilevs force-pushed the issue_2290_contentsnpe branch from 5e2a755 to b60a035 Compare December 10, 2025 12:40
@basilevs
Copy link
Contributor Author

@jukzi could you please review this?

Copy link
Contributor

@jukzi jukzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NPE fix itself looks legit.

@basilevs basilevs force-pushed the issue_2290_contentsnpe branch from b60a035 to 3549904 Compare December 16, 2025 17:59
@basilevs
Copy link
Contributor Author

Build fails due to a dead mirror:

download from https://mirrors.jevincanders.net/eclipse/eclipse/updates/4.38/R-4.38-202512010920/plugins/org.eclipse.team.core_3.10.900.v20251104-0924.jar failed

@jukzi jukzi force-pushed the issue_2290_contentsnpe branch from e73e0d4 to 706f2f6 Compare December 16, 2025 18:34
@iloveeclipse iloveeclipse merged commit 66f6070 into eclipse-platform:master Dec 17, 2025
18 checks passed
@iloveeclipse
Copy link
Member

Thanks. Patch makes sense.

@basilevs basilevs deleted the issue_2290_contentsnpe branch December 17, 2025 15:39
@HeikoKlare
Copy link
Contributor

The test introduced with this PR sporadically fails on Windows, see:

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

5 participants