Java null pointer when executing a PL/SQL function using jOOQ

五迷三道 提交于 2019-12-05 05:19:30

问题


I'm currently attempting to call a PL/SQL Function which accepts multiple in/out arguments. This function contains the following data types:

  • String.
  • Array of Strings.

However while the application is setting up the data to send it to the database server, the application is throwing a null pointer exception which is irrelevant to the actual error caused (Note that the actual error is given below as this has been figured out when debugging the application).

The application is preparing the following data:

  1. Strings -> There are no issues with these
  2. List -> Converted to CustTabVarchar2_50Record
  3. List -> Converted to CustTabVarchar2_4000Record

Which is then passed to the jOOQ generated class which contains the Java wrapper of the PL/SQL function.

At this point it fails when it is iterating through the arguments and specifically when it is iterating on the CustTabVarchar2_50Record.

During this point, it will throw an exception:

java.lang.NoSuchMethodException: No similar method createARRAY with params [class java.lang.String, class [Ljava.lang.Object;] could be found on type class org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8.

I'm currently assuming that it could be one of the following issues:

  1. An issue with jOOQ.
  2. Incorrect library being used by jBoss as it is stating: 'org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8'

PL SQL Header:

procedure a_l_ws(
  p_i_num      in      varchar2, 
  p_s       in      varchar2,
  p_u       in      varchar2,
  p_tpu    in      varchar2,
  p_tpa     in      varchar2,
  p_data_desc     in      cust_tab_varchar2_50,
  p_l     in      cust_tab_varchar2_4000,
  p_r        out     pls_integer,
  p_p     out     varchar2,
  p_appl        out     varchar2,
  p_ml    out     cust_tab_varchar2_12,
  p_m         out     cust_tab_varchar2_4000) 

Stack trace:

result = {ReflectException@23035} Method threw 'org.jooq.tools.reflect.ReflectException' exception.
detailMessage = "java.lang.NoSuchMethodException: No similar method createARRAY with params [class java.lang.String, class [Ljava.lang.Object;] could be found on type class org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8."
cause = {NoSuchMethodException@23038} "java.lang.NoSuchMethodException: No similar method createARRAY with params [class java.lang.String, class [Ljava.lang.Object;] could be found on type class org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8."
detailMessage = "No similar method createARRAY with params [class java.lang.String, class [Ljava.lang.Object;] could be found on type class org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8."
cause = {NoSuchMethodException@23038} "java.lang.NoSuchMethodException: No similar method createARRAY with params [class java.lang.String, class [Ljava.lang.Object;] could be found on type class org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8."
stackTrace = {StackTraceElement[102]@23047} 
0 = {StackTraceElement@23049} "org.jooq.tools.reflect.Reflect.similarMethod(Reflect.java:436)"… Navigate
1 = {StackTraceElement@23050} "org.jooq.tools.reflect.Reflect.call(Reflect.java:366)"… Navigate
2 = {StackTraceElement@23051} "org.jooq.impl.DefaultBinding.createOracleARRAY(DefaultBinding.java:1403)"… Navigate
3 = {StackTraceElement@23052} "org.jooq.impl.DefaultBinding.set(DefaultBinding.java:1243)"… Navigate
4 = {StackTraceElement@23053} "org.jooq.impl.DefaultBindContext.bindValue0(DefaultBindContext.java:62)"… Navigate
5 = {StackTraceElement@23054} "org.jooq.impl.AbstractBindContext.bindValue(AbstractBindContext.java:127)"… Navigate
6 = {StackTraceElement@23055} "org.jooq.impl.ArrayConstant.bind0(ArrayConstant.java:110)"… Navigate
7 = {StackTraceElement@23056} "org.jooq.impl.ArrayConstant.accept(ArrayConstant.java:81)"… Navigate
8 = {StackTraceElement@23057} "org.jooq.impl.AbstractBindContext.bindInternal(AbstractBindContext.java:257)"… Navigate
9 = {StackTraceElement@23058} "org.jooq.impl.AbstractBindContext.visit0(AbstractBindContext.java:91)"… Navigate
10 = {StackTraceElement@23059} "org.jooq.impl.AbstractContext.visit0(AbstractContext.java:402)"… Navigate
11 = {StackTraceElement@23060} "org.jooq.impl.AbstractContext.visit(AbstractContext.java:168)"… Navigate
12 = {StackTraceElement@23061} "org.jooq.impl.AbstractRoutine.bind1(AbstractRoutine.java:588)"… Navigate
13 = {StackTraceElement@23062} "org.jooq.impl.AbstractRoutine.bind0(AbstractRoutine.java:558)"… Navigate
14 = {StackTraceElement@23063} "org.jooq.impl.AbstractRoutine.accept(AbstractRoutine.java:508)"… Navigate
15 = {StackTraceElement@23064} "org.jooq.impl.AbstractBindContext.bindInternal(AbstractBindContext.java:257)"… Navigate
16 = {StackTraceElement@23065} "org.jooq.impl.AbstractBindContext.visit0(AbstractBindContext.java:91)"… Navigate
17 = {StackTraceElement@23066} "org.jooq.impl.AbstractContext.visit0(AbstractContext.java:402)"… Navigate
18 = {StackTraceElement@23067} "org.jooq.impl.AbstractContext.visit(AbstractContext.java:168)"… Navigate
19 = {StackTraceElement@23068} "org.jooq.impl.AbstractRoutine.executeCallableStatement(AbstractRoutine.java:439)"… Navigate
20 = {StackTraceElement@23069} "org.jooq.impl.AbstractRoutine.execute(AbstractRoutine.java:310)"… Navigate
21 = {StackTraceElement@23070} "org.jooq.impl.AbstractRoutine.execute(AbstractRoutine.java:287)"… Navigate
22 = {StackTraceElement@23071} "c.r.w.jooq.model.db.db.packages.Aim.aimLoadWs(Aim.java:71)"… Navigate
23 = {StackTraceElement@23072} "c.r.w.jsonapi.repositories.onboarding.OnboardingService.loadApplication(OnboardingService.java:378)"… Navigate
24 = {StackTraceElement@23073} "c.r.w.jsonapi.repositories.onboarding.OnboardingService.loadMerchant(OnboardingService.java:74)"… Navigate
25 = {StackTraceElement@23074} "c.r.w.jsonapi.repositories.merchants.merchant.resource.MerchantRepository.saveRecord(MerchantRepository.java:93)"… Navigate
26 = {StackTraceElement@23075} "c.r.w.jsonapi.repositories.merchants.merchant.resource.MerchantRepository.saveRecord(MerchantRepository.java:24)"… Navigate
27 = {StackTraceElement@23076} "c.r.w.jsonapi.repositories.AbstractResourceRepository.save(AbstractResourceRepository.java:204)"… Navigate
28 = {StackTraceElement@23077} "c.r.w.jsonapi.repositories.AbstractResourceRepository.save(AbstractResourceRepository.java:33)"… Navigate
29 = {StackTraceElement@23078} "io.katharsis.core.internal.repository.adapter.ResourceRepositoryAdapter$4.invoke(ResourceRepositoryAdapter.java:133)"… Navigate
30 = {StackTraceElement@23079} "io.katharsis.core.internal.repository.adapter.ResponseRepositoryAdapter$RepositoryRequestFilterChainImpl.doFilter(ResponseRepositoryAdapter.java:203)"… Navigate
31 = {StackTraceElement@23080} "io.katharsis.core.internal.repository.adapter.ResourceRepositoryAdapter.save(ResourceRepositoryAdapter.java:145)"… Navigate
32 = {StackTraceElement@23081} "io.katharsis.core.internal.repository.adapter.ResourceRepositoryAdapter.update(ResourceRepositoryAdapter.java:110)"… Navigate
33 = {StackTraceElement@23082} "io.katharsis.core.internal.dispatcher.controller.ResourcePatch.handle(ResourcePatch.java:133)"… Navigate
34 = {StackTraceElement@23083} "io.katharsis.core.internal.dispatcher.RequestDispatcher$DefaultFilterChain.doFilter(RequestDispatcher.java:126)"… Navigate
35 = {StackTraceElement@23084} "io.katharsis.core.internal.dispatcher.RequestDispatcher.dispatchRequest(RequestDispatcher.java:80)"… Navigate
36 = {StackTraceElement@23085} "io.katharsis.rs.KatharsisFilter.dispatchRequest(KatharsisFilter.java:151)"… Navigate
37 = {StackTraceElement@23086} "io.katharsis.rs.KatharsisFilter.filter(KatharsisFilter.java:111)"… Navigate
38 = {StackTraceElement@23087} "org.apache.cxf.jaxrs.utils.JAXRSUtils.runContainerRequestFilters(JAXRSUtils.java:1642)"… Navigate
39 = {StackTraceElement@23088} "org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:106)"… Navigate
40 = {StackTraceElement@23089} "org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:77)"… Navigate
41 = {StackTraceElement@23090} "org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)"… Navigate
42 = {StackTraceElement@23091} "org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)"… Navigate
43 = {StackTraceElement@23092} "org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:251)"… Navigate
44 = {StackTraceElement@23093} "org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)"… Navigate
45 = {StackTraceElement@23094} "org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)"… Navigate
46 = {StackTraceElement@23095} "org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)"… Navigate
47 = {StackTraceElement@23096} "org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:180)"… Navigate
48 = {StackTraceElement@23097} "org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:293)"… Navigate
49 = {StackTraceElement@23098} "org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:270)"… Navigate
50 = {StackTraceElement@23099} "io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)"… Navigate
51 = {StackTraceElement@23100} "io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)"… Navigate
52 = {StackTraceElement@23101} "org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)"… Navigate
53 = {StackTraceElement@23102} "org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)"… Navigate
54 = {StackTraceElement@23103} "org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)"… Navigate
55 = {StackTraceElement@23104} "org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)"… Navigate
56 = {StackTraceElement@23105} "org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)"… Navigate
57 = {StackTraceElement@23106} "org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)"… Navigate
58 = {StackTraceElement@23107} "org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)"… Navigate
59 = {StackTraceElement@23108} "org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)"… Navigate
60 = {StackTraceElement@23109} "org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)"… Navigate
61 = {StackTraceElement@23110} "org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)"… Navigate
62 = {StackTraceElement@23111} "c.r.wsecurity.oauth2.AuthenticationFilterOAuth2.doFilter(AuthenticationFilterOAuth2.java:73)"… Navigate
63 = {StackTraceElement@23112} "org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)"… Navigate
64 = {StackTraceElement@23113} "org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)"… Navigate
65 = {StackTraceElement@23114} "org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)"… Navigate
66 = {StackTraceElement@23115} "org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)"… Navigate
67 = {StackTraceElement@23116} "org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)"… Navigate
68 = {StackTraceElement@23117} "org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)"… Navigate
69 = {StackTraceElement@23118} "org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)"… Navigate
70 = {StackTraceElement@23119} "org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)"… Navigate
71 = {StackTraceElement@23120} "org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)"… Navigate
72 = {StackTraceElement@23121} "org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)"… Navigate
73 = {StackTraceElement@23122} "io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)"… Navigate
74 = {StackTraceElement@23123} "io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)"… Navigate
75 = {StackTraceElement@23124} "io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)"… Navigate
76 = {StackTraceElement@23125} "io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)"… Navigate
77 = {StackTraceElement@23126} "io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)"… Navigate
78 = {StackTraceElement@23127} "org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)"… Navigate
79 = {StackTraceElement@23128} "io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)"… Navigate
80 = {StackTraceElement@23129} "io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)"… Navigate
81 = {StackTraceElement@23130} "io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)"… Navigate
82 = {StackTraceElement@23131} "io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)"… Navigate
83 = {StackTraceElement@23132} "io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)"… Navigate
84 = {StackTraceElement@23133} "io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)"… Navigate
85 = {StackTraceElement@23134} "io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)"… Navigate
86 = {StackTraceElement@23135} "io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)"… Navigate
87 = {StackTraceElement@23136} "io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)"… Navigate
88 = {StackTraceElement@23137} "io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)"… Navigate
89 = {StackTraceElement@23138} "io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)"… Navigate
90 = {StackTraceElement@23139} "org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)"… Navigate
91 = {StackTraceElement@23140} "io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)"… Navigate
92 = {StackTraceElement@23141} "io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)"… Navigate
93 = {StackTraceElement@23142} "io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:285)"… Navigate
94 = {StackTraceElement@23143} "io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:264)"… Navigate
95 = {StackTraceElement@23144} "io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)"… Navigate
96 = {StackTraceElement@23145} "io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:175)"… Navigate
97 = {StackTraceElement@23146} "io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)"… Navigate
98 = {StackTraceElement@23147} "io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:792)"… Navigate
99 = {StackTraceElement@23148} "java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)"… Navigate
… (2 more items. Double-click to see)
suppressedExceptions = {Collections$UnmodifiableRandomAccessList@22457}  size = 0
stackTrace = {StackTraceElement[101]@23039} 
suppressedExceptions = {Collections$UnmodifiableRandomAccessList@22457}  size = 0

回答1:


This seems to be related to https://github.com/jOOQ/jOOQ/issues/3639 when using a connection wrapper (through a datasource or connection pool) that is configured with an Oracle JDBC driver. In your case it looks like you are using a JBoss datasource. As mentioned in the issue, since createARRAY is not standard JDBC but specific to Oracle, if you create a DSL connection with Oracle dialect, jOOQ will assume that the Oracle connection is being used and thus try to call Oracle's createARRAY() instead of createArrayOf().

Maybe jOOQ's author can shed some light on whether this can be avoided through a configuration setting, fix or otherwise.

Note: had to leave this as an answer as opposed to a comment as I'm still low on reputation. Will provide the final answer here if this entry is high on up-votes.




回答2:


This seems to be a limitation of that JBoss WrappedConnectionJDK8, which doesn't seem to correctly unwrap the OracleConnection type when calling:

OracleConnection ocn = wrapped.unwrap(OracleConnection.class);

In the past, (as GilbertD has mentioned), jOOQ worked around such limitations by calling vendor specific unwrapping methods through reflection, e.g. those in Spring through #3639. It might be possible to do the same for WrappedConnectionJDK8.getUnderlyingConnection(), see #7641

Workaround

As a workaround, you can manually unwrap the OracleConnection from your JBoss provided JDBC Connection wrapper and supply that to jOOQ, directly, e.g. by proxying the JBoss DataSource

class WorkaroundDataSource implements DataSource {
    final DataSource delegate;

    public WorkaroundDataSource(DataSource delegate) {
        this.delegate = delegate;
    }

    @Override
    public Connection getConnection() throws SQLException {
        return unwrapOracleConnection(delegate.getConnection());
    }

    // ...
}

And then:

DSLContext ctx = DSL.using(new WorkaroundDataSource(jbossDataSource), SQLDialect.ORACLE);


来源:https://stackoverflow.com/questions/51157656/java-null-pointer-when-executing-a-pl-sql-function-using-jooq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!