Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPE in switch case #1714

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ public class ProxyManager implements IProxyService, IPreferenceChangeListener {
private ProxyManager() {
try {
String os = System.getProperty("osgi.os"); //$NON-NLS-1$
nativeProxyProvider = switch (os) {
case Constants.OS_LINUX -> new ProxyProviderLinux();
case Constants.OS_WIN32 -> new ProxyProviderWin32();
default -> null;
};
if (os != null) {
nativeProxyProvider = switch (os) {
case Constants.OS_LINUX -> new ProxyProviderLinux();
case Constants.OS_WIN32 -> new ProxyProviderWin32();
default -> null;
Copy link
Contributor

Choose a reason for hiding this comment

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

@laeubi you could also just write ...case null, default -> null;. The switch can deal with null, if it's declared in the cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if its not only the case on Java 21,... but even System.getProperty("osgi.os", "") would be possible... so many options :-D

Copy link
Contributor

Choose a reason for hiding this comment

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

right, I sometimes forget that not everyone is on 21 yet. :)

};
}
} catch (Exception e) {
Activator.logInfo("Problems occured during the proxy provider initialization.", e); //$NON-NLS-1$
}
Expand Down
Loading