Search code examples
javagoogle-app-enginejakarta-ee

java.security.AccessControlException: access denied ("java.io.FilePermission" "C:\tempFolder" "read") on GAE


I am migrating my application from Tomcat to Google App Engine (1.9.1). I am running jsf 2.2 on servlet 2.5 and I am facing an issue with reading files from file system. I have code that creates a file on the file system as follows:

File file = new File("C:\\tempFolder");
if(file.isDirectory()){
  // do writing stuff here
}

On Tomcat I was not getting any exceptions on the above code, but on Google App Engine I am getting the following exception:

Caused by: java.security.AccessControlException: access denied ("java.io.FilePermission" "C:\tempFolder" "read")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
    at java.security.AccessController.checkPermission(AccessController.java:559)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:429)

Why am I getting this exception, and how to fix it?


Solution

  • why i am getting this exception

    GAE environment is sandboxed for a number of reasons. This means that you cannot do a lot of things you could normally do on your local machine.

    This also includes write access to the file system.

    how to fix it

    Find another way to persist your data (database, for example).

    You can read a little bit more on sandbox restrictions here.