db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1025888 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java
Date Thu, 21 Oct 2010 08:53:30 GMT
Author: kahatlen
Date: Thu Oct 21 08:53:29 2010
New Revision: 1025888

URL: http://svn.apache.org/viewvc?rev=1025888&view=rev
Log:
DERBY-4859: Missing doPrivileged in DatabaseClasses.WriteClassFile()

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java?rev=1025888&r1=1025887&r2=1025888&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/reflect/DatabaseClasses.java
Thu Oct 21 08:53:29 2010
@@ -57,6 +57,9 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.Serializable;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 
 /**
 
@@ -181,13 +184,23 @@ abstract class DatabaseClasses
 		Object env = Monitor.getMonitor().getEnvironment();
 		File dir = env instanceof File ? (File) env : null;
 
-		File classFile = FileUtil.newFile(dir,filename);
+		final File classFile = FileUtil.newFile(dir,filename);
 
 		// find the error stream
 		HeaderPrintWriter errorStream = Monitor.getStream();
 
 		try {
-			FileOutputStream fis = new FileOutputStream(classFile);
+            FileOutputStream fis;
+            try {
+                fis = (FileOutputStream) AccessController.doPrivileged(
+                        new PrivilegedExceptionAction() {
+                            public Object run() throws IOException {
+                                return new FileOutputStream(classFile);
+                            }
+                        });
+            } catch (PrivilegedActionException pae) {
+                throw (IOException) pae.getCause();
+            }
 			fis.write(bytecode.getArray(),
 				bytecode.getOffset(), bytecode.getLength());
 			fis.flush();
@@ -197,7 +210,7 @@ abstract class DatabaseClasses
 			fis.close();
 		} catch (IOException e) {
 			if (SanityManager.DEBUG)
-				SanityManager.THROWASSERT("Unable to write .class file");
+				SanityManager.THROWASSERT("Unable to write .class file", e);
 		}
 	}
 



Mime
View raw message