I've read here about null pointer exception issue, please dont forward me there. I've already broken my head.
Have a tomcat v9. It's used to process voice calls as an IVR server. Inside is webapp with java classes and jsp pages (vxml inside). Problem, when calling this method:
<c:if test="${(param.CUSTOMER_TYPE eq 'PPP') or (param.CUSTOMER_TYPE eq 'PKL') or (param.CUSTOMER_TYPE eq 'GIN')}">
<c:set var="cin_cust_id" value="${param.VAR3}"/>
<c:set var="cin_ani" value="${param.ANI}"/>
<c:set var="cin_ursconnid" value="${param.URSCONNID}"/>
<debug:message message="checkisnew.jsp. cin_cust_id: ${cin_cust_id}"/>
<debug:message message="checkisnew.jsp. cin_ani: ${cin_ani}"/>
<debug:message message="checkisnew.jsp. cin_ursconnid: ${cin_ursconnid}"/>
<c:set var="isnew" value="${bakcellivr:cICN(cin_cust_id, cin_ani, cin_ursconnid)}" scope="request"/>
<debug:message message="checkisnew.jsp. isnew: ${isnew}"/>
</c:if>
This is taglib:
<function>
<description>Check if subscriber is calling for the first time or not</description>
<name>cICN</name>
<function-class>bkc.DB_Requests</function-class>
<function-signature>java.lang.String checkIsCustomerNew(java.lang.String, java.lang.String, java.lang.String)</function-signature>
</function>
This is the java method itself:
package bkc;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import javax.naming.NamingException;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class DB_Requests {
private static Logger logger = LogManager.getLogger(DB_Requests.class);
private static String url_out = "jdbc:oracle:thin:@xxxxxx:xxxx/xxxxx";
public String checkIsCustomerNew (String custid, String msisdn, String connid) {
Connection conn = null;
CallableStatement s = null;
String isNew = "-1";
int ret_param = -2;
try {
conn = DBPool.getConnection();
} catch (Exception e) {
logger.error("Error while retrieving DB params from context. CONNID: " + connid);
//System.out.println("DB_Requests.checkIsCustomerNew error retrieving DB params from context");
//System.out.println("MSISDN is: " + msisdn + " ConnectioID is: " + connid + " Timestamp: " + sdf.format(date) + "\n");
//e.printStackTrace();
ErrorNotifier.sendMail("DB_Requests.checkIsCustomerNew", msisdn, connid, url_out, "--", "Error while retrieving DB params from context", e.getMessage(), e.getStackTrace());
return "old";
}
String query = "{ ? = call cc.GET_SUBS_IVR_LISTEN_STATUS(?, ?) }";
try {
s = conn.prepareCall(query);
s.registerOutParameter(1, java.sql.Types.INTEGER);
s.setString(2, custid);
s.setString(3, "BKC");
s.execute();
ret_param = s.getInt(1);
} catch (SQLException e) {
logger.error("Failed to prepare or execute statement. CONNID: " + connid);
//System.out.println("DB_Requests.checkIsCustomerNew failed to prepare or execute statement");
//System.out.println("MSISDN is: " + msisdn + " ConnectioID is: " + connid + " Timestamp: " + sdf.format(date) + "\n");
//e.printStackTrace();
ErrorNotifier.sendMail("DB_Requests.checkIsCustomerNew", msisdn, connid, url_out, query, "Failed to prepare or execute statement", e.getMessage(), e.getStackTrace());
return "old";
}
//System.out.println("DBPool.checkIsNew ret_param: " + ret_param);
if (ret_param == 0) {
isNew = "new";
} else {
isNew = "old";
}
//System.out.println("DBPool.checkIsNew isNew: " + isNew);
try {
conn.close();
} catch (SQLException e) {
logger.error("Failed to close connection object. CONNID: " + connid);
//System.out.println("DB_Requests.getSubInfo failed to parse resultset object");
//System.out.println("MSISDN is: " + msisdn + " ConnectioID is: " + connid + " Timestamp: " + sdf.format(date) + "\n");
//e.printStackTrace();
ErrorNotifier.sendMail("DB_Requests.checkIsNew", msisdn, connid, url_out, query, "Failed to close connection object", e.getMessage(), e.getStackTrace());
return "old";
}
return isNew;
}
}
This is the exception i get in tomcat log:
09-Feb-2022 00:28:07.902 SEVERE [http-nio-0.0.0.0-8080-exec-5] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [jsp] in context with path [/BAKCELLIVR] threw exception [An exception occurred processing [/vxml/checkisnew.jsp] at line [49]
46: <debug:message message="checkisnew.jsp. cin_cust_id: ${cin_cust_id}"/>
47: <debug:message message="checkisnew.jsp. cin_ani: ${cin_ani}"/>
48: <debug:message message="checkisnew.jsp. cin_ursconnid: ${cin_ursconnid}"/>
49: <c:set var="isnew" value="${bakcellivr:cICN(cin_cust_id, cin_ani, cin_ursconnid)}" scope="request"/>
50: <debug:message message="checkisnew.jsp. isnew: ${isnew}"/>
51: </c:if>
52:
Stacktrace:] with root cause
java.lang.NullPointerException
at java.base/java.lang.reflect.Method.invoke(Method.java:559)
at org.apache.el.parser.AstFunction.getValue(AstFunction.java:198)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:129)
at org.apache.jsp.vxml.checkisnew_jsp._jspx_meth_c_005fset_005f6(checkisnew_jsp.java:1032)
at org.apache.jsp.vxml.checkisnew_jsp._jspx_meth_c_005fif_005f2(checkisnew_jsp.java:860)
at org.apache.jsp.vxml.checkisnew_jsp._jspService(checkisnew_jsp.java:161)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:71)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:359)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:889)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1735)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834)
looking at stacktrace it looks like tomcat is not even calling the method and exception occures on page render phase. I've checked all input variablesthey are not null. They print in log before the jstl is called and they have values. Dont't know where to dig.
Solved. It was my mistake. Function in tld must be refereced to static method. My method was not static.