Skip to content

Conversation

@laeubi
Copy link
Contributor

@laeubi laeubi commented Dec 20, 2025

In some cases the return value of Platform.getOS() can be null resulting in NPE being thrown but the method itself claims to return false "in all other cases".

This now uses null safe Objects.equals(..) to account for that and ensure the API claim.

Fix eclipse-platform/eclipse.platform.ui#3604

@github-actions
Copy link
Contributor

github-actions bot commented Dec 20, 2025

Test Results

 1 926 files   -  27   1 926 suites   - 27   1h 24m 37s ⏱️ - 6m 27s
 4 745 tests ±  0   4 720 ✅  -   1   24 💤 ±0  0 ❌ ±0  1 🔥 +1 
14 082 runs   - 153  13 899 ✅  - 154  182 💤 ±0  0 ❌ ±0  1 🔥 +1 

For more details on these errors, see this check.

Results for commit 26a8b12. ± Comparison against base commit 2f623a3.

♻️ This comment has been updated with latest results.

@eclipse-platform-bot
Copy link
Contributor

eclipse-platform-bot commented Dec 20, 2025

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

runtime/bundles/org.eclipse.core.runtime/META-INF/MANIFEST.MF

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 112cb7c4f1cba2ed987b20edbb342692088e5cce Mon Sep 17 00:00:00 2001
From: Eclipse Platform Bot <platform-bot@eclipse.org>
Date: Sat, 20 Dec 2025 08:41:26 +0000
Subject: [PATCH] Version bump(s) for 4.39 stream


diff --git a/runtime/bundles/org.eclipse.core.runtime/META-INF/MANIFEST.MF b/runtime/bundles/org.eclipse.core.runtime/META-INF/MANIFEST.MF
index 1eeb53d089..7ad1e9e8a7 100644
--- a/runtime/bundles/org.eclipse.core.runtime/META-INF/MANIFEST.MF
+++ b/runtime/bundles/org.eclipse.core.runtime/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
 Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
-Bundle-Version: 3.34.100.qualifier
+Bundle-Version: 3.34.200.qualifier
 Bundle-SymbolicName: org.eclipse.core.runtime; singleton:=true
 Bundle-Vendor: %providerName
 Bundle-Activator: org.eclipse.core.internal.runtime.PlatformActivator
-- 
2.52.0

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

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a NullPointerException in Platform.OS.is() by replacing direct equality comparison with null-safe Objects.equals(). When Platform.getOS() returns null in some cases, the original implementation would throw NPE, violating the method's contract that claims to return false "in all other cases".

Key Changes

  • Replaced Platform.getOS().equals(osString) with Objects.equals(Platform.getOS(), osString) for null-safe comparison
  • Added import for java.util.Objects

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 82 to 84
public static boolean is(String osString) {
return Platform.getOS().equals(osString);
return Objects.equals(Platform.getOS(), osString);
}
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

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

While this change correctly fixes the NPE issue, there's no test coverage for the case where Platform.getOS() returns null. Consider adding a test case to verify that OS.is() returns false when Platform.getOS() returns null, ensuring the documented behavior 'false in all other cases' is maintained even when the OS cannot be determined.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me that the Platform class doesn't work stand alone and that while we can fix symptoms of that, it will produce poor results so maybe better it fail dismally than just fail to work correctly.

For the reported problem it would be better to use SWT.getPlatform() as suggested in:

eclipse-platform/eclipse.platform.ui#3604 (comment)

We seem many uses of that:

Image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to me that the Platform class doesn't work stand alone and that while we can fix symptoms of that, it will produce poor results so maybe better it fail dismally than just fail to work correctly.

I'm not sure what you mean by "standalone" the class works perfectly fine and uses some kind of delegation model that ultimately falls back to using system properties. In any case I think using a defensive approach here is better than throwing an NPE or any other exception as it does not really helps the user here.

For the reported problem it would be better to use SWT.getPlatform() as suggested in:

Independent from that the Platform class needs to work (independent from SWT).

Copy link
Contributor

@basilevs basilevs Dec 20, 2025

Choose a reason for hiding this comment

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

Independent from that the Platform class needs to work

This can not be correct. Please see Platform class documentation - it requires Platform to be in Running state to be usable. Instead of returning strange values, it might be better to throw an explicit exception and refer clients to class documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can not be correct.

What specifically

Instead of returning strange values,

Why is it strange to say it is not windows if we can not detect it is windows?

it requires Platform to be in Running state to be usable

This is not particular true... the javadoc only says (emphasis by me)

A runtime exception might be thrown or incorrect result might be returned if a method from this class is called while Platform is not running.

So it perfectly aligns with the contracts of the class.

In some cases the return value of Platform.getOS() can be return null
but its API doc states it return Platform.OS_UNKNOWN is the OS can not
be found.

Fix eclipse-platform/eclipse.platform.ui#3604
@laeubi
Copy link
Contributor Author

laeubi commented Dec 20, 2025

I now fixed the Platform.getOS() that actually states it return Platform.OS_UNKNOWN in case the OS can not be determined.

@laeubi laeubi merged commit a3cab84 into eclipse-platform:master Dec 20, 2025
16 of 18 checks passed
@jeffecom
Copy link

It does seem a bit bizarre than one can include the specific SWT jar for a particular platform, yet SWT (or more specifically, the Forms API) can't tell what platform it's running on. That must raise a few eyebrows, and eyebrow elevation is not going to help with adoption levels. SWT is a good technology and good for standalone apps, but if people get counter-intuitive problems like this it can make people give up on SWT. Just my feeling - I'm an SWT fan.
Perhaps standalone mode is not a priority, but I think it should be supported at least. It's a very nice way to develop Java desktop apps. SWT is relatively easy to use and a very smooth developer experience so long as WindowBuilder cooperates.

If SWT and Forms work without knowing the OS in these cases, that seems fine so long as everything still looks ok.
If the visual representation doesn't change then no problems.
Currently my workaround is to add the JVM system property osgi.os=win32 to the standalone app at runtime.

It did notice that the style of Forms Section headers has changed. I think it looked better before. Is that configurable, or is it just like that now?

@basilevs
Copy link
Contributor

basilevs commented Dec 20, 2025

It does seem a bit bizarre than one can include the specific SWT jar for a particular platform, yet SWT (or more specifically, the Forms API) can't tell what platform it's running on.

This is Eclipse Platform. It can run without SWT or Forms. It can run without any graphical interfcae. Wirhout any graphical subsystem, on a headless hardware. It can be launched without binary executable from a raw Java command, without OS dependent code.

Do not confuse it with PlatformUI from Eclipse RCP.

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.

SWT standalone app fails to start with NPE "org.eclipse.core.runtime.Platform.getOS()" is null

5 participants