Thread: String index out of range - Postgresql 7.3.4, Resin & JDBC

String index out of range - Postgresql 7.3.4, Resin & JDBC

From
"Antony Brooke-Wood"
Date:
HI,

We are getting the following error through a JSP.

We received the same error for both 7.3.1 through 7.3.4 and several JDBC
driver changes (currently running the latest).

The strange thing is that this actual page was working fine, then, after
we modified a different separate page, this page started producing the
following error.

Is anyone else receiving Out Of Bound errors?

Can anyone suggest how I could get a more descriptive error?

I have included full source code for the page (sorry it is so long), as
well as the error that is shown in Resin's Standard Error log whenever
the page is loaded.

Thanks for any help.

Regards,

Antony

___________________

java.lang.StringIndexOutOfBoundsException: String index out of range: 0
        at java.lang.String.charAt(String.java:444)
        at
org.postgresql.jdbc1.AbstractJdbc1ResultSet.toBoolean(AbstractJdbc1Resul
tSet.java:684)
        at
org.postgresql.jdbc1.AbstractJdbc1ResultSet.getBoolean(AbstractJdbc1Resu
ltSet.java:102)
        at
_ejb.com.nortelleads.LeadBean__QPersist._caucho_load(LeadBean__QPersist.
java:2903)
        at
_ejb.com.nortelleads.ManagerBean__QPersist.ejbSelectAllWithManager(Manag
erBean__QPersist.java:2713)
        at
com.nortelleads.ManagerBean.getAllWithManager(ManagerBean.java:169)
        at
_ejb.com.nortelleads.ManagerBean__EJB$Local.getAllWithManager(ManagerBea
n__EJB.java:921)
        at _lead_0listing__jsp._jspService(_lead_0listing__jsp.java:373)
        at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
        at com.caucho.jsp.Page.subservice(Page.java:506)
        at
com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182
)
        at
com.caucho.server.http.Invocation.service(Invocation.java:315)
        at
com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
        at
com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:246)
        at
com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163
)
        at com.caucho.server.TcpConnection.run(TcpConnection.java:139)
        at java.lang.Thread.run(Thread.java:534)
___________________

<%@ page import="com.nortelleads.*, javax.naming.*, java.util.*,
java.net.*, java.text.DateFormat" session="true" errorPage="error.jsp"%>

<%@ taglib uri="ejbtags" prefix="ejb" %>

<%!

private CountryHome countryHome = null;

private LeadHome leadHome = null;

private LanguageHome languageHome = null;

private CampaignHome campaignHome = null;

public void jspInit()

{

try

{

Context ejb = (Context) new
InitialContext().lookup("java:comp/env/nortel");

countryHome = (CountryHome)ejb.lookup("Country");

leadHome = (LeadHome)ejb.lookup("Lead");

languageHome = (LanguageHome)ejb.lookup("Language");

campaignHome = (CampaignHome)ejb.lookup("Campaign");

}

catch (NamingException ignore)

{

}

}

private String getDisplayForActions(Integer action)

{

if (action == null)

return null;

switch (action.intValue())

{

case 1: return "<img src='images/tick.gif' width='18' height='18'
border='0'>";

case 0: return "<img src='images/cross.gif' width='18' height='18'
border='0'>";

case -1: return "<img src='images/slash.gif' width='18' height='18'
border='0'>";

case -2: return "<img src='images/slash.gif' width='18' height='18'
border='0'>";

default: return null;

}

}

%>

<%

response.setHeader("Pragma", "no-cache");

response.setHeader("Cache-Control", "no-cache");

response.setDateHeader("Expires", 0);

Manager currentUser = (Manager)session.getAttribute("currentUser");

if (currentUser == null)

{

// If moving to archive change login.jsp to ../login.jsp

response.sendRedirect("login.jsp");

return;

}

// If moving to archive change false to true

CombinedPrivilege cp = currentUser.getPrivilege(false);

Hashtable pageInfo = (Hashtable)session.getAttribute("pageInfo");

Language language = (Language)pageInfo.get("language");

Campaign campaign = (Campaign)pageInfo.get("campaign");

Country country = (Country)pageInfo.get("country");

Vector managerFilter = (Vector)pageInfo.get("managerFilter");

String managerFocus = (String)pageInfo.get("managerFocus");

String managerFilterStatus =
(String)pageInfo.get("managerFilterStatus");

Collection countryManagers = null;

boolean noManagers = true;

if (country == null)

countryManagers = currentUser.getCountryManagerLists();

else

countryManagers = currentUser.getCountryManagerLists(country);

%>

<HTML>

<HEAD>

<TITLE>Lead Listing</TITLE>

<META http-equiv="Content-Type" content="text/html;
charset=<%=language.getEncoding()%>">

<META http-equiv="Content-Style-Type" content="text/css">

<LINK rel="stylesheet" type="text/css" href="styles.css"
src="styles.css">

<SCRIPT language="JavaScript">

<!--

var managerFocus = "<%=managerFocus%>";

var mngr;

var mngrRep;

function focusManager()

{

if (managerFocus != "")

window.location.href = "lead_listing.jsp#" + managerFocus;

}

function performAction(file)

{

document.lead_listing.action = file;

var chkd = false;

for (var i = 0; i < document.lead_listing.elements.length; i++)

{

if (document.lead_listing.elements[i].type == "checkbox")

if (document.lead_listing.elements[i].checked)

{

chkd = true;

break;

}

}

if (chkd)

document.lead_listing.submit();

else

alert("You must check at least one lead to perform this action");

}

function popWindow(file)

{

var popup = window.open(file,
"ManagerFilter","width=700,height=400,scrollbars,resizable");

popup.focus();

}

// -->

</SCRIPT>

</HEAD>

<BODY class="bgNeg" marginwidth="0" marginheight="0" leftmargin="0"
topmargin="0" onLoad="menu.initMenu();focusManager();">

<%@ include file="menuBar.jsp" %>

<IMG src="images/trans.gif" width="1" height="30" border="0">

<TABLE border="0" cellspacing="0" cellpadding="0" width="*">

<TR>

<TD rowspan="2"><IMG src="images/trans.gif" width="8" height="1"
border="0"></TD>

<TD class="lines" colspan="3"><IMG src="images/trans.gif" width="1"
height="1" border="0"></TD>

</TR>

<TR>

<TD class="lines"><IMG src="images/trans.gif" width="1" height="30"
border="0"></TD>

<TD class="bgMain">  <B class="medtextNeg">LEAD
LISTING</B>  </TD>

<TD class="lines"><IMG src="images/trans.gif" width="1" height="1"
border="0"></TD>

</TR>

</TABLE>

<TABLE border="0" cellspacing="0" cellpadding="0" width="100%">

<TR>

<TD rowspan="3"><IMG src="images/trans.gif" width="8" height="1"
border="0"></TD>

<TD class="lines" colspan="10"><IMG src="images/trans.gif" width="1"
height="1" border="0"></TD>

<TD rowspan="3"><IMG src="images/trans.gif" width="8" height="1"
border="0"></TD>

</TR>

<TR>

<TD class="bgNeg" rowspan="2" width="100%"><IMG src="images/trans.gif"
width="1" height="1" border="0"></TD>

<TD class="lines"><IMG src="images/trans.gif" width="1" height="24"
border="0"></TD>

<TD class="bgNeg" class="text">  <A
href="javascript:performAction('choose_reassign_managers.jsp');">Reassig
n checked</A>  </TD>

<TD class="lines"><IMG src="images/trans.gif" width="1" height="1"
border="0"></TD>

<TD class="bgNeg" class="text">  <A
href="javascript:performAction('confirm_delete_leads.jsp');">Delete 
;checked</A>  </TD>

<TD class="lines"><IMG src="images/trans.gif" width="1" height="1"
border="0"></TD>

<TD class="bgNeg" class="text">  <A
href="javascript:performAction('confirm_archive_leads.jsp');">Archive&nb
sp;checked</A>  </TD>

<TD class="lines"><IMG src="images/trans.gif" width="1" height="1"
border="0"></TD>

<TD class="bgNeg" class="text">  <a
href="javascript:popWindow('manager_filter_1.jsp')">Manager Filter<
/a> <a
href="activate-manager-filter"><%=managerFilterStatus%></a>  <
/TD>

<TD class="lines"><IMG src="images/trans.gif" width="1" height="1"
border="0"></TD>

</TR>

<TR>

<TD class="lines" colspan="9"><IMG src="images/trans.gif" width="1"
height="1" border="0"></TD>

</TR>

</TABLE>

<br>

<FORM name="lead_listing" method="post">

<ejb:iterate id="countryManager" type="CountryManagerList"
collection="<%=countryManagers%>" empty="<SPAN
class='text'>  You don't have privileges</SPAN>">

<ejb:iterate id="manager" type="Manager"
collection="<%=countryManager%>">

<%

Collection leads = null;

String output = "";

StringBuffer outputStringBuffer = new StringBuffer();

// If moving to archive change false to true

long numberOfLeads = (campaign == null) ?
manager.getCountAllWithManager(false).longValue() :
manager.getCountAllWithManagerInCampaign(campaign, false).longValue();

if (managerFilterStatus.equals("On"))

{

if (managerFilter.contains(manager.getId()))

noManagers = false;

else

continue;

}

if (numberOfLeads > 0)

{

if (cp.getViewLeadsPerPage())

{

int current = 1;

int fromIndex = 0;

long numberOfLinks = (long)Math.ceil((double)numberOfLeads / 10.0d);

if (numberOfLinks > 1)

{

String sessionKey = manager.getCountry().getName() +
manager.getFirstName() + manager.getLastName();

sessionKey = sessionKey.replace(' ', '_');

String currPage = request.getParameter(sessionKey);

Hashtable sessionObj = (Hashtable)pageInfo.get(sessionKey);

if (sessionObj == null)

{

sessionObj = new Hashtable();

pageInfo.put(sessionKey, sessionObj);

}

if (currPage == null)

{

if (sessionObj.get("currpage") == null)

{

sessionObj.put("currpage", new Integer(1));

pageInfo.put(sessionKey, sessionObj);

}

}

else

{

sessionObj.put("currpage", new Integer(currPage));

pageInfo.put(sessionKey, sessionObj);

}

current = ((Integer)sessionObj.get("currpage")).intValue();

for (int i = 0; i < numberOfLinks; i++)

{

if (current == (i+1))

{

fromIndex = i * 10;

outputStringBuffer.append("<A style=\"color:#ff9900; font-weight:700;\"
href=\"lead_listing.jsp?");

outputStringBuffer.append(sessionKey);

outputStringBuffer.append("=");

outputStringBuffer.append(i+1);

outputStringBuffer.append("\">");

outputStringBuffer.append(i+1);

outputStringBuffer.append("</A> ");

}

else

{

outputStringBuffer.append("<A style=\"font-weight:700;\"
href=\"lead_listing.jsp?");

outputStringBuffer.append(sessionKey);

outputStringBuffer.append("=");

outputStringBuffer.append(i+1);

outputStringBuffer.append("\">");

outputStringBuffer.append(i+1);

outputStringBuffer.append("</A> ");

}

}

// If moving to archive change false to true

leads = (campaign == null) ?
manager.getAllWithManagerWithIndex(fromIndex, false) :
manager.getAllWithManagerInCampaignWithIndex(campaign, fromIndex,
false);

output = outputStringBuffer.toString();

}

else

// If moving to archive change false to true

leads = (campaign == null) ? manager.getAllWithManager(false) :
manager.getAllWithManagerInCampaign(campaign, false);

}

else

// If moving to archive change false to true

leads = (campaign == null) ? manager.getAllWithManager(false) :
manager.getAllWithManagerInCampaign(campaign, false);

}

else

continue;

%>

<SCRIPT language="JavaScript">

<!--

mngr = "<%=manager.getFirstName()%>" + "<%=manager.getLastName()%>";

mngrRep = mngr.replace(/\s/g, "_");

var HTMLstr ="<TD rowspan='2'><a name='"+mngrRep+"'><IMG
src='images/trans.gif' width='8' height='1' border='0'></a></TD>"

// -->

</SCRIPT>

<TABLE border="0" cellspacing="0" cellpadding="0" width="*">

<TR>

<SCRIPT language="JavaScript">

<!--

document.write(HTMLstr);

// -->

</SCRIPT>

<TD class="lines" colspan="5"><IMG src="images/trans.gif" width="1"
height="1" border="0"></TD>

<TD><IMG src="images/trans.gif" width="1" height="1" border="0"></TD>

</TR>

<TR>

<TD class="lines"><IMG src="images/trans.gif" width="1" height="26"
border="0"></TD>

<TD class="bgMain">  <B
class="textNeg"><%=manager.getFirstName()%> <%=manager.getLastName(
)%>, <%=manager.getLob()%>, <%=manager.getState()%>, <%=c
ountryManager.getName()%></B>  </TD>

<TD class="lines"><IMG src="images/trans.gif" width="1" height="1"
border="0"></TD>

<TD class="bgNeg">  <A
href="compile_send_reminder.jsp?id=<%=manager.getId()%>&fromPage=1">Send
reminder (last sent <%=((manager.getLastReminder() != null) ?
DateFormat.getDateTimeInstance(DateFormat.MEDIUM ,
DateFormat.MEDIUM).format(manager.getLastReminder()):
"N/A")%>)</A>  </TD>

<TD class="lines"><IMG src="images/trans.gif" width="1" height="1"
border="0"></TD>

<TD class="bgNeg">  <%=output%>  </TD>

</TR>

</TABLE>

<TABLE border="0" cellspacing="0" cellpadding="0" width="100%">

<TR>

<TD width="8" class="bgNeg"><IMG src="images/trans.gif" width="8"
height="1" border="0"></TD>

<TD class="lines">

<TABLE border="0" cellspacing="1" cellpadding="4" width="100%">

<TR>

<TD rowspan="2" colspan="5" valign="top" class="bgNeg"><B
class="text">Client</B></TD>

<TD colspan="2" align="center" class="bgNeg"><B
class="text">Actions</B></TD>

<TD colspan="4" align="center" class="bgNeg"><B
class="text">Results</B></TD>

</TR>

<TR>

<TD class="bgNeg" align="center"><SPAN class="smalltextAlt">Called
Lead</SPAN></TD>

<TD class="bgNeg" align="center"><SPAN class="smalltextAlt">Sent
Info</SPAN></TD>

<TD class="bgNeg" align="center"><SPAN class="smalltextAlt">Closed
Lead</SPAN></TD>

<TD class="bgNeg" align="center"><SPAN class="smalltextAlt">In
Progress</SPAN></TD>

<TD class="bgNeg" align="center"><SPAN class="smalltextAlt">Made
Sale</SPAN></TD>

<TD class="bgNeg" align="center"><SPAN class="smalltextAlt">Deal Size
$US</SPAN></TD>

</TR>

<ejb:iterate id="lead" type="Lead" collection="<%=leads%>">

<%

String dealSize = "";

if (lead.getDealSize().trim().length() > 0)

{

dealSize = lead.getDealSize().trim();

if (!dealSize.startsWith("?"))

dealSize = "$" + dealSize;

}

%>

<TR>

<TD class="bgNeg"><INPUT name="lead<%=lead.getId()%>" type="checkbox"
value="true"></INPUT></TD>

<TD class="bgNeg"><SPAN
class="text"><%=lead.getPriority().getName()%></SPAN></TD>

<TD class="bgNeg"><SPAN class="text"><%=lead.getCampaign() == null ? "No
Campaign" : lead.getCampaign().getName()%></SPAN></TD>

<TD class="bgNeg"><A
href="view_lead.jsp?id=<%=lead.getId()%>"><B><%=lead.getCompanyName()%><
/B></A></TD>

<TD class="bgNeg"><SPAN
class="text"><%=lead.getDisplayDate()%></SPAN></TD>

<TD class="bgNeg"
align="center"><%=getDisplayForActions(lead.getCalled())%></TD>

<TD class="bgNeg"
align="center"><%=getDisplayForActions(lead.getBrochureSent())%></TD>

<TD class="bgNeg" align="center"><%=(lead.getResult().intValue() == 1) ?
"<img src='images/checked.gif' width='18' height='18' border='0'>" :
" "%></TD>

<TD class="bgNeg" align="center"><%=(lead.getResult().intValue() == 2) ?
"<img src='images/checked.gif' width='18' height='18' border='0'>" :
" "%></TD>

<TD class="bgNeg" align="center"><%=(lead.getResult().intValue() == 3) ?
"<img src='images/checked.gif' width='18' height='18' border='0'>" :
" "%></TD>

<TD class="bgNeg" align="center"><SPAN
class="text"><%=dealSize%></SPAN></TD>

</TR>

</ejb:iterate>

</TABLE>

</TD>

<TD width="8" class="bgNeg"><IMG src="images/trans.gif" width="8"
height="1" border="0"></TD>

</TR>

</TABLE>

<BR>

</ejb:iterate>

</ejb:iterate>

<%

if (managerFilterStatus.equals("On") && noManagers)

{

%>

<TABLE border="0" cellspacing="0" cellpadding="0" width="*">

<TR>

<TD>  <SPAN class="text">All managers have been blocked by the
filter</SPAN>  </TD>

</TR>

</TABLE>

<%

}

%>

</FORM>

<%@ include file="footer.html" %>

</BODY>

</HTML>

Re: String index out of range - Postgresql 7.3.4, Resin & JDBC

From
Richard Huxton
Date:
On Monday 24 November 2003 12:22, Antony Brooke-Wood wrote:
> HI,
>
> We are getting the following error through a JSP.

Since I don't see any expert answers, I'll offer my inexpert one.

> java.lang.StringIndexOutOfBoundsException: String index out of range: 0
>         at java.lang.String.charAt(String.java:444)
>         at
> org.postgresql.jdbc1.AbstractJdbc1ResultSet.toBoolean(AbstractJdbc1Resul
> tSet.java:684)
>         at
> org.postgresql.jdbc1.AbstractJdbc1ResultSet.getBoolean(AbstractJdbc1Resu
> ltSet.java:102)

Since it's complaining about a string index = 0, that suggests to me it's
trying to check charAt(0) when the string is empty (converting "T" or "F" to
a java true/false?). Possibly the toBoolean() call is having problems with a
boolean field that is null in PG.

I'd have a look at the source for the jdbc driver near the line mentioned and
see if you can see anything suspicious. Can't help you there since my java
skills don't extend much past "hello world".

--
  Richard Huxton
  Archonet Ltd

Re: String index out of range - Postgresql 7.3.4, Resin &

From
Kris Jurka
Date:
On Mon, 24 Nov 2003, Antony Brooke-Wood wrote:

> HI,
>
> We are getting the following error through a JSP.
>
> We received the same error for both 7.3.1 through 7.3.4 and several JDBC
> driver changes (currently running the latest).
>
> java.lang.StringIndexOutOfBoundsException: String index out of range: 0
>         at java.lang.String.charAt(String.java:444)
>         at
> org.postgresql.jdbc1.AbstractJdbc1ResultSet.toBoolean(AbstractJdbc1Resul
> tSet.java:684)
>         at
> org.postgresql.jdbc1.AbstractJdbc1ResultSet.getBoolean(AbstractJdbc1Resu
> ltSet.java:102)
>         at

This problem was fixed nearly three months ago in a patch from Kim Ho, but
unfortunately the builds on jdbc.postgresql.org have not been updated in
some time.  This fix is in the 7.4 and HEAD cvs branches, but a source
build is the only way to get it at this point.

Kris Jurka