yong-hu / objenesis

Automatically exported from code.google.com/p/objenesis
0 stars 0 forks source link

Objenesis can't work on the Google Apps Engine #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Trying to use objenesis on GAE the following exception is thrown

java.lang.NoClassDefFoundError: sun.reflect.ReflectionFactory is a restricted 
class. 
Please see the Google  App Engine developer's guide for more details.
at 
com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java
:51)
at 
org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.<init>(SunReflec
tionFactoryInstantiator.java:40)
at 
org.objenesis.strategy.StdInstantiatorStrategy.newInstantiatorOf(StdInstantiator
Strategy.java:85)
at org.objenesis.ObjenesisBase.getInstantiatorOf(ObjenesisBase.java:90)
at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:73)

Original issue reported on code.google.com by mario.fu...@gmail.com on 9 Oct 2010 at 10:34

GoogleCodeExporter commented 9 years ago
Objenesis is indeed using some restricted classes. I'm not sure we can 
workaround it.

Some insider information (from Google App Engine team) would be really helpful

Anyhow, we'll look into it.

Original comment by henri.tr...@gmail.com on 7 Nov 2010 at 2:51

GoogleCodeExporter commented 9 years ago

Original comment by henri.tr...@gmail.com on 7 Nov 2010 at 2:58

GoogleCodeExporter commented 9 years ago

Original comment by henri.tr...@gmail.com on 7 Nov 2010 at 2:59

GoogleCodeExporter commented 9 years ago
It also a problem for lamdaj

Original comment by grego...@gmail.com on 10 Aug 2011 at 6:10

GoogleCodeExporter commented 9 years ago

Original comment by henri.tr...@gmail.com on 23 Jan 2013 at 10:32

GoogleCodeExporter commented 9 years ago
Was there any chance on making Objenesis work with GAE? If we implement our own 
version of sun.reflect.ReflectionFactory, would be a work-around?

Original comment by xyb...@gmail.com on 4 Apr 2013 at 8:49

GoogleCodeExporter commented 9 years ago
I would of course be interested. Can someone try Unsafe.allocateInstance? I 
will as soon as I have the time but I can't say when.

Then, if someone has an answer, I'm listening.

Original comment by henri.tr...@gmail.com on 4 Apr 2013 at 10:55

GoogleCodeExporter commented 9 years ago
(Disclaimer: I'm a Googler, but I have no particular insider knowledge of App 
Engine)

I had a bit of time, so I tried Unsafe.allocateInstance in a simple AppEngine 
app - it fails with an Exception similar to the above:

Unsafe.allocateInstance(TestAllocateInstance.class):
java.lang.NoClassDefFoundError: sun.misc.Unsafe is a restricted class. Please 
see the Google App Engine developer's guide for more details.
    at com.google.apphosting.runtime.security.shared.stub.sun.misc.Unsafe.<clinit>(Unsafe.java)

I also tried the ObjectStreamClass.newInstance() method that Objenesis can use; 
this fails when tweaking the accessibility of the method:

java.lang.SecurityException: java.lang.IllegalAccessException: Reflection is 
not allowed on java.lang.Object java.io.ObjectStreamClass.newInstance() throws 
java.lang.InstantiationException,java.lang.reflect.InvocationTargetException,jav
a.lang.UnsupportedOperationException
    at com.google.appengine.runtime.Request.process-4e7d974abb397f1b(Request.java)
    at java.lang.reflect.Method.setAccessible(Method.java:135)

Interestingly, this latter approach works fine in the dev appserver but fails 
when running in the production App Engine environment.

As I understand it, it'd probably be considered a failure of App Engine's 
sandbox for these sorts of techniques to work.

Original comment by i...@google.com on 16 Apr 2013 at 10:17

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

Original comment by henri.tr...@gmail.com on 21 Aug 2013 at 9:01