Java lang reflect invocationtargetexception null как исправить

I have a REST API project in jersey and hk2 used. Now, I convert is to spring boot project and keep jersey endpoints and DI in hk2. it seems that it is working except the following error. But I have no idea why the following error happens. Any hints welcomed. I will provide more details as requested. I have no idea what the error is about.

Thanks

Error:

java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161]
    at org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl.useContextualLobCreation(LobCreatorBuilderImpl.java:113) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl.makeLobCreatorBuilder(LobCreatorBuilderImpl.java:54) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl.<init>(JdbcEnvironmentImpl.java:271) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:114) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:858) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:885) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58) [hibernate-core-5.2.10.Final.jar:5.2.10.Final]
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79) [javax.persistence-api-2.2.jar:2.2]
    at com.opentext.eventbus.EMFFactory.<init>(EMFFactory.java:38) [classes/:na]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [na:1.8.0_161]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [na:1.8.0_161]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [na:1.8.0_161]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [na:1.8.0_161]
    at org.glassfish.hk2.utilities.reflection.ReflectionHelper.makeMe(ReflectionHelper.java:1375) [hk2-utils-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.createMe(ClazzCreator.java:272) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:366) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:487) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:70) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2126) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:116) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:90) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.FactoryCreator.create(FactoryCreator.java:135) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:487) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:83) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.SingletonContext$1.compute(SingletonContext.java:71) [hk2-locator-2.5.0-b42.jar:na]
    at org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture$1.call(Cache.java:97) [hk2-utils-2.5.0-b42.jar:na]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_161]
    at org.glassfish.hk2.utilities.cache.Cache$OriginThreadAwareFuture.run(Cache.java:154) [hk2-utils-2.5.0-b42.jar:na]
    at org.glassfish.hk2.utilities.cache.Cache.compute(Cache.java:199) [hk2-utils-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.SingletonContext.findOrCreate(SingletonContext.java:122) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2126) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:116) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:698) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:78) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:212) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:229) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:358) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:487) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:70) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2126) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:116) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:90) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.FactoryCreator.create(FactoryCreator.java:135) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:487) [hk2-locator-2.5.0-b42.jar:na]
    at org.glassfish.jersey.inject.hk2.RequestContext.findOrCreate(RequestContext.java:83) [jersey-hk2-2.26.jar:na]
    at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2126) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:116) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:698) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:78) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:212) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:229) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:358) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:487) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:70) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2126) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:116) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:698) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:78) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:212) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:229) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:358) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:487) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:70) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2126) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:685) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:78) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.resolve(ClazzCreator.java:212) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(ClazzCreator.java:229) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:358) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:487) [hk2-locator-2.5.0-b42.jar:na]
    at org.glassfish.jersey.inject.hk2.RequestContext.findOrCreate(RequestContext.java:83) [jersey-hk2-2.26.jar:na]
    at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2126) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:777) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:740) [hk2-locator-2.5.0-b42.jar:na]
    at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:710) [hk2-locator-2.5.0-b42.jar:na]
    at org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.getInstance(AbstractHk2InjectionManager.java:184) [jersey-hk2-2.26.jar:na]
    at org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.getInstance(ImmediateHk2InjectionManager.java:54) [jersey-hk2-2.26.jar:na]
    at org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:129) [jersey-common-2.26.jar:na]
    at org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.getInstance(MethodHandler.java:284) [jersey-server-2.26.jar:na]
    at org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:75) [jersey-server-2.26.jar:na]
    at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:110) [jersey-server-2.26.jar:na]
    at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:113) [jersey-server-2.26.jar:na]
    at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:113) [jersey-server-2.26.jar:na]
    at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:113) [jersey-server-2.26.jar:na]
    at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:113) [jersey-server-2.26.jar:na]
    at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:93) [jersey-server-2.26.jar:na]
    at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:62) [jersey-server-2.26.jar:na]
    at org.glassfish.jersey.process.internal.Stages.process(Stages.java:197) [jersey-common-2.26.jar:na]
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:269) [jersey-server-2.26.jar:na]
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:272) [jersey-common-2.26.jar:na]
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:268) [jersey-common-2.26.jar:na]
    at org.glassfish.jersey.internal.Errors.process(Errors.java:316) [jersey-common-2.26.jar:na]
    at org.glassfish.jersey.internal.Errors.process(Errors.java:298) [jersey-common-2.26.jar:na]
    at org.glassfish.jersey.internal.Errors.process(Errors.java:268) [jersey-common-2.26.jar:na]
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:289) [jersey-common-2.26.jar:na]
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:256) [jersey-server-2.26.jar:na]
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:703) [jersey-server-2.26.jar:na]
    at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:416) [jersey-container-servlet-core-2.26.jar:na]
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:370) [jersey-container-servlet-core-2.26.jar:na]
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:389) [jersey-container-servlet-core-2.26.jar:na]
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:342) [jersey-container-servlet-core-2.26.jar:na]
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:229) [jersey-container-servlet-core-2.26.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.5.29.jar:8.5.29]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) [spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) [spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) [spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.0.5.RELEASE.jar:5.0.5.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_161]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_161]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.29.jar:8.5.29]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_161]
Caused by: java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented.
    at org.postgresql.Driver.notImplemented(Driver.java:669) ~[postgresql-42.1.4.jar:42.1.4]
    at org.postgresql.jdbc.PgConnection.createClob(PgConnection.java:1246) ~[postgresql-42.1.4.jar:42.1.4]
    ... 154 common frames omitted

part of persistence.xml

<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect" />

pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</version>
  </parent>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jersey</artifactId>
    </dependency>
   <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>5.2.10.Final</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-server</artifactId>
      <version>2.26</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.containers</groupId>
      <artifactId>jersey-container-servlet</artifactId>
      <version>2.26</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-json-jackson</artifactId>
      <version>2.26</version>
    </dependency>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>42.1.4</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.bundles.repackaged</groupId>
      <artifactId>jersey-guava</artifactId>
      <version>2.26-b01</version>
    </dependency>

  </dependencies>

Paul Samsotha's user avatar

Paul Samsotha

204k37 gold badges481 silver badges716 bronze badges

asked Apr 5, 2018 at 19:35

BAE's user avatar

0

Root problem

Caused by: java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented.

Looks like bug https://hibernate.atlassian.net/browse/HHH-12368

They recommended set property (I believe it’s the best workaround):

as workaround is to disable hibernate to detect this function by
setting flag hibernate.jdbc.lob.non_contextual_creation=true

The other solution described here: http://vkuzel.blogspot.com.cy/2016/03/spring-boot-jpa-hibernate-atomikos.html

Disable feature detection by this undocumented parameter. Check the org.hibernate.engine.jdbc.internal.JdbcServiceImpl.configure method for more details.
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false

So you can also try to add to your Spring boot properties file

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false

answered Apr 5, 2018 at 19:48

Yuriy Alevohin's user avatar

4

I am adding the compile time dependencies because otherwise it will not import the individual class files like Dockerfile, here is the end of the stacktrace.

:build (Thread[main,5,main]) started.
:build
Skipping task ':build' as it has no actions.
:build (Thread[main,5,main]) completed. Took 0.0 secs.
:createDockerfile (Thread[main,5,main]) started.
:createDockerfile
Executing task ':createDockerfile' (up-to-date check took 0.001 secs) due to:
  Task.upToDateWhen is false.
:createDockerfile (Thread[main,5,main]) completed. Took 0.016 secs.
:buildImage (Thread[main,5,main]) started.
:buildImage
Executing task ':buildImage' (up-to-date check took 0.0 secs) due to:
  Task has not declared any outputs.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Building image using context '/Users/abalz1/Work/nike/code/notificationeventproc/build/mydockerfile'.
Using Dockerfile '/Users/abalz1/Work/nike/code/notificationeventproc/build/mydockerfile/Dockerfile'
Using tag 'bmuschko/myimage' for image.
Running in a non-OSGi environment
"No custom request executor provider registrations found - using default: [org.glassfish.jersey.client.ClientAsyncExecutorFactory$1]."
:buildImage FAILED
:buildImage (Thread[main,5,main]) completed. Took 1.213 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildImage'.
> java.lang.reflect.InvocationTargetException-->null

* Try:
Run with --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':buildImage'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:62)
    at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:25)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:110)
    at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
    at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
    at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
    at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
    at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLauncher.java:158)
    at org.gradle.internal.Factories$1.create(Factories.java:22)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:52)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:155)
    at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGradleLauncher.java:36)
    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:103)
    at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradleLauncher.java:97)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:90)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:62)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:97)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:102)
    at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
    at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:47)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:32)
    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:77)
    at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:47)
    at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:51)
    at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:28)
    at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:43)
    at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:170)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
    at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
    at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
    at org.gradle.launcher.Main.doAction(Main.java:33)
    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
    at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Caused by: net.sf.cglib.proxy.UndeclaredThrowableException: java.lang.reflect.InvocationTargetException-->null
    at com.github.dockerjava.core.command.BuildImageResultCallback$$EnhancerByCGLIB$$6b522a0c.awaitImageId(<generated>)
    at com.github.dockerjava.core.command.BuildImageResultCallback$$EnhancerByCGLIB$$6b522a0c$awaitImageId.call(Unknown Source)
    at com.bmuschko.gradle.docker.tasks.image.DockerBuildImage.runRemoteCommand(DockerBuildImage.groovy:119)
    at com.bmuschko.gradle.docker.tasks.AbstractDockerRemoteApiTask$_start_closure1.doCall(AbstractDockerRemoteApiTask.groovy:48)
    at com.bmuschko.gradle.docker.utils.DockerThreadContextClassLoader.withClasspath(DockerThreadContextClassLoader.groovy:43)
    at com.bmuschko.gradle.docker.utils.ThreadContextClassLoader$withClasspath.call(Unknown Source)
    at com.bmuschko.gradle.docker.tasks.AbstractDockerRemoteApiTask.runInDockerClassPath(AbstractDockerRemoteApiTask.groovy:53)
    at com.bmuschko.gradle.docker.tasks.AbstractDockerRemoteApiTask$runInDockerClassPath.callCurrent(Unknown Source)
    at com.bmuschko.gradle.docker.tasks.AbstractDockerRemoteApiTask.start(AbstractDockerRemoteApiTask.groovy:47)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:226)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:219)
    at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:208)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:585)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:568)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
    ... 60 more
Caused by: java.lang.reflect.InvocationTargetException
    at java_lang_reflect_Method$invoke.call(Unknown Source)
    at com.bmuschko.gradle.docker.utils.DockerThreadContextClassLoader$_createPrintStreamProxyCallback_closure8.doCall(DockerThreadContextClassLoader.groovy:354)
    at com.sun.proxy.$Proxy74.invoke(Unknown Source)
    ... 77 more
Caused by: com.github.dockerjava.api.DockerClientException: Could not build image
    at com.github.dockerjava.core.command.BuildImageResultCallback.getImageId(BuildImageResultCallback.java:69)
    at com.github.dockerjava.core.command.BuildImageResultCallback.awaitImageId(BuildImageResultCallback.java:48)
    ... 80 more


BUILD FAILED

Total time: 41.01 secs
Stopped 0 compiler daemon(s).

Is it not able to build the image? If so why it seems pretty vague.

Error background

Java code occasionally reports an error, but it will not report an error under normal circumstances.

exception: java.lang.reflect.InvocationTargetException: null

2020-05-11 at 15:17:39 CST traceId:[] ERROR io.netty.util.internal.logging.AbstractInternalLogger 91 error-Unexpected exception: java.lang.reflect.InvocationTargetException: null 
    at sun.reflect.GeneratedMethodAccessor214. invoke(Unknown Source) ~[?:? ]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java: 43) ~[?:1.8 .0_192]
    at java.lang.reflect.Method.invoke(Method.java: 498) ~[?:1.8 .0_192]
    at org.yeauty.pojo.PojoEndpointServer.doOnClose(PojoEndpointServer.java: 121) [netty-websocket-spring-boot-starter-0.8.0.jar!/:? ]
    at org.yeauty.standard.WebSocketServerHandler.channelInactive(WebSocketServerHandler.java: 29) [netty-websocket-spring-boot-starter-0.8.0.jar!/:? ]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java: 257) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java: 243) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java: 236) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.handler.codec.ByteToMessageDecoder.channelInputClosed(ByteToMessageDecoder.java: 393) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java: 358) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java: 257) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java: 243) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java: 236) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelInactive(DefaultChannelPipeline.java: 1416) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java: 257) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java: 243) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java: 912) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.channel.AbstractChannel$AbstractUnsafe$ 8.run(AbstractChannel.java:816) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java: 163) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java: 416) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java: 515) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$ 5.run(SingleThreadEventExecutor.java:918) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.util.internal.ThreadExecutorMap$ 2.run(ThreadExecutorMap.java:74) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java: 30) [netty-all-4.1.38.Final.jar!/:4.1.38 .Final]
    at java.lang.Thread.run(Thread.java: 748) [?:1.8 .0_192]
Caused by: java.util.ConcurrentModificationException
    at java.util.HashMap$HashIterator.nextNode(HashMap.java: 1445) ~[?:1.8 .0_192]
    at java.util.HashMap$EntryIterator.next(HashMap.java: 1479) ~[?:1.8 .0_192]
    at java.util.HashMap$EntryIterator.next(HashMap.java: 1477) ~[?:1.8 .0_192]
    at com.jcdz.hbdservice.websocket.ServerWebSocket1.onClose(ServerWebSocket1.java: 38) ~[coalminehbdservice-1.0.jar!/:1.0 ]
    ... 25 more

Reason for error

There are many reasons for the error, I will only say the reason I came into contact:

(1) If (==) judgment statement is wrong

if( devMap. getOrDefault ( “locationcode”,”” ) == null )

devMap.get( “locationcode” ) : It is possible that a null is passed, and a null pointer will appear at this time

View the source code of getOrDefault()

1  /** 
2       * Returns the value to which the specified key is mapped, or
 3       * { @code defaultValue} if this map contains no mapping for the key.
 4       *
 5       * @implSpec
 6       * The default implementation makes no guarantees about synchronization
 7       * or atomicity properties of this method. Any implementation providing
 8       * atomicity guarantees must override this method and document its
 9       * concurrency properties.
 10       *
 11       * @param key the key whose associated value is to be returned
12       * @param defaultValue the default mapping of the key
 13       * @return the value to which the specified key is mapped, or
 14       * { @code defaultValue} if this map contains no mapping for the key
 15       * @throws ClassCastException if the key AN of inappropriate type for IS
 16       * the this Map
 . 17       * (<a href="{@%20docroot%20}/java/util/Collection.html#optional-restrictions"> optional </a>)
 18 is       * @throws a NullPointerException IF The specified key is null and this map
 19      * does not permit null keys
 20       * (<a href="{@%20docRoot%20}/java/util/Collection.html#optional-restrictions">optional</a>)
 21       * @since 1.8
 22       */ 
23      default V getOrDefault (Object key, V defaultValue) {
 24          V v;
 25          return (((v = get(key)) != null ) || containsKey(key))
 26              ? V
 27              : defaultValue;
 28      }

@throws NullPointerException if the specified key is null and this map does not allow null keys

We can see that there is a get(key) method in the getOrDefault () method. At this time, if the value of key is a null, an error will be reported, such as key:null.

When the value of map is passed in, it is necessary to avoid the phenomenon of passing in map.put(key: null). You can use map.put(key: “”) instead.

(2) if (equals) judgment statement is wrong

if(! time .equals( “1900-01-01 00:00:00” ))

time : it is possible to pass a null, then there will be a null pointer phenomenon

Error resolution

Modify the sequence of judgment statements as follows:

if( null == devMap getOrDefault ( “locationcode”,”” ))

if(! “1900-01-01 00:00:00”.equals(time))

Read More:

Автор оригинала: baeldung.

1. Обзор

При работе с Java Reflection API часто встречается java.lang.reflect.InvocationTargetException . В этом уроке мы рассмотрим его и то, как с ним справиться, на простом примере .

В основном это происходит, когда мы работаем со слоем отражения и пытаемся вызвать метод или конструктор, который сам создает базовое исключение.

Слой отражения обертывает фактическое исключение, вызванное методом, с помощью исключения InvocationTargetException . Давайте попробуем понять это на примере.

Давайте напишем класс с методом, который намеренно создает исключение:

public class InvocationTargetExample {
    public int divideByZeroExample() {
        return 1 / 0;
    }
}

Теперь давайте вызовем описанный выше метод, используя отражение в простом тесте JUnit 5:

InvocationTargetExample targetExample = new InvocationTargetExample(); 
Method method =
  InvocationTargetExample.class.getMethod("divideByZeroExample");
 
Exception exception =
  assertThrows(InvocationTargetException.class, () -> method.invoke(targetExample));

В приведенном выше коде мы утвердили исключение InvocationTargetException , которое возникает при вызове метода. Здесь важно отметить, что фактическое исключение – ArithmeticException в данном случае – оборачивается в InvocationTargetException.

Теперь вопрос, который приходит на ум, заключается в том, почему отражение не создает фактическое исключение в первую очередь?

Причина в том, что это позволяет нам понять, произошло ли Исключение из-за сбоя при вызове метода через слой отражения или оно произошло внутри самого метода.

3. Как обрабатывать исключение InvocationTargetException?

Здесь фактическое базовое исключение является причиной InvocationTargetException , поэтому мы можем использовать Throwable.getCause () , чтобы получить дополнительную информацию об этом.

Давайте посмотрим, как мы можем использовать getCause() для получения фактического исключения в том же примере, который использовался выше:

assertEquals(ArithmeticException.class, exception.getCause().getClass());

Здесь мы использовали метод getCause() для того же объекта exception , который был брошен. И мы утверждали ArithmeticException.class как причина исключения.

Таким образом, как только мы получим базовое исключение, мы можем перестроить его, обернуть в какое-то пользовательское исключение или просто зарегистрировать исключение в соответствии с нашими требованиями.

4. Заключение

В этой короткой статье мы рассмотрели, как слой отражения обертывает любое базовое исключение. Мы также видели, как определить основную причину исключения InvocationTargetException и как справиться с таким сценарием на простом примере.

Как обычно, код, используемый в этой статье, доступен на GitHub .

If a InvocationTargetException is a checked exception in Java that wraps an exception thrown by an invoked method or constructor. The method or constructor that throws the exception is invoked using the Method.invoke() method. The InvocationTargetException is quite common when using the Java Reflection API.

The Java reflection layer wraps any exception as an InvocationTargetException. This helps clarify whether the exception is caused by an issue in the reflection call or within the called method.

What Causes InvocationTargetException

The InvocationTargetException occurs mainly when working with the Java reflection API to invoke a method or constructor, which throws an exception.

This underlying exception is the actual cause of the issue, therefore resolving the InvocationTargetException equates to finding and resolving the underlying exception that occurs within the invoked method.

InvocationTargetException Example

Here is an example of a InvocationTargetException thrown when a method that is called using Method.invoke() throws an exception:

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class InvocationTargetExceptionExample {
    public int divideByZero() {
                return 1 / 0;
        }

    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException {
        InvocationTargetExceptionExample itee = new InvocationTargetExceptionExample(); 
        Method method = InvocationTargetExceptionExample.class.getMethod("divideByZero");
        try {
            method.invoke(itee);
        } catch (InvocationTargetException ite) {
            ite.printStackTrace();
        }
        }
}

In this example, the main() method invokes divideByZero() using Method.invoke(). Since divideByZero() throws an ArithmeticException, it is wrapped within an InvocationTargetException thrown in the main() method:

java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at InvocationTargetExceptionExample.main(InvocationTargetExceptionExample.java:13)
Caused by: java.lang.ArithmeticException: / by zero
    at InvocationTargetExceptionExample.divideByZero(InvocationTargetExceptionExample.java:6)
    ... 5 more

How to Resolve InvocationTargetException

Since the underlying exception is the actual cause of the InvocationTargetException, finding and resolving the underlying exception resolves the InvocationTargetException. The getCause() method of the Throwable class can be used to obtain the underlying exception. The earlier example can be updated accordingly to get the underlying exception and print its stack trace:

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class InvocationTargetExceptionExample {
    public int divideByZero() {
        return 1 / 0;
    }

    public static void main(String[] args) throws NoSuchMethodException {
        InvocationTargetExceptionExample itee = new InvocationTargetExceptionExample();
        Method method = InvocationTargetExceptionExample.class.getMethod("divideByZero");
        try {
            method.invoke(itee);
        } catch (InvocationTargetException ite) {
            Throwable underlyingException = ite.getCause();
            underlyingException.printStackTrace();
        } catch (IllegalAccessException iae) {
            iae.printStackTrace();
        }
    }
}

Running the above will print out the stack trace of the underlying ArithmeticException:

java.lang.ArithmeticException: / by zero
    at InvocationTargetExceptionExample.divideByZero(InvocationTargetExceptionExample.java:6)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at InvocationTargetExceptionExample.main(InvocationTargetExceptionExample.java:13)

The stack trace can then be inspected to resolve the underlying exception. This will also resolve the wrapped InvocationTargetException.

Track, Analyze and Manage Java Errors With Rollbar

Rollbar in action

Managing errors and exceptions in your code is challenging. It can make deploying production code an unnerving experience. Being able to track, analyze, and manage errors in real-time can help you to proceed with more confidence. Rollbar automates Java error monitoring and triaging, making fixing errors easier than ever. Try it today.

Добавить комментарий