[jboss-cvs] JBossAS SVN: r60538 - trunk/system/src/main/org/jboss/system/server.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 14 10:22:52 EST 2007


Author: dimitris at jboss.org
Date: 2007-02-14 10:22:52 -0500 (Wed, 14 Feb 2007)
New Revision: 60538

Modified:
   trunk/system/src/main/org/jboss/system/server/ServerInfo.java
Log:
JBAS-3838, avoid NPE at getThreadInfo

Modified: trunk/system/src/main/org/jboss/system/server/ServerInfo.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/ServerInfo.java	2007-02-14 15:22:19 UTC (rev 60537)
+++ trunk/system/src/main/org/jboss/system/server/ServerInfo.java	2007-02-14 15:22:52 UTC (rev 60538)
@@ -189,7 +189,7 @@
          }
       }
       
-      return name == null ? new ObjectName(OBJECT_NAME_STR) : name;
+      return name == null ? OBJECT_NAME : name;
    }
    
    public void postRegister(Boolean registrationDone)
@@ -569,8 +569,11 @@
             Long id = new Long(threads[i]);
             Long cpuTime = (Long) getThreadCpuTime.invoke(threadMXBean, new Object[] { id });
             Object threadInfo = getThreadInfo.invoke(threadMXBean, new Object[] { id, ZERO });
-            String name = (String) getThreadName.invoke(threadInfo, NO_PARAMS);
-            result.add(new ThreadCPU(name, cpuTime.longValue()));
+            if (threadInfo != null)
+            {
+               String name = (String) getThreadName.invoke(threadInfo, NO_PARAMS);
+               result.add(new ThreadCPU(name, cpuTime.longValue()));
+            }
          }
          return result;
       }
@@ -653,31 +656,40 @@
          {
             // get the threadId
             Long threadId = (Long)getThreadId.invoke(thread, NO_PARAMS);
+            sbuf.append(", threadId:").append(threadId);
+
             // get the ThreadInfo object for that threadId, max StackTraceElement depth
             Object threadInfo = getThreadInfo.invoke(threadMXBean,
                   new Object[] { threadId, new Integer(Integer.MAX_VALUE) });
-            // get misc info from ThreadInfo
-            Object threadState = getThreadState.invoke(threadInfo, NO_PARAMS); // enum
-            String lockName = (String)getLockName.invoke(threadInfo, NO_PARAMS);
-            //Long lockOwnerId = (Long)getLockOwnerId.invoke(threadInfo, NO_PARAMS);
-            //String lockOwnerName = (String)getLockOwnerName.invoke(threadInfo, NO_PARAMS);
-            Object[] stackTrace = (Object[])getStackTrace.invoke(threadInfo, NO_PARAMS);
-            
-            sbuf.append(", threadId:").append(threadId);
-            sbuf.append(", threadState:").append(threadState);
-            sbuf.append(", lockName:").append(lockName);
-            //sbuf.append(", lockOwnerId:").append(lockOwnerId);
-            //sbuf.append(", lockOwnerName:").append(lockOwnerName);
-            sbuf.append("<br>");
-            if (stackTrace.length > 0)
+            // JBAS-3838, thread might not be alive
+            if (threadInfo != null)
             {
-               sbuf.append("<blockquote>");
-               for (int i = 0; i < stackTrace.length; i++)
+               // get misc info from ThreadInfo
+               Object threadState = getThreadState.invoke(threadInfo, NO_PARAMS); // enum
+               String lockName = (String)getLockName.invoke(threadInfo, NO_PARAMS);
+               //Long lockOwnerId = (Long)getLockOwnerId.invoke(threadInfo, NO_PARAMS);
+               //String lockOwnerName = (String)getLockOwnerName.invoke(threadInfo, NO_PARAMS);
+               Object[] stackTrace = (Object[])getStackTrace.invoke(threadInfo, NO_PARAMS);
+
+               sbuf.append(", threadState:").append(threadState);
+               sbuf.append(", lockName:").append(lockName);
+               //sbuf.append(", lockOwnerId:").append(lockOwnerId);
+               //sbuf.append(", lockOwnerName:").append(lockOwnerName);
+               sbuf.append("<br>");
+               if (stackTrace.length > 0)
                {
-                  sbuf.append(stackTrace[i]).append("<br>");
+                  sbuf.append("<blockquote>");
+                  for (int i = 0; i < stackTrace.length; i++)
+                  {
+                     sbuf.append(stackTrace[i]).append("<br>");
+                  }
+                  sbuf.append("</blockquote>");
                }
-               sbuf.append("</blockquote>");
             }
+            else
+            {
+               sbuf.append("<br>");
+            }
          }
          catch (Exception ignore)
          {
@@ -879,4 +891,4 @@
       public int threads;
       public int groups;
    }
-}
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list