jdk/test/sun/tools/jps/JpsBase.java
changeset 39326 7493098fd9cd
parent 34327 50693d25f4a7
child 39736 f939432eb32a
--- a/jdk/test/sun/tools/jps/JpsBase.java	Mon Jun 13 09:03:32 2016 -0400
+++ b/jdk/test/sun/tools/jps/JpsBase.java	Wed Jun 15 11:24:12 2016 +0300
@@ -35,27 +35,28 @@
  */
 public final class JpsBase {
 
-    private static final String shortProcessName;
-    private static final String fullProcessName;
-
     /**
      * The jps output should contain processes' names
      * (except when jps is started in quite mode).
      * The expected name of the test process is prepared here.
      */
-    static {
+
+    private static String getShortProcessName() {
         URL url = JpsBase.class.getResource("JpsBase.class");
         boolean isJar = url.getProtocol().equals("jar");
+        return (isJar) ? JpsBase.class.getSimpleName() + ".jar" : JpsBase.class.getSimpleName();
+    }
 
+    private static String getFullProcessName() {
+        URL url = JpsBase.class.getResource("JpsBase.class");
+        boolean isJar = url.getProtocol().equals("jar");
         if (isJar) {
-            shortProcessName = JpsBase.class.getSimpleName() + ".jar";
             String urlPath = url.getPath();
             File jar = new File(urlPath.substring(urlPath.indexOf("file:") + 5, urlPath.indexOf("jar!") + 3));
-            fullProcessName = jar.getAbsolutePath();
-        } else {
-            shortProcessName = JpsBase.class.getSimpleName();
-            fullProcessName = JpsBase.class.getName();
+            return jar.getAbsolutePath();
         }
+
+        return JpsBase.class.getName();
     }
 
     public static void main(String[] args) throws Exception {
@@ -83,6 +84,7 @@
                     // or the full path name to the application's JAR file:
                     // 30673 /tmp/jtreg/jtreg-workdir/scratch/JpsBase.jar ...
                     isFull = true;
+                    String fullProcessName = getFullProcessName();
                     pattern = "^" + pid + "\\s+" + replaceSpecialChars(fullProcessName) + ".*";
                     output.shouldMatch(pattern);
                     break;
@@ -120,6 +122,7 @@
                 // Output should only contain lines with pids after the first line with pid.
                 JpsHelper.verifyJpsOutput(output, "^\\d+\\s+.*");
                 if (!isFull) {
+                    String shortProcessName = getShortProcessName();
                     pattern = "^" + pid + "\\s+" + replaceSpecialChars(shortProcessName);
                     if (combination.isEmpty()) {
                         // If no arguments are specified output should only contain