java.lang.reflect.InvocationTargetException when using Kotlin-Mokito library - mockito

any() from Kotlin Mockito library crash with the following code
The Test Class
import com.nhaarman.mockito_kotlin.any
import com.nhaarman.mockito_kotlin.verify
import org.junit.Before
import org.junit.Test
import org.mockito.Mock
import org.mockito.MockitoAnnotations
class SimpleClassTest {
lateinit var simpleObject: SimpleClass
#Mock lateinit var injectedObject: InjectedClass
#Before
fun setUp() {
MockitoAnnotations.initMocks(this)
}
#Test
fun testSimpleFunction() {
simpleObject = SimpleClass(injectedObject)
simpleObject.simpleFunction()
verify(injectedObject).settingDependentObject(any())
}
}
The Source Class
import com.squareup.okhttp.Protocol
import com.squareup.okhttp.Request
import com.squareup.okhttp.Response
class SimpleClass(val injectedClass: InjectedClass) {
fun simpleFunction() {
injectedClass.settingDependentObject(Response.Builder()
.request(Request.Builder().url("https://example.com").build())
.code(200)
.body(null)
.protocol(Protocol.HTTP_1_1)
.build())
}
}
open class DependentClass(response: Response) {
}
open class InjectedClass() {
lateinit var response: Response
open fun settingDependentObject(response: Response) {
this.response = response
}
}
The Crash Log
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at kotlin.reflect.jvm.internal.FunctionCaller$Constructor.call(FunctionCaller.kt:63)
at kotlin.reflect.jvm.internal.KCallableImpl$DefaultImpls.call(KCallableImpl.kt:67)
at kotlin.reflect.jvm.internal.KFunctionImpl.call(KFunctionImpl.kt:30)
at kotlin.reflect.jvm.internal.KCallableImpl$DefaultImpls.callBy(KCallableImpl.kt:103)
at kotlin.reflect.jvm.internal.KFunctionImpl.callBy(KFunctionImpl.kt:30)
at com.nhaarman.mockito_kotlin.CreateInstanceKt.newInstance(CreateInstance.kt:138)
at com.nhaarman.mockito_kotlin.CreateInstanceKt.createInstance(CreateInstance.kt:60)
at com.elyeproj.phoneinfo.SimpleClassTest.testSimpleFunction(SimpleClassTest.kt:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.NullPointerException
at com.squareup.okhttp.Response.<init>(Response.java:56)
... 39 more

The library relies on the reflection to instantiate an object of a given type to be used as mockito "Any" object.
It might not be possible for those classes which have non-trivial constructors. Response is one of them.
If you could get an instance of Response somehow, you can use it instead like:
verify(injectedObject).settingDependentObject(Mockito.any<Response>() ?: someResponse)

Related

Issue populating map in Groovy

I've got an interesting issue in groovy, I am trying to populate a map and for some reason it doesn't work, here is the program (just made a bare-bones version to see the problem easier):
public class dd2 {
Map<String, String> subscriptions = ["Listing":"a Listing","Issue":"an Issue"]
Map<String, Object> subscriptionAttributes = new HashMap<String, Object>()
public static void main(String[] args) throws Exception {
def dd = new dd2()
dd.getSubscriptionAttributes()
}
def getSubscriptionAttributes(){
subscriptions.each {
def attributes = ""
println "getting ${it.key}"
subscriptionAttributes.put(it.key, attributes)
}
}
}
if I remove:
subscriptionAttributes.put(it.key, attributes)
it iterates through the whole map of subscriptions. If I try to add to the subscriptionAttributes map it will only get Listing until eventually I get stack overflow.
What am I doing wrong?
It's due to def getSubscriptionAttributes() method name - when getter method is defined Groovy uses it wherever you use a property name. So in your case you are getting:
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at JPLISAgent.c line: 844
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at JPLISAgent.c line: 844
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message transform method call failed at JPLISAgent.c line: 844
Exception in thread "main" java.lang.StackOverflowError
at sun.net.www.protocol.file.Handler.parseURL(Handler.java:67)
at java.net.URL.<init>(URL.java:622)
at java.net.URL.<init>(URL.java:490)
at sun.misc.URLClassPath$FileLoader.getResource(URLClassPath.java:1259)
at sun.misc.URLClassPath.getResource(URLClassPath.java:239)
at java.net.URLClassLoader$1.run(URLClassLoader.java:365)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at groovy.lang.Closure.call(Closure.java:416)
at groovy.lang.Closure.call(Closure.java:430)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.callClosureForMapEntry(DefaultGroovyMethods.java:5278)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2117)
at org.codehaus.groovy.runtime.dgm$164.invoke(Unknown Source)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:56)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at dd2.getSubscriptionAttributes(dd2.groovy:13)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1850)
at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3758)
at dd2.getProperty(dd2.groovy)
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174)
at groovy.lang.Closure.getPropertyTryThese(Closure.java:312)
at groovy.lang.Closure.getPropertyOwnerFirst(Closure.java:306)
at groovy.lang.Closure.getProperty(Closure.java:295)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:50)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at dd2$_getSubscriptionAttributes_closure1.doCall(dd2.groovy:16)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:430)
because when you say:
subscriptionAttributes.put(it.key, attributes)
Groovy actually tries doing:
getSubscriptionAttributes().put(it.key, attributes)
and you get into infinite loop.
Change your method name so it does not conflict with internal map variable and you're good.

thread-weaver with hibernate unit testing

I am trying to write a multithread unit test for my hibernate test.
I chose thread-weaver and got a little play with it.
I used the HSQL Database engine for my hibernate testing which is an in memory database.
It was working perfect until i wanted to write some multi thread unit tests.
Since i am new to thread weaver, i could make some newbie mistakes.
I knew the thread weaver is loading my class with its customized loader.
But in the #ThreadedBefore i try to set the sessionFactory for HSQL one. However, i got a bunch of error logs like
log4j:ERROR "org.apache.log4j.ConsoleAppender" was loaded by [sun.misc.Launcher$AppClassLoader#ece88d2].
log4j:ERROR Could not instantiate appender named "console".
log4j:ERROR A "org.apache.log4j.ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
log4j:ERROR [com.google.testing.instrumentation.InstrumentedClassLoader#2a57a184] whereas object of type
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:71)
at com.google.testing.threadtester.BaseThreadedTestRunner.runTests(BaseThreadedTestRunner.java:179)
at com.google.testing.threadtester.BaseThreadedTestRunner.runTests(BaseThreadedTestRunner.java:143)
at com.amazon.amazonclicksdali.test.simpleTest.run(simpleTest.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at com.intellij.junit4.JUnit4TestRunnerUtil$IgnoreIgnoredTestJUnit4ClassRunner.runChild(JUnit4TestRunnerUtil.java:306)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:68)
... 30 more
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:71)
at com.google.testing.threadtester.ThreadedTestWrapper.runTests(ThreadedTestWrapper.java:71)
... 35 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:68)
... 36 more
Caused by: java.lang.NullPointerException
at com.google.testing.instrumentation.InstrumentedClassLoader.loadClassData(InstrumentedClassLoader.java:152)
at com.google.testing.instrumentation.InstrumentedClassLoader.findClass(InstrumentedClassLoader.java:137)
at com.google.testing.instrumentation.InstrumentedClassLoader.loadClass(InstrumentedClassLoader.java:113)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:278)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:170)
at org.hibernate.cfg.Configuration.applyHibernateValidatorLegacyConstraintsOnDDL(Configuration.java:1663)
at org.hibernate.cfg.Configuration.applyConstraintsToDDL(Configuration.java:1653)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1445)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
at com.amazon.amazonclicksdali.test.scheduler.repository.TestSessionHelper.getSessionFactory(TestSessionHelper.java:20)
at com.amazon.amazonclicksdali.test.simpleTest.setup(simpleTest.java:45)
... 41 more
A simple test is like this
public class simpleTest {
Script<RDBInternalReportRepository> main;
Script<RDBInternalReportRepository> second;
final RDBInternalReportRepository target = new RDBInternalReportRepository();
SessionFactory sessionFactory;
RDBInternalReport internalReport1;
#Test
public void run() {
new ThreadedTestRunner().runTests(getClass(), RDBInternalReportRepository.class);
}
#ThreadedBefore
public void setup() throws Exception {
TestSessionHelper testSessionHelper = new TestSessionHelper();
sessionFactory = testSessionHelper.getSessionFactory();
target.setSessionFactory(sessionFactory);
internalReport1 = new RDBInternalReport();
internalReport1.setReferenceId("aaa");
internalReport1.setReportName("testReportName");
internalReport1.setSubmittedDate(new DateTime(2015, 1, 1, 0, 0));
internalReport1.setMarketplaceId(1);
internalReport1.setHashKey("hashValues");
internalReport1.setDedupingString("uid");
internalReport1.setState(ReportState.SUBMITTED);
internalReport1.setErrorCount(0);
target.createOrUpdateInternalReport(internalReport1);
}
#ThreadedTest
public void testSession() throws Exception {
main = new Script<RDBInternalReportRepository>(target);
second = new Script<RDBInternalReportRepository>(target);
main.addTask(new ScriptedTask<RDBInternalReportRepository>() {
#Override
public void execute() throws Exception {
IInternalReport report1 = target.getInternalReport("aaa");
releaseTo(second);
}
});
second.addTask(new ScriptedTask<RDBInternalReportRepository>() {
#Override
public void execute() throws Exception {
releaseTo(main);
}
});
new Scripter<RDBInternalReportRepository>(main, second).execute();
}
}
It fails to even load the sessionFactory which is a simple HSQL database.
It looks as though the NullPointerException is caused by getSystemResourceAsStream() returning null. See line 136 here: https://github.com/google/thread-weaver/blob/5c316abcfdfa1832df981f90cfa5c5811003012e/main/com/google/testing/instrumentation/InstrumentedClassLoader.java
I found the following question which sounds like a pretty good explanation as to what's going on: getSystemResourceAsStream() returns null
It sounds as though a fix might be to add the following to 'InstrumentedCLassLoader.findClass()'
InputStream input = getSystemResourceAsStream(resourceName);
if (input == null) {
return Thread.currentThread().getContextClassLoader().findClass(className);
}
Can you try building threadweaver from source with this fix? Alternatively, I would need to run your entire test and verify.

Injection of EntityManager in JSF

I am using injections but I have some problems :
HTTP Status 500 - javax.ejb.EJBException: The bean encountered a non-application exception; nested exception is:
type Exception report
message javax.ejb.EJBException: The bean encountered a non-application exception; nested exception is:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: javax.ejb.EJBException: The bean encountered a non-application exception; nested exception is:
java.lang.NullPointerException
javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
javax.faces.el.EvaluationException: javax.ejb.EJBException: The bean encountered a non-application exception; nested exception is:
java.lang.NullPointerException
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:98)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)
javax.faces.component.UICommand.broadcast(UICommand.java:311)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
javax.ejb.EJBException: The bean encountered a non-application exception; nested exception is:
java.lang.NullPointerException
org.apache.openejb.core.ivm.BaseEjbProxyHandler.convertException(BaseEjbProxyHandler.java:408)
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:312)
pl.konrad.daoTest.ServiceUzytkownik$$LocalBeanProxy.dodaj(pl/konrad/daoTest/ServiceUzytkownik.java)
pl.konrad.beans.UzytkownikBean.dodajUzytkownika(UzytkownikBean.java:84)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.el.parser.AstValue.invoke(AstValue.java:278)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:84)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)
javax.faces.component.UICommand.broadcast(UICommand.java:311)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NullPointerException
pl.konrad.daoTest.ServiceUzytkownik.dodaj(ServiceUzytkownik.java:17)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:181)
org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:100)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:85)
org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:227)
org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:194)
org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:308)
org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:303)
org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:92)
org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:308)
pl.konrad.daoTest.ServiceUzytkownik$$LocalBeanProxy.dodaj(pl/konrad/daoTest/ServiceUzytkownik.java)
pl.konrad.beans.UzytkownikBean.dodajUzytkownika(UzytkownikBean.java:84)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.el.parser.AstValue.invoke(AstValue.java:278)
org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:102)
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:84)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98)
javax.faces.component.UICommand.broadcast(UICommand.java:311)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat (TomEE)/7.0.55 (1.7.1) logs.
And this is my Bean :
#ManagedBean(name = "uzytkownikBean")
#ViewScoped
public class UzytkownikBean implements Serializable {
private static final long serialVersionUID = 1L;
private Uzytkownik uzytkownik;
private DataModel<Uzytkownik> modelUzytkownicy;
#EJB
private ServiceUzytkownik serviceUzytkownik;
public Uzytkownik getUzytkownik() {
return uzytkownik;
}
public void setUzytkownik(Uzytkownik uzytkownik) {
this.uzytkownik = uzytkownik;
}
public DataModel<Uzytkownik> getModelUzytkownicy() {
return modelUzytkownicy;
}
public void setModelUzytkownicy(ArrayDataModel<Uzytkownik> modelUzytkownicy) {
this.modelUzytkownicy = modelUzytkownicy;
}
#PostConstruct
public void init() {
uzytkownik = new Uzytkownik();
}
public void dodajUzytkownika() {
serviceUzytkownik.dodaj(uzytkownik);
}
}
And my EJB class :
#Stateless
public class ServiceUzytkownik {
#PersistenceContext
private EntityManager em;
public void dodaj(Uzytkownik uzytkownik) {
em.persist(uzytkownik);
}
}
Whats wrong now? and if I should add it to persistence.xml. This is my config for Hibernate. When creating a dynamic web project, would add connection so maybe it is unnecessary. But for now, I have to get rid of this error. Error connecting to the database probably looks different.
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="konrad" />
<property name="javax.persistence.jdbc.password" value="konrad" />
<property name="javax.persistence.jdbc.url"
value="jdbc:mysql://localhost:3306/bazahealthhelper" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
<property name="hibernate.hbm2ddl.auto" value="create" />
</properties>

LibGDX Desktop launch error

I have a game in Libgdx. It will now not run on the desktop version, or on android. When I run Main.java as desktop application, it sends these errors.. I will also post my code. Thanks.
Errors:
Exception in thread "main" java.lang.NoClassDefFoundError: com/badlogic/gdx/graphics/GLCommon
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.<init>(LwjglApplication.java:64)
at com.ahewdev.spacepace.Main.main(Main.java:17)
Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.graphics.GLCommon
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Desktop - Main.java code
package com.ahewdev.spacepace;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.ahewdev.spacepace.SpacePace;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.setup.resources.desktop.*;
public class Main {
public static void main(String[] args) {
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
cfg.title = "spacepace";
cfg.width = 480;
cfg.height = 320;
cfg.useGL20 = false;
new LwjglApplication(new SpacePace(), cfg);
}
}
EDIT:

MethodMissing doesn't catch method call for inner classes

Running this simple test will result in a groovy.lang.MissingMethodException for callInnerClass() only. The error indicates that it's looking for a static method A.bar().
Is there a reliable work around? Is groovy attempting type coercion before calling bar()? Why is it incorrectly assuming I am trying to call a static method off an instance?
class UnitTest2 {
#Test public void callInnerClass() {
new A.InnerA().bar()
}
#Test public void callOuterClass() {
new A().bar()
}
}
class A {
def methodMissing(String name, Object args) { return null }
public static class InnerA extends A {}
}
The full error is:
groovy.lang.MissingMethodException: No signature of method: static A.bar() is applicable for argument types: () values: []
Possible solutions: wait(), any(), wait(long), is(java.lang.Object), use([Ljava.lang.Object;), any(groovy.lang.Closure)
at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1373)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1359)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:822)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:164)
at A$InnerA.methodMissing(GroovyMethodMissingTest.groovy)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaClassImpl.invokeMissingMethod(MetaClassImpl.java:837)
at groovy.lang.MetaClassImpl.invokePropertyOrMissing(MetaClassImpl.java:1134)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1087)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:39)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at UnitTest2.callInnerClass(GroovyMethodMissingTest.groovy:239)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runners.Suite.runChild(Suite.java:127)
at org.junit.runners.Suite.runChild(Suite.java:26)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Resources