Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2020-10-28 15:15:42 +0000
committerAndrey Loskutov2020-10-28 15:15:42 +0000
commit13bd8d6d0429e44bd59cd28dbab4fea566442396 (patch)
tree974f2eb9da2e6ab3659afb0a893bed3f146ce0a4
parent12dad1e18bd3f5cad5dcf918476ce6a74c985649 (diff)
downloadeclipse.platform.ui-13bd8d6d0429e44bd59cd28dbab4fea566442396.tar.gz
eclipse.platform.ui-13bd8d6d0429e44bd59cd28dbab4fea566442396.tar.xz
eclipse.platform.ui-13bd8d6d0429e44bd59cd28dbab4fea566442396.zip
Bug 566490 - NPE in DesktopFileWriter.escapeSpaces
Avoid using raw values from system properties, they could be null. Also some smaller issues fixed - don't use != to compare strings - don't call same methods in a loop - don't use pattern matching just to remove "file:" prefix Change-Id: Ia6c0578cfb571ee54a260a2c5bb1a08b75473dd2 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/DesktopFileWriter.java4
-rw-r--r--bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/RegistrationLinux.java19
-rw-r--r--bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/RegistrationMacOsX.java3
3 files changed, 21 insertions, 5 deletions
diff --git a/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/DesktopFileWriter.java b/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/DesktopFileWriter.java
index e584319f8b9..34dbdfd4dbd 100644
--- a/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/DesktopFileWriter.java
+++ b/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/DesktopFileWriter.java
@@ -16,6 +16,7 @@ package org.eclipse.urischeme.internal.registration;
import static java.util.stream.Collectors.joining;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
@@ -172,6 +173,9 @@ public class DesktopFileWriter {
* @return The minimal file content as list (one entry = one file line)
*/
public static List<String> getMinimalDesktopFileContent(String eclipseExecutableLocation, String productName) {
+ if (eclipseExecutableLocation == null || eclipseExecutableLocation.isEmpty()) {
+ return Collections.emptyList();
+ }
String executable = escapeSpaces(eclipseExecutableLocation);
return Arrays.asList(//
"[Desktop Entry]", //$NON-NLS-1$
diff --git a/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/RegistrationLinux.java b/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/RegistrationLinux.java
index c0085fa69eb..bb63549dd28 100644
--- a/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/RegistrationLinux.java
+++ b/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/RegistrationLinux.java
@@ -70,12 +70,13 @@ public class RegistrationLinux implements IOperatingSystemRegistration {
public List<ISchemeInformation> getSchemesInformation(Collection<IScheme> schemes) throws Exception {
List<ISchemeInformation> returnList = new ArrayList<>();
+ String eclipseLauncher = getEclipseLauncher();
for (IScheme scheme : schemes) {
SchemeInformation schemeInfo = new SchemeInformation(scheme.getName(),
scheme.getDescription());
String location = determineHandlerLocation(scheme.getName());
- if (location.equals(getEclipseLauncher())) {
+ if (location.equals(eclipseLauncher)) {
schemeInfo.setHandled(true);
}
schemeInfo.setHandlerLocation(location);
@@ -96,6 +97,9 @@ public class RegistrationLinux implements IOperatingSystemRegistration {
String desktopFilePath) throws IOException {
List<String> lines = readFileOrGetInitialContent(desktopFilePath);
+ if (lines.isEmpty()) {
+ return;
+ }
DesktopFileWriter writer = new DesktopFileWriter(lines);
for (IScheme scheme : toAdd) {
@@ -152,12 +156,19 @@ public class RegistrationLinux implements IOperatingSystemRegistration {
@Override
public String getEclipseLauncher() {
- return System.getProperty("eclipse.launcher"); //$NON-NLS-1$
+ String property = System.getProperty("eclipse.launcher"); //$NON-NLS-1$
+ if (property == null) {
+ return getEclipseHomeLocation() + "eclipse"; //$NON-NLS-1$
+ }
+ return property;
}
private String getEclipseHomeLocation() {
- String homeLocationProperty = System.getProperty("eclipse.home.location"); //$NON-NLS-1$
- return homeLocationProperty.replaceAll("file:(.*)", "$1"); //$NON-NLS-1$ //$NON-NLS-2$
+ String homeLocationProperty = System.getProperty("eclipse.home.location", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ if (homeLocationProperty.startsWith("file:")) { //$NON-NLS-1$
+ return homeLocationProperty.substring("file:".length()); //$NON-NLS-1$
+ }
+ return homeLocationProperty;
}
/**
diff --git a/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/RegistrationMacOsX.java b/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/RegistrationMacOsX.java
index 0ad7a2652ed..25bcae1d795 100644
--- a/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/RegistrationMacOsX.java
+++ b/bundles/org.eclipse.urischeme/src/org/eclipse/urischeme/internal/registration/RegistrationMacOsX.java
@@ -61,12 +61,13 @@ public class RegistrationMacOsX implements IOperatingSystemRegistration {
public List<ISchemeInformation> getSchemesInformation(Collection<IScheme> schemes) throws Exception {
List<ISchemeInformation> returnList = new ArrayList<>();
+ String eclipseLauncher = getEclipseLauncher();
for (IScheme scheme : schemes) {
SchemeInformation schemeInfo = new SchemeInformation(scheme.getName(), scheme.getDescription());
String location = determineHandlerLocation(getLsRegisterOutput(), scheme.getName());
- if (location != "" && getEclipseLauncher().startsWith(location)) { //$NON-NLS-1$
+ if (!location.isEmpty() && eclipseLauncher.startsWith(location)) {
schemeInfo.setHandled(true);
}
schemeInfo.setHandlerLocation(location);

Back to the top