Safer casting in java config parsing
authorBill Erickson <berick@esilibrary.com>
Thu, 1 Nov 2012 13:41:52 +0000 (09:41 -0400)
committerDan Scott <dscott@laurentian.ca>
Fri, 14 Dec 2012 19:33:38 +0000 (14:33 -0500)
Java config parsing, in particular getString and getInt, no longer fail
when encountering a number value in the internl JSON->Map object.

Java does not allow the following cast:

String s = (String) someNumber;

Instead, rely on the object's toString() which is safe and guaranteed
to exist.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Signed-off-by: Dan Scott <dscott@laurentian.ca>
src/java/org/opensrf/util/Config.java

index ddac9c0..526d863 100644 (file)
@@ -78,7 +78,7 @@ public class Config {
      */
     public String getString(String path) throws ConfigException {
         try {
-            return (String) get(path);
+            return get(path).toString();
         } catch(Exception e) {
             throw new 
                 ConfigException("No config string found at " + path);