I wrote JUnit (4.10) unit test, which makes the following call com.google.appengine.api.ThreadManager:
ThreadManager.currentRequestThreadFactory();
When this test runs, I get NullPointerExceptionfrom this method currentRequestThreadFactory:
Caused by: java.lang.NullPointerException
at com.google.appengine.api.ThreadManager.currentRequestThreadFactory(ThreadManager.java:39)
at com.myapp.server.plumbing.di.BaseModule.providesThreadFactory(BaseModule.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
When I pull out the source for ThreadManagerand look at line 39 (which is the source of the NPE), I see:
public static ThreadFactory currentRequestThreadFactory() {
return (ThreadFactory) ApiProxy.getCurrentEnvironment().getAttributes()
.get(REQUEST_THREAD_FACTORY_ATTR);
}
Thus, it seems to be ApiProxy.getCurrentEnvironment()null, and when it is called getAttribute(), the NPE is thrown. I confirmed this by adding some new print statements above in my unit test code:
if(ApiProxy.getCurrentEnvironment() == null)
System.out.println("Environment is null.");
, GAE " " , ( ), . : GAE ? , ApiProxy ? , ? , (ThreadManager#currentRequestThreadFactory ApiProxy#getCurrentEnvironment), . .
. , appengine-testing.jar, SDK. JAR ApiProxyLocal.class, , , ApiProxy, JUnit, NPE. ( ), : ThreadManager ?