Link to home
Start Free TrialLog in
Avatar of abooysen2
abooysen2Flag for South Africa

asked on

JSP CODE ERROR

Hi experts

I busy working on a old project but there is a part in the jsp page that causes and Error


2010-08-17 13:19:57,640 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/mmticket].[jsp]] (http-127.0.0.1-8080-1) Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
      at org.apache.jsp.main_jsp._jspService(main_jsp.java:968)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

<%
	ArrayList arrClients = deal.getClients();		
	
	
	String client = request.getParameter("clients");	
	if(client==null) { client=""; }
	String clientApostrophe = client;
	if (clientApostrophe.indexOf("'") > -1) clientApostrophe = TicketUtils.addAposEscape(clientApostrophe);
	
	
	
	
%>
	
<select name="clients"  	
	onchange="clientOnChange()"	
	>
	<option value=""/>
<%	for (int i=0; i<arrClients.size(); i++)	
	{
		String strVal = (String) arrClients.get(i);
		if (client.equals(strVal))
		{
%>	
			<option value="<%=strVal%>" selected="selected"><%=strVal%></option>
<%		
		}
		else	
		{
%>	
			<option value="<%=strVal%>"><%=strVal%></option>
<%
		}
	}
%>
</select>
</td>


<br>

<%
	client = request.getParameter("clients");
	ArrayList arrClientAccounts = deal.getAccountsByClient(client);
	
	String account = request.getParameter("account_number");
				if(account==null) account="";
%>

Open in new window

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>>ArrayList arrClients = deal.getClients();

Make sure that neither 'deal' nor 'arrClients' is null
Avatar of abooysen2

ASKER

I place this in the psj code and when i reached my second line i go this error

14:28:55,951 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
      at org.apache.jsp.main_jsp._jspService(main_jsp.java:950)

                  ArrayList arrClients = new ArrayList();
                  System.out.println("This is empty" + deal.getClients());
                  arrClients = deal.getClients();
                  if(deal.getClients() == null){
                        System.out.println("This is empty" + deal.getClients());
                  }
I event tries this

                  ArrayList arrClients = new ArrayList();
                  if(deal.getClients() == null){
                        System.out.println("This is empty" + deal.getClients());
                  }else{
                        System.out.println("Something" + deal.getClients());
                  }

when it gets to deal.getClients() == null it throws the same error given above

to give you a breakdown

the Deal.java

 has       
public abstract ArrayList getClients()
    throws RemoteException;
I even tried this

ArrayList arrClients = new ArrayList();

still does not work??
i changed the code to

            <%
            ArrayList arrClients = deal.getClients();

            String client = request.getParameter("clients");
            if (client == null) {
                  client = "";
            }
            String clientApostrophe = client;
            if (clientApostrophe.indexOf("'") > -1)
                  clientApostrophe = TicketUtils.addAposEscape(clientApostrophe);
            %>

but when it get to ArrayList arrClients = deal.getClients();  it just fails

can you perhaps assist
You're not checking if 'deal'is null
when I debug arrCLients and just placed my mouse on arrClient is see this

ArrayList arrClients - main._jspService(HttpServletRequest, HttpServletResponse)

What does this means?
I check deal is null. But I have attached the code below.

Could this be the reason

<%!private Deal deal = null;%>

I am not sure why the previews developer did this. Is there a way to work around this.
<%@ page
	import="deal.Deal,deal.DealHome,util.*,java.util.ArrayList,javax.ejb.*,java.math.*,java.text.*,java.net.*,javax.naming.*,java.util.*,java.lang.*,java.io.*,javax.rmi.PortableRemoteObject,java.rmi.RemoteException"
	session="true"%>
<%!private Deal deal = null;%>

<%@page import="org.apache.commons.collections.iterators.ArrayListIterator"%><HTML>
<HEAD>
<TITLE>MMTicket</TITLE>
<script type="text/javascript">



//Function to get accounts based on client selected
function clientOnChange()
{	   	

	var selectedIndex = document.accounts.clients.selectedIndex;
	var selectedClient = document.accounts.clients.options[selectedIndex].value;
	document.accounts.clients.value = selectedClient;	
	document.accounts.account_number.value = "";	
	document.accounts.submit();

} 


//Function to get account details based on account selected
function accountOnClick(client,accountNumber,accountStruct,accountType)
{	
	document.accounts.clients.value = client;
	document.accounts.account_number.value = accountNumber;
	document.accounts.account_structure.value = accountStruct;	
	document.accounts.account_type.value = accountType;
	
	document.accounts.submit();
} 


//handle buttons
function doDeal(client,accountNumber,dealType,accStruct,newOrExists)
{
	<%session.setAttribute("deal", deal);%>
	
	//set the deal type to be exactly either DEPOSIT or WITHDRAWAL to simplify processing in forms its forwarded to
	if (dealType.toUpperCase().indexOf("DEPOSIT") > -1)
		dealType="DEPOSIT";
	if (dealType.toUpperCase().indexOf("LOAN") > -1 || dealType.toUpperCase().indexOf("WITHDRAWAL") > -1)
		dealType="WITHDRAWAL";
	
	client = client.replace('&','*');
	
	var param = "";	
	param += addParam("client",client);
	param += "&" +addParam("account_number",accountNumber);
	param += "&" + addParam("deal_type",dealType);
	param += "&" + addParam("acc_struct",accStruct);
	param += "&" + addParam("new_or_exists",newOrExists);
	
	CallServlet("deal.jsp",param, dealType);
	document.accounts.submit();
}	

//handle interdiv button
function doInterDiv(dealId, dealType, client)
{
	<%session.setAttribute("deal", deal);%>
	
	var param = "";	
	param += addParam("deal_id",dealId);
	param += "&" + addParam("deal_type",dealType);
	param += "&" + addParam("client",client);
		
	CallServlet("interdiv.jsp",param,dealType);
	document.accounts.submit();
	
}


//handle amend button
function doAmend(dealId, client,accountNumber,dealType,accStruct,newOrExists)
{
	
	<%session.setAttribute("deal", deal);%>	
	
	if (dealType.toUpperCase().indexOf("DEPOSIT") > -1)
			dealType="DEPOSIT";
		if (dealType.toUpperCase().indexOf("LOAN") > -1 || dealType.toUpperCase().indexOf("WITHDRAWAL") > -1)
		dealType="WITHDRAWAL";
	
	if (dealType.toUpperCase().indexOf("DEPOSIT") > -1 || dealType.toUpperCase().indexOf("WITHDRAWAL") > -1 || dealType.toUpperCase().indexOf("LOAN") > -1)
	{
	
		
			
			client = client.replace('&','*');
			
			var param = "";	
			param += addParam("client",client);
			param += "&" +addParam("account_number",accountNumber);
			param += "&" + addParam("deal_type",dealType);
			param += "&" + addParam("acc_struct",accStruct);
			param += "&" + addParam("new_or_exists",newOrExists);
			param += "&" + addParam("is_amend","true");
			//add deal_id for the case that this is an amend deal
			param += "&" + addParam("deal_id",dealId);
			
			
			CallServlet("deal.jsp",param, dealType);
	}	
	
	else if (dealType.toUpperCase().indexOf("TRANSFER") > -1 && dealType.toUpperCase().indexOf("INTERDIV") > -1)	
	{
			var param = "";	
			param += addParam("deal_id",dealId);
			param += "&" + addParam("deal_type",dealType);
			param += "&" + addParam("client",client);
				
			CallServlet("interdiv.jsp",param,dealType);
	}
	
	document.accounts.submit();
	
}


//handle cancel button
function doCancel(dealId, dealType)
{
	var msg;
	if (dealType.toUpperCase().indexOf("RATE") > -1)
		msg = "Are you sure you want to cancel deal "+dealId+"?\n. Please check the account rate after the change and ensure it's as intended.";
	else
		msg = "Are you sure you want to cancel deal "+dealId+"?";
	if (confirm(msg))
	{
	<%session.setAttribute("deal", deal);%>
	
	if (dealType.toUpperCase().indexOf("DEPOSIT") > -1)
			dealType="DEPOSIT";
		if (dealType.toUpperCase().indexOf("LOAN") > -1 || dealType.toUpperCase().indexOf("WITHDRAWAL") > -1)
		dealType="WITHDRAWAL";
		
	
	var param = "";	
	param += addParam("deal_id",dealId);
	param += "&" + addParam("deal_type",dealType);
	
		
	CallServlet("CancelDeal",param,"Cancel");	
	
	}
	
	document.accounts.submit();
		
}

</script>

</HEAD>


<%@ include file="general.jsp"%>
<%@ include file="comboBox.jsp"%>


<BODY bgcolor=white>

<table border=0 align=center width=100%>
	<tr>
		<td colspan=3 align=left><img src="images/InvestecLogo.gif"
			alt="Investec"></td>
	</tr>
	<tr>
		<td colspan=3 style="font-family: arial; color: navy; font-size: 16"
			align=center><b>Account and Deal Manager</b></td>
	</tr>
	<tr>
		<td style="font-family: arial; font-color: blue; font-size: 9"
			align=right><a href="logoff.jsp">Log off</a></td>
	</tr>
</table>


<form name="accounts">
<%
	String user = request.getRemoteUser();
%>


<table>
	<tr>
		<td><a style="font-family: arial; font-size: 13">Select
		Client:</a></td>
		<td><input size=23
			onkeyup="return combo_keyup(this,document.accounts.clients, event)"
			onkeydown="return combo_keydown(document.accounts.clients, event)"
			onkeypress="return combo_keypress(this,document.accounts.clients, event);" />
		</td>

		<td style="font-family: arial; font-color: navy; font-size: 12">
		<a href="new_client.jsp">New Client / Account </a></td>
		<td />
		<td />
		<td style="font-family: arial; font-color: navy; font-size: 12">
		<a href="ticketsearch.jsp">Deal Search </a></td>

	</tr>

	<tr>
		<td />
		<td>
		<%
		ArrayList arrClients = new ArrayList();
		if(deal == null){
			System.out.println(" deal is null" + deal);
			
		}else{
			System.out.println("deal is not null" + deal);
		}
		//deal.getClients();
		System.out.println(arrClients);
		String client = request.getParameter("clients");
		if (client == null) {
			client = "";
		}
		String clientApostrophe = client;
		if (clientApostrophe.indexOf("'") > -1)
			clientApostrophe = TicketUtils.addAposEscape(clientApostrophe);
		%> 
		<select name="clients" onchange="clientOnChange()">
							<option value="" />

		</select></td>


		<br>

		<input name="account_number" type=hidden />
		<input name="account_structure" type=hidden />
		<input name="account_type" type=hidden />

		<table border=0 align=center width=650>
			<caption align=right><b
				style="font-family: arial; font-size: 14">All accounts<b></caption>
			<tr bgcolor=navy>
				<td width=150 align=left
					style="font-family: arial; font-size: 12; color: white">Account</td>
				<td width=100 align=left
					style="font-family: arial; font-size: 12; color: white">Account
				type</td>
				<td width=100 align=left
					style="font-family: arial; font-size: 12; color: white">Account
				structure</td>
				<td width=100 align=right
					style="font-family: arial; font-size: 12; color: white">Balance</td>
				<td width=100 align=right
					style="font-family: arial; font-size: 12; color: white">Rate</td>
				<td width=100 align=right
					style="font-family: arial; font-size: 12; color: white">Interest</td>
			</tr>

			<tr>
				<td colspan=6>
				<div style="overflow: auto; width: 650; height: 120;"></div>
				</td>
			</tr>

			<tr>
				<td />
				<td />
				<td />
			</tr>

		</table>

		<table align=center>

			<tr />
			<tr>

				<td><input type=button name='butcalldeposit'
					value='New Call Deposit ' /></td>
				<td><input type=button name='butcallloan'
					value='New Call Loan    ' /></td>

				<td><input type=button name='butfixeddeposit'
					value='New Fixed Deposit' /></td>
				<td><input type=button name='butfixedloan'
					value='New Fixed Loan   ' /></td>
				<td><input type=button name='butfixeddeposit'
					value='New Fixed Deposit' /></td>
				<td><input type=button name='butfixedloan'
					value='New Fixed Loan   ' /></td>


				<td><input type=button name='butfixeddeposit'
					value='New Fixed Deposit' /></td>
				<td><input type=button name='butfixedloan'
					value='New Fixed Loan   ' /></td>


				<td><input type=button name='buttransfer' value='Transfer' /></td>
			</tr>
		</table>



		<br>


		<table align=center width=1160 border=0>

		</table>
		<table align=center width=950 border=0>
			<caption align=right><b
				style='font-family: arial; font-size: 13'>Deals on account <b></caption>
			<tr bgcolor=navy
				style='font-family: arial; font-size: 12; color: white'>
				<td border=0 align=left width=150>Deal id</td>
				<td border=0 align=left width=100>Deal date</td>
				<td border=0 align=left width=100>Start date</td>
				<td border=0 align=left width=100>Account</td>
				<td border=0 align=left width=100>Deal type</td>
				<td border=0 align=right width=100>Amount</td>
				<td border=0 align=right width=100>Rate</td>
				<td border=0 align=left width=100>Interest</td>
				<td border=0 align=right width=100>Maturity date</td>

				<!--	<td border=0 align=right width=70>Interdiv</td>
				<td border=0 align=right width=70>Amend</td>
				<td border=0 align=right width=70>Cancel</td>   -->


			</tr>


			<tr>
				<td colspan=9>
				<div style='overflow: auto; width: 950; height: 150;'>
				<table border=0 width='950'>

					<tr bgcolor='#ffffff' height=6>

						<td width=150 align=left style='font-family: arial; font-size: 12'></td>

						<td width=150 align=left style='font-family: arial; font-size: 12'></td>

						<td width=100 align=left style='font-family: arial; font-size: 12'></td>
						<td width=100 align=left style='font-family: arial; font-size: 12'></td>
						<td width=100 align=left style='font-family: arial; font-size: 12'></td>
						<td width=100 align=left style='font-family: arial; font-size: 12'></td>
						<td width=100 align=right
							style='font-family: arial; font-size: 12'></td>
						<td width=100 align=right
							style='font-family: arial; font-size: 12'></td>
						<td width=100 align=right
							style='font-family: arial; font-size: 12'></td>
						<td width=100 align=right
							style='font-family: arial; font-size: 12'></td>
					</tr>

					<tr height=6>
						<td width=150 />
						<td width=100 />
						<td width=100 />
						<td height=6><input name='InterDiv' type=button size=100
							value='   InterDiv    ' />
						<td><input name='InterDiv' type=button size=100
							value='   InterDiv    ' disabled /></td>

						<td><input name='Amend' type=button size=100
							value='   Amend     ' />
						<td><input name='Amend' type=button size=100
							value='   Amend     ' DISABLED />
						<td><input name='Cancel' type=button size=100
							value='   Cancel    ' />
						<td width=100 />
						<td width=100 />
						<td width=100 />
					</tr>



				</table>
				</div>
				</td>
			</tr>

			<tr />
			<tr />
				<!--			<tr>
			<td/>
			<td/>
			<td/>

					<td width=100 align=left><input name='deposit' type=button value='   Deposit    ' /></td>
					<td width=100 align=left><input name='withdrawal' type=button  value='Withdrawal' /></td>
					<td width=100 align=left><input name='rate_change' type=button value='Rate Change'/></td>

			<td/>
			<td/>
			<td/>	
					
				
				
			</tr>	-->
		</table>





		</form>
</BODY>
</HTML>

Open in new window

It doesn't mean much - just showing the location
currently this work fine in live. The only difference is that I am using Jboss 5 and jdk 1.5.

But deal should be null because of this
<%!
private Deal deal = null;
%>
Because I am setting deal to null

>>Because I am setting deal to null

Then you can't call deal.getClients without an NPE
but deal is like the object reference to the object Deal. So should I not check for deal.getClients is null ?
Question how can this work in a live environment and not in Test(my local machine). Is this related to data maybe.

I am trying to find out all the possible issues ?
>>but deal is like the object reference to the object Deal. So should I not check for deal.getClients is null ?

You need to check whether 'deal' is null *first*

>>Question how can this work in a live environment and not in Test(my local machine). Is this related to data maybe.

Probably because 'deal' is getting initialized in the live env
deal.getClients()  is link to
// Decompiled by Jad v1.5.8f. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   Deal.java

package deal;

import account.*;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.ejb.EJBObject;

import util.AccountDetails;
import util.TicketDetails;

public interface Deal extends EJBObject {

	public abstract String createAccount(String s,
			AccountDetails accountdetails, String s1, String s2, String s3,
			String s4, String s5, String s6, String s7, String s8, Map map)
			throws Exception, RemoteException;

	public abstract String interDiv(String s, String s1, String s2, String s3,
			String s4, String s5, String s6, String s7, String s8, String s9,
			String s10, double d, double d1, String s11, String s12, Map map)
			throws NonExistentAccountException, InsufficientBalanceException,
			TermAccountException, IOException, Exception, RemoteException;

	public abstract String withdrawalTicket(String s, String s1, String s2,
			String s3, double d, double d1, String s4, String s5, String s6,
			String s7, String s8, String s9, String s10, String s11,
			boolean flag, boolean flag1, Map map, int i)
			throws NonExistentAccountException, InsufficientBalanceException,
			TermAccountException, IOException, Exception, RemoteException;

	public abstract String depositTicket(String s, String s1, String s2,
			String s3, double d, double d1, String s4, String s5, String s6,
			String s7, String s8, String s9, String s10, String s11,
			boolean flag, boolean flag1, Map map, int i)
			throws NonExistentAccountException, TermAccountException,
			ExceededSettlementException, IOException, Exception,
			RemoteException;

	public abstract String rateChangeTicket(String s, String s1, String s2,
			String s3, String s4, double d, Map map)
			throws NonExistentAccountException, TermAccountException,
			RemoteException;

	public abstract String amendTicket(String s, String s1, String s2,
			String s3, String s4, String s5, double d, double d1, String s6,
			String s7, String s8, String s9, String s10, String s11,
			String s12, String s13, boolean flag, boolean flag1, Map map, int i)
			throws Exception, RemoteException;

	public abstract boolean cancelTicket(String s, String s1, String s2)
			throws Exception, RemoteException;

	public abstract void createTicket(TicketDetails ticketdetails)
			throws RemoteException;

	public abstract boolean emailDeal(String s, String s1, String s2, String s3)
			throws IOException, Exception, RemoteException;

	public abstract boolean setDealFile(String s, String s1)
			throws RemoteException;

	public abstract ArrayList getClientAccounts(String s)
			throws RemoteException;

	public abstract ArrayList getAccountsByClient(String s)
			throws RemoteException;

	public abstract ArrayList getClients()
    throws RemoteException;

	public abstract ArrayList getSearchClients(String s) throws RemoteException;

	public abstract AccountDetails getAccountDetails(String s)
			throws RemoteException;

	public abstract TicketDetails getTicketDetails(String s)
			throws RemoteException;

	public abstract ArrayList getDeals(String s) throws RemoteException;

	public abstract ArrayList getBankInfo(String s) throws RemoteException;
}

Open in new window

That object needs to be non-null
silly question

--->That object needs to be non-null
Is it the Deal object?
Yes
Well that Object is null and also I cannot bug the actual class because it's a interface. I think this is a end of the road?
Yes - it's quite simple. You can't use the methods of an uninitialised object without an exception.
So this means I will never be able so slove this issues?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you have any guide lines on how to check this?
You should ask the EJB people why Deal would be null when it shouldn't be