FELIX-2291 Catch NoSuchMethodError on pre-1.4 Java runtimes which do not have the Runtime.availableProcessors method

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@936174 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
index c7a1189..a700fb3 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
@@ -206,11 +206,17 @@
             json.put( "jvm", System.getProperty( "java.vm.name" ) + "(build " + System.getProperty( "java.vm.version" )
                 + ", " + System.getProperty( "java.vm.info" ) + ")" );
             json.put( "shutdownTimer", shutdownTimer );
-            json.put( "processors", Runtime.getRuntime().availableProcessors() );
             json.put( "mem_total", totalMem );
             json.put( "mem_free", freeMem );
             json.put( "mem_used", usedMem );
             json.put( "shutdownType", shutdownType );
+
+            // only add the processors if the number is available
+            final int processors = getAvailableProcessors();
+            if ( processors > 0 )
+            {
+                json.put( "processors", processors );
+            }
         }
         catch ( JSONException e )
         {
@@ -228,4 +234,24 @@
     {
         return ( StartLevel ) getService( START_LEVEL_NAME );
     }
+
+
+    /**
+     * Returns the number of processor available on Java 1.4 and newer runtimes.
+     * If the Runtime.availableProcessors() method is not available, this
+     * method returns -1.
+     */
+    private int getAvailableProcessors()
+    {
+        try
+        {
+            return Runtime.getRuntime().availableProcessors();
+        }
+        catch ( Throwable t )
+        {
+            // NoSuchMethodError on pre-1.4 runtimes
+        }
+
+        return -1;
+    }
 }