本文介绍了App Engine:私有java.lang.Throwable中不允许反射java.lang.Throwable.cause的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我去部署了一个我创建的Google App Engine的应用程序,并且我被一些无用的错误消息阻止。

 调用init方法失败;嵌套异常是java.lang.SecurityException:
java.lang.IllegalAccessException:私有
上不允许反射java.lang.Throwable java.lang.Throwable.cause

接下来是一个没有提及我的类的堆栈跟踪:我的代码没有一行可以指向导致这个。

这个应用程序使用Objectify和Spring MVC,并且在我的本地开发服务器(App Engine 1.7.4版本)上正常工作。



我已经通过了我的代码,并从我使用的任何异常类中删除了任何提及的cause。我仍然有这个问题。另外,我的控制器只能抛出一种类型的异常,这再次没有提及原因。



有什么想法?



PS我发现,但没有很多信息。

解决方案

如果有其他人遇到类似问题,他们与在沙箱安全限制下运行的代码有关appengine服务器,但在本地开发服务器上运行时没有这些限制。

沙箱限制不允许在私有变量上进行反射。

在我的例子中,我使用Gson进行序列化,这种方法使用反射的方式很难调试。我仍然不知道它试图在堆栈跟踪中讨论的Throwable thingie上进行反射的位置或原因。无论如何,当我转而使用杰克逊时,所有的问题都消失了。

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.

解决方案

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.

这篇关于App Engine:私有java.lang.Throwable中不允许反射java.lang.Throwable.cause的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 09:49