Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
henri-tremblay opened this issue Apr 8, 2015 · 7 comments
Closed

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

henri-tremblay opened this issue Apr 8, 2015 · 7 comments
Assignees
Milestone

Comments

@henri-tremblay
Copy link
Contributor

Original issue 12 created by henri-tremblay on 2010-10-09T10:34:41.000Z:

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>(SunReflectionFactoryInstantiator.java:40)
at org.objenesis.strategy.StdInstantiatorStrategy.newInstantiatorOf(StdInstantiatorStrategy.java:85)
at org.objenesis.ObjenesisBase.getInstantiatorOf(ObjenesisBase.java:90)
at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:73)

@henri-tremblay
Copy link
Contributor Author

Comment #1 originally posted by henri-tremblay on 2010-11-07T14:51:57.000Z:

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.

@henri-tremblay
Copy link
Contributor Author

Comment #4 originally posted by henri-tremblay on 2011-08-10T18:10:38.000Z:

It also a problem for lamdaj

@henri-tremblay
Copy link
Contributor Author

Comment #6 originally posted by henri-tremblay on 2013-04-04T20:49:37.000Z:

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?

@henri-tremblay
Copy link
Contributor Author

Comment #7 originally posted by henri-tremblay on 2013-04-04T22:55:53.000Z:

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.

@henri-tremblay
Copy link
Contributor Author

Comment #8 originally posted by henri-tremblay on 2013-04-16T10:17:59.000Z:

(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.(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,java.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.

@henri-tremblay
Copy link
Contributor Author

Comment #9 originally posted by henri-tremblay on 2013-08-03T13:08:30.000Z:

reflections.0.9.9-RC1.jar (https://code.google.com/p/reflections/)
working well in my google app engine project.
But I don't use it directly, I don't know if it can replace sun.reflect.ReflectionFactory.
Hope the jar have any help to the issue.

@henri-tremblay
Copy link
Contributor Author

No perfect solution seems possible so far. I've implemented the best I could so far https://github.com/easymock/objenesis/blob/master/SupportedJVMs.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant