Issue Details (XML | Word | Printable)

Key: JDBC-487
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Mark Rotteveel
Reporter: Fabio Silva
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Jaybird JDBC Driver

NPE when PreparedStatement setString is null

Created: 03/Apr/17 01:05 PM   Updated: 03/Apr/17 07:11 PM
Component/s: None
Affects Version/s: Jaybird 2.2.12
Fix Version/s: None

File Attachments: 1. Zip Archive files.zip (5 kB)

Environment:
Windows 10 64 bits / Glassfish 3.1.2.2 / JDK 1.7.0_79 / Firebird 2.5.4
CentOS 6.5 64 bits / Glassfish 3.1.2.2 / java-1.7.0-openjdk-1.7.0.85-2.6.1.3 / Firebird 2.5.7


 Description  « Hide
Hi guys.

I have a code like this:

String sql = "select * from lista_tabsite(?, ?,'X', ?, ?, ?, ?) where qtd > 0 order by qtd desc";
Connection conexao = banco.getConexao(filial);
PreparedStatement ps = conexao.prepareStatement(mySQL);
ps.setString(1, filial.getSigla());
ps.setString(2, getStringTabelaPadrao());
ps.setString(3, myFabricante);
ps.setString(4, myTipoProduto);
ps.setString(5, myPalavraChave);
ps.setInt(6, myFaturar);
ResultSet rs = ps.executeQuery();

The 2th parameter "getStringTabelaPadrao()" sometimes returns a String sometimes null (it's expected and perfectly normal) and works fine for both cases with the code above. but sometimes (maybe 1 in 100 cases) i receive the stack trace below:

java.lang.NullPointerException at org.firebirdsql.jdbc.AbstractPreparedStatement.getXsqlvar(AbstractPreparedStatement.java:504) at org.firebirdsql.jdbc.AbstractPreparedStatement$1.setFieldData(AbstractPreparedStatement.java:1292) at org.firebirdsql.jdbc.field.FBField.setFieldData(FBField.java:179) at org.firebirdsql.jdbc.field.FBField.setNull(FBField.java:203) at org.firebirdsql.jdbc.field.FBWorkaroundStringField.setStringForced(FBWorkaroundStringField.java:92) at org.firebirdsql.jdbc.field.FBWorkaroundStringField.setString(FBWorkaroundStringField.java:70) at org.firebirdsql.jdbc.AbstractPreparedStatement.setString(AbstractPreparedStatement.java:426) at com.sun.gjc.spi.base.PreparedStatementWrapper.setString(PreparedStatementWrapper.java:258) at br.com.vanguardati.commerce.dao.ProdutosDAO.getProdutosDAO(ProdutosDAO.java:141) at br.com.vanguardati.commerce.dao.ProdutosDAO.getProdutos(ProdutosDAO.java:260) at br.com.vanguardati.commerce.facade.ProdutosFacade.pesquisa(ProdutosFacade.java:78) at br.com.vanguardati.commerce.bean.ProdutosBean.buscaProdutosPadraoAntigo(ProdutosBean.java:192) at br.com.vanguardati.commerce.bean.ProdutosBean.buscaProdutos(ProdutosBean.java:101) at br.com.vanguardati.commerce.bean.ProdutosBean.getProdutos(ProdutosBean.java:381) at sun.reflect.GeneratedMethodAccessor368.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at javax.el.BeanELResolver.getValue(BeanELResolver.java:363) at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) at com.sun.el.parser.AstValue.getValue(AstValue.java:138) at com.sun.el.parser.AstValue.getValue(AstValue.java:183) at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224) at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) at com.sun.faces.facelets.tag.jstl.core.ForEachHandler.apply(ForEachHandler.java:178) at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137) at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:187) at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120) at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95) at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137) at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:187) at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120) at com.sun.faces.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:106) at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:178) at com.sun.faces.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:395) at com.sun.faces.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:366) at com.sun.faces.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:111) at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95) at com.sun.faces.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:188) at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95) at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137) at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:187) at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120) at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95) at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93) at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87) at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:320) at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:379) at com.sun.faces.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:358) at com.sun.faces.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:199) at com.sun.faces.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:155) at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93) at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:87) at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:164) at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:914) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:807) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:671) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:505) at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:476) at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:355) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:305) at org.ocpsoft.rewrite.servlet.impl.HttpRewriteResultHandler.handleResult(HttpRewriteResultHandler.java:41) at org.ocpsoft.rewrite.servlet.RewriteFilter.rewrite(RewriteFilter.java:268) at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:188) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:745)



I tried change to that with no luck:

if(getStringTabelaPadrao()){
    ps.setNull(2, java.sql.Types.VARCHAR);
} else {
    ps.setString(2, getStringTabelaPadrao());
}



 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Mark Rotteveel added a comment - 03/Apr/17 03:36 PM
The exception suggests that the statement was either never prepared or was already closed.

Is this the actual code, or a simplification? Do you by any chance use a data source that caches statements, or share the same connection on multiple threads?

Fabio Silva added a comment - 03/Apr/17 06:42 PM
Hi Mark.

This is a simplified code. I will attach the full method code.

I am using the glassfish connection poll that follow attached too.

I disabled the cache through pesistence.xml that are attached too.

No, this connection is not shared, it's closed at the finally try / catch block.