commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r389911 - in /jakarta/commons/proper/lang/trunk/src: java/org/apache/commons/lang/SystemUtils.java test/org/apache/commons/lang/SystemUtilsTest.java
Date Wed, 29 Mar 2006 22:22:36 GMT
Author: scolebourne
Date: Wed Mar 29 14:22:32 2006
New Revision: 389911

URL: http://svn.apache.org/viewcvs?rev=389911&view=rev
Log:
Handle badly formatted java version numbers without exceptions

Modified:
    jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/SystemUtils.java
    jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/SystemUtilsTest.java

Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/SystemUtils.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/SystemUtils.java?rev=389911&r1=389910&r2=389911&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/SystemUtils.java (original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/SystemUtils.java Wed
Mar 29 14:22:32 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2005 The Apache Software Foundation.
+ * Copyright 2002-2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -1114,7 +1114,11 @@
         if (JAVA_VERSION_TRIMMED.length() >= 5) {
             str = str + JAVA_VERSION_TRIMMED.substring(4, 5);
         }
-        return Float.parseFloat(str);
+        try {
+            return Float.parseFloat(str);
+        } catch (Exception ex) {
+            return 0;
+        }
     }
     
     /**
@@ -1142,7 +1146,11 @@
         } else {
             str = str + "0";
         }
-        return Integer.parseInt(str);
+        try {
+            return Integer.parseInt(str);
+        } catch (Exception ex) {
+            return 0;
+        }
     }
 
     /**

Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/SystemUtilsTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/SystemUtilsTest.java?rev=389911&r1=389910&r2=389911&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/SystemUtilsTest.java
(original)
+++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/SystemUtilsTest.java
Wed Mar 29 14:22:32 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003,2004 The Apache Software Foundation.
+ * Copyright 2003,2004,2006 The Apache Software Foundation.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -83,7 +83,11 @@
         if (JAVA_VERSION_TRIMMED.length() >= 5) {
             str = str + JAVA_VERSION_TRIMMED.substring(4, 5);
         }
-        return Float.parseFloat(str);
+        try {
+            return Float.parseFloat(str);
+        } catch (Exception ex) {
+            return 0;
+        }
     }
 
     /**
@@ -111,7 +115,11 @@
         } else {
             str = str + "0";
         }
-        return Integer.parseInt(str);
+        try {
+            return Integer.parseInt(str);
+        } catch (Exception ex) {
+            return 0;
+        }
     }
 
     /**
@@ -324,6 +332,9 @@
         JAVA_VERSION = "JavaVM-1.3.1";  //HP-UX
         JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
         assertEquals(1.31f, getJavaVersionAsFloat(), 0.000001f);
+        JAVA_VERSION = "XXX-1.3.x";  //error
+        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
+        assertEquals(0.0f, getJavaVersionAsFloat(), 0.000001f);
     }
 
     public void testJavaVersionAsInt() {
@@ -357,6 +368,9 @@
         JAVA_VERSION = "JavaVM-1.3.1";  //HP-UX
         JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
         assertEquals(131, getJavaVersionAsInt());
+        JAVA_VERSION = "XXX-1.3.x";  //error
+        JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
+        assertEquals(0, getJavaVersionAsInt());
     }
 
     public void testJavaVersionAtLeastFloat() {



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message