App Engine: Reflection is not allowed on private j

2019-08-17 00:05发布

问题:

Today I went to deploy a java application I've created up to Google App Engine, and I am being roadblocked by some very unhelpful error messages.

Invocation of init method failed; nested exception is java.lang.SecurityException:
java.lang.IllegalAccessException: Reflection is not allowed on private 
java.lang.Throwable java.lang.Throwable.cause

Followed by a stack-trace that doesn't mention any of my classes: there is no line of my code I can point to as causing this.

This application uses Objectify and Spring MVC, and works fine on my local development server (App Engine version 1.7.4).

I've gone through my code and removed any mention of "cause" from any of the exception classes I use. I still have this problem. Also, there is only one type of Exception my controllers can throw, and this again makes no mention of cause.

Any ideas?

P.S. I found this discussion, but wasnt very informative.

回答1:

In case anyone else comes across similar problems, they have something to do with the code running under sandbox security restrictions when on the appengine servers, but without such restrictions when running on a local development server.

The sandbox restrictions don't allow reflection on private variables.

In my case, I was using Gson for serialization, which uses reflection heavily in ways that are difficult to debug. I still have no idea where or why it was trying to perform reflection on the Throwable thingie it talks about in the stack trace. Regardless, all of my problems went away when I switched to using Jackson instead.