slf4j AccessControlException on app engine

2019-07-20 02:00发布

All I am trying to do is use luceneappengine's GaeDirectory. Apparently it needed to have slf4j. So I added the jar slf4j-api-1.7.12.jar to my project. Now I am getting the following error trace. So luceneappengine is created expressly for GAE. So why in the world would it require a logger that is not readily supported when Java itself comes with a logger? What am I missing here?

com.google.api.server.spi.SystemService invokeServiceMethod: exception occurred while calling backed method
java.lang.ExceptionInInitializerError
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:149)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:120)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:331)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:283)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:304)
    at com.googlecode.luceneappengine.GaeDirectory.<clinit>(GaeDirectory.java:56)
    …
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:45)
    at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:359)
    at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:160)
    at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:118)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "createSecurityManager")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:382)
    at java.security.AccessController.checkPermission(AccessController.java:572)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.<init>(SecurityManager.java:299)
    at org.slf4j.helpers.Util$ClassContextSecurityManager.<init>(Util.java:43)
    at org.slf4j.helpers.Util$ClassContextSecurityManager.<init>(Util.java:43)
    at org.slf4j.helpers.Util.<clinit>(Util.java:49)
    ... 42 more

3条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-20 02:13

SLF4J should work, are you sure you are using the same version defined in LAE's dependencies?

Try the setup explained in here: http://blog.xam.de/2010/03/logging-in-google-appengine-for-java.html

查看更多
戒情不戒烟
3楼-- · 2019-07-20 02:21

The problem you encounter identified by the following exception (same as the root cause given above)

Caused by: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "createSecurityManager")
  at java.security.AccessControlContext.checkPermission(AccessControlContext.java:382)
  at java.security.AccessController.checkPermission(AccessController.java:572)
  at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
  at java.lang.SecurityManager.<init>(SecurityManager.java:299)
  at org.slf4j.helpers.Util$ClassContextSecurityManager.<init>(Util.java:43)
  at org.slf4j.helpers.Util$ClassContextSecurityManager.<init>(Util.java:43)
  at org.slf4j.helpers.Util.<clinit>(Util.java:49)

is specific to slf4j-api versions 1.7.9 to 1.7.12. It is fixed in version 1.7.13 which was released yesterday to fix this same issue.

查看更多
老娘就宠你
4楼-- · 2019-07-20 02:25

I encountered this same problem and it turned out to be because I had 2 slf4j implementations. I was explicitly using slf4j-jdk14, which seems to be the recommended implementation for GAE, and one of my libraries (Apache Jena) was bringing in slf4j-log4j12.

Somewhere in my debug output (as well as the error you list above) was org.slf4j.LoggerFactory.reportMultipleBindingAmbiguity (as well as the AccessControlException).

I'm not sure why Jena would include slf4j-log4j12 - my other libraries just depend on the slf4j-api and leave the choice of implementation to the user. In any event, I excluded slf4j-log4j12 from Jena, which in my case looks like this:

compile ('org.apache.jena:apache-jena-libs:2.11.1')   {
    exclude group: 'org.slf4j', module: 'slf4j-log4j12'
}

And things started working again.

查看更多
登录 后发表回答