Bug 538494 - NullPointerException in PerfCore.getHostName

- fix PerfCore getHostName() to check that project URI exists
  before accessing
- add warning message if URI doesn't exist

Change-Id: Iff242a0a70f4d75358e435593683900e8fa501c5
Reviewed-on: https://git.eclipse.org/r/128479
Tested-by: CI Bot
Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/Messages.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/Messages.java
index 550eaa2..6f986dc 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/Messages.java
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/Messages.java
@@ -18,6 +18,7 @@
 public class Messages extends NLS {
     private static final String BUNDLE_NAME = "org.eclipse.linuxtools.internal.perf.messages"; //$NON-NLS-1$
     public static String MsgProxyError;
+    public static String MsgNoProjectError;
     static {
         // initialize resource bundle
         NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfCore.java b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfCore.java
index bc3e529..465ff62 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfCore.java
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/PerfCore.java
@@ -16,6 +16,7 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintStream;
+import java.net.URI;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -43,6 +44,7 @@
 import org.eclipse.linuxtools.internal.perf.ui.PerfProfileView;
 import org.eclipse.linuxtools.profiling.launch.ConfigUtils;
 import org.eclipse.linuxtools.tools.launch.core.factory.RuntimeProcessFactory;
+import org.eclipse.osgi.util.NLS;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
@@ -117,6 +119,14 @@
         if(project == null){
             return null;
         }
+
+        URI projectURI = project.getLocationURI();
+        if (projectURI == null) {
+        	Status status = new Status(IStatus.WARNING, PerfPlugin.PLUGIN_ID,
+                    NLS.bind(Messages.MsgNoProjectError, projectName));
+            PerfPlugin.getDefault().getLog().log(status);
+            return null;
+        }
         return project.getLocationURI().getHost();
 
     }
diff --git a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/messages.properties b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/messages.properties
index 3b63b35..bb2c92e 100644
--- a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/messages.properties
+++ b/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/messages.properties
@@ -1 +1,2 @@
 MsgProxyError=Proxy could not be instantiated.
+MsgNoProjectError=Project {0} could not be located