Merge
authormduigou
Mon, 14 Feb 2011 10:48:46 -0800
changeset 8393 582bd30ef587
parent 8392 3e5784c9f73e (current diff)
parent 8391 6fc6aef1be12 (diff)
child 8394 49215a09f282
Merge
--- a/jdk/src/share/classes/sun/tools/jps/Jps.java	Mon Feb 14 10:38:51 2011 -0800
+++ b/jdk/src/share/classes/sun/tools/jps/Jps.java	Mon Feb 14 10:48:46 2011 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -77,9 +77,52 @@
                 MonitoredVm vm = null;
                 String vmidString = "//" + lvmid + "?mode=r";
 
+                String errorString = null;
+
                 try {
+                    // Note: The VM associated with the current VM id may
+                    // no longer be running so these queries may fail. We
+                    // already added the VM id to the output stream above.
+                    // If one of the queries fails, then we try to add a
+                    // reasonable message to indicate that the requested
+                    // info is not available.
+
+                    errorString = " -- process information unavailable";
                     VmIdentifier id = new VmIdentifier(vmidString);
                     vm = monitoredHost.getMonitoredVm(id, 0);
+
+                    errorString = " -- main class information unavailable";
+                    output.append(" " + MonitoredVmUtil.mainClass(vm,
+                            arguments.showLongPaths()));
+
+                    if (arguments.showMainArgs()) {
+                        errorString = " -- main args information unavailable";
+                        String mainArgs = MonitoredVmUtil.mainArgs(vm);
+                        if (mainArgs != null && mainArgs.length() > 0) {
+                            output.append(" " + mainArgs);
+                        }
+                    }
+                    if (arguments.showVmArgs()) {
+                        errorString = " -- jvm args information unavailable";
+                        String jvmArgs = MonitoredVmUtil.jvmArgs(vm);
+                        if (jvmArgs != null && jvmArgs.length() > 0) {
+                          output.append(" " + jvmArgs);
+                        }
+                    }
+                    if (arguments.showVmFlags()) {
+                        errorString = " -- jvm flags information unavailable";
+                        String jvmFlags = MonitoredVmUtil.jvmFlags(vm);
+                        if (jvmFlags != null && jvmFlags.length() > 0) {
+                            output.append(" " + jvmFlags);
+                        }
+                    }
+
+                    errorString = " -- detach failed";
+                    monitoredHost.detach(vm);
+
+                    System.out.println(output);
+
+                    errorString = null;
                 } catch (URISyntaxException e) {
                     // unexpected as vmidString is based on a validated hostid
                     lastError = e;
@@ -87,7 +130,7 @@
                 } catch (Exception e) {
                     lastError = e;
                 } finally {
-                    if (vm == null) {
+                    if (errorString != null) {
                         /*
                          * we ignore most exceptions, as there are race
                          * conditions where a JVM in 'jvms' may terminate
@@ -95,7 +138,7 @@
                          * Other errors, such as access and I/O exceptions
                          * should stop us from iterating over the complete set.
                          */
-                        output.append(" -- process information unavailable");
+                        output.append(errorString);
                         if (arguments.isDebug()) {
                             if ((lastError != null)
                                     && (lastError.getMessage() != null)) {
@@ -110,33 +153,6 @@
                         continue;
                     }
                 }
-
-                output.append(" ");
-                output.append(MonitoredVmUtil.mainClass(vm,
-                        arguments.showLongPaths()));
-
-                if (arguments.showMainArgs()) {
-                    String mainArgs = MonitoredVmUtil.mainArgs(vm);
-                    if (mainArgs != null && mainArgs.length() > 0) {
-                        output.append(" ").append(mainArgs);
-                    }
-                }
-                if (arguments.showVmArgs()) {
-                    String jvmArgs = MonitoredVmUtil.jvmArgs(vm);
-                    if (jvmArgs != null && jvmArgs.length() > 0) {
-                      output.append(" ").append(jvmArgs);
-                    }
-                }
-                if (arguments.showVmFlags()) {
-                    String jvmFlags = MonitoredVmUtil.jvmFlags(vm);
-                    if (jvmFlags != null && jvmFlags.length() > 0) {
-                        output.append(" ").append(jvmFlags);
-                    }
-                }
-
-                System.out.println(output);
-
-                monitoredHost.detach(vm);
             }
         } catch (MonitorException e) {
             if (e.getMessage() != null) {
--- a/jdk/test/java/nio/file/Files/walkFileTree/PrintFileTree.java	Mon Feb 14 10:38:51 2011 -0800
+++ b/jdk/test/java/nio/file/Files/walkFileTree/PrintFileTree.java	Mon Feb 14 10:48:46 2011 -0800
@@ -54,6 +54,7 @@
         if (followLinks)
             options.add(FileVisitOption.FOLLOW_LINKS);
 
+        final boolean follow = followLinks;
         final boolean reportCycles = printCycles;
         Files.walkFileTree(dir, options, Integer.MAX_VALUE, new FileVisitor<Path>() {
             @Override
@@ -63,8 +64,7 @@
             }
             @Override
             public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
-                if (!attrs.isDirectory() || reportCycles)
-                    System.out.println(file);
+                System.out.println(file);
                 return FileVisitResult.CONTINUE;
             }
             @Override
@@ -79,11 +79,13 @@
             public FileVisitResult visitFileFailed(Path file, IOException exc)
                 throws IOException
             {
-                if (reportCycles && (exc instanceof FileSystemLoopException)) {
-                    System.out.println(file);
+                if (follow && (exc instanceof FileSystemLoopException)) {
+                    if (reportCycles)
+                        System.out.println(file);
                     return FileVisitResult.CONTINUE;
+                } else {
+                    throw exc;
                 }
-                throw exc;
             }
         });
     }