You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by km...@apache.org on 2011/04/27 23:24:45 UTC

svn commit: r1097247 - /db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java

Author: kmarsden
Date: Wed Apr 27 21:24:45 2011
New Revision: 1097247

URL: http://svn.apache.org/viewvc?rev=1097247&view=rev
Log:
DERBY-4617 Sysinfo.testSysinfoLocale failed with IBM  1.6 on Windows 7 64bit

Wrap getCononicalPath() in sysinfo.


Modified:
    db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java

Modified: db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java?rev=1097247&r1=1097246&r2=1097247&view=diff
==============================================================================
--- db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java (original)
+++ db/derby/code/trunk/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java Wed Apr 27 21:24:45 2011
@@ -44,6 +44,8 @@ import java.io.InputStream;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLDecoder;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.security.ProtectionDomain;
 import java.security.CodeSource;
 import java.security.AccessController;
@@ -366,6 +368,29 @@ public static void getMainInfo (java.io.
   } // end of getJavaProperty (String whichProperty)
 
 
+    /**
+     * wrapper for getCanonicalPath for sysinfo. For sysinfo we just want to print
+     * the security exceptions, not throw them if we don't have permmission
+     * 
+     * @param f file on which to call getCanonicalPath
+     * @return f.getCanonicalPath
+     * @throws IOException
+     */
+    private static String getCanonicalPath(final File f) throws IOException {
+
+        try {
+            return (String) AccessController
+                    .doPrivileged(new PrivilegedExceptionAction() {
+                        public Object run() throws IOException {
+                            return f.getCanonicalPath();
+                        }
+                    });
+        } catch (PrivilegedActionException pae) {
+            throw (IOException) pae.getCause();
+        } catch (SecurityException se) {
+            return Main.getTextMessage("SIF01.I", se);
+        }
+    }
 
   /**
     for use by the main () method
@@ -999,7 +1024,7 @@ public static void getMainInfo (java.io.
             InputStream bis = new FileInputStream(f);
 
             ZipInfoProperties zip = new ZipInfoProperties(ProductVersionHolder.getProductVersionHolderFromMyEnv(bis));
-            zip.setLocation(new File(dirname).getCanonicalPath().replace('/', File.separatorChar));
+            zip.setLocation(getCanonicalPath(new File(dirname)).replace('/', File.separatorChar));
             return zip;
         }
         catch (IOException ioe)
@@ -1048,7 +1073,7 @@ public static void getMainInfo (java.io.
             }
 
             ZipInfoProperties zip = new ZipInfoProperties(ProductVersionHolder.getProductVersionHolderFromMyEnv(bis));
-            zip.setLocation(new File(filename).getCanonicalPath().replace('/', File.separatorChar));
+            zip.setLocation(getCanonicalPath(new File(filename)).replace('/', File.separatorChar));
             return zip;
 
         }
@@ -1221,7 +1246,7 @@ public static void getMainInfo (java.io.
 
         String result = ""; 
         try {
-            result = new File(filename).getCanonicalPath().replace('/', File.separatorChar);
+            result = getCanonicalPath(new File(filename)).replace('/', File.separatorChar);
         } catch (IOException e) {
             result = e.getMessage();
         }