PDA

View Full Version : Help on ArrayOutOfBound Issue


sonia.sandren
02-24-2009, 07:59 AM
Hi,

In my project i need to create user profile using puma groups. But, few lines of my coding throwing ArrayOutOfBound Exception (Highlighted in Bold).

Here is my coding:

package com.raqno.pr;

import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bowstreet.webapp.WebAppAccess;
import com.ibm.portal.puma.Group;
import com.ibm.portal.puma.InvalidMemberIdException;
import com.ibm.portal.puma.MemberNotFoundException;
import com.ibm.portal.puma.SchemaViolationException;
import com.ibm.wps.util.DataBackendException;

public class PumaGroup{
public void DisplayMessage(WebAppAccess app){
HttpServletRequest httpRequest = app.getHttpServletRequest();
HttpServletResponse httpRes = app.getHttpServletResponse();

try{
app.getHttpServletResponse().getWriter().println("<SCRIPT LANGUAGE=\"JavaScript\">");
app.getHttpServletResponse().getWriter().println("alert(\"message();\")");
app.getHttpServletResponse().getWriter().println("</SCRIPT>");
}catch(Exception e)
{
System.out.println("Error in javascript Alert"+e);
System.out.println("Error in javascript Alert"+httpRequest);
System.out.println("Error in javascript Alert"+httpRes);
e.printStackTrace();
}

}


public String getGroupName(WebAppAccess app)
{
HttpServletRequest httpRequest = app.getHttpServletRequest();
com.ibm.portal.puma.User user = (com.ibm.portal.puma.User)httpRequest.getAttribute("com.ibm.portal.puma.request-user");
Group gr;
String group ="";
try {
for(Iterator e = user.getGroups().iterator();e.hasNext();)
{
gr = (Group)e.next();
group = gr.getName();

if(group.indexOf("_BW_")>0)
break;
}
} catch (MemberNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidMemberIdException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SchemaViolationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DataBackendException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return group;
}

public String getContext(WebAppAccess app)
{
HttpServletRequest req = app.getHttpServletRequest();
String path =req.getContextPath();
return path;
}

public Vector getList(WebAppAccess app)
{
Vector list = new Vector();
String group = getGroupName(app);
//System.out.println("--inside getList---");

try{

int bwlocation = group.indexOf("_BW");
//System.out.println("---inside try---"+bwlocation);
String strgroup = group.substring(0,bwlocation);
//System.out.println("---strgroup---"+strgroup);
StringTokenizer st =new StringTokenizer(strgroup,"_");
//System.out.println("---st---"+st);
while (st.hasMoreElements())
{
list.add(st.nextElement());
}

}//try
catch(Exception s)
{
System.out.println("error in method getCountry BU"+s);
}

//System.out.println("list"+list);
return list;
}


public String getCountry(WebAppAccess app)
{
Vector list = getList(app);
System.out.println("inside getCountry" +list);
String country ="null";
try{

country = (String)list.get(0);
System.out.println("inside try"+country);


}//try
catch(Exception s)
{
System.out.println("error in method getCountry"+s);
}
//System.out.println("inside getcountry"+country);


//String country ="MY";
return country;
}


public String getBU(WebAppAccess app)
{
Vector list = getList(app);
String bu ="null";
try{
bu = (String)list.get(1);
System.out.println("bu"+bu);
}//try
catch(Exception s)
{
System.out.println("error in method getBU"+s);
}

//String bu ="%";

return bu.toUpperCase().trim();
}

}


How to solve this issue? Please assist me.

Gox
02-24-2009, 08:38 AM
Is the call to getList(app) returning "null' or an empty Vector? If so then it's possible your (String)list.get(0) and (String)list.get(1) calls could be outside the size of the Vector.

Balu Sadhasivam
02-25-2009, 07:06 PM
public Vector getList(WebAppAccess app)
{
Vector list = new Vector();
....

public String getCountry(WebAppAccess app)
{
Vector list = getList(app);



Since you are creating a Vector object and returning it , list is not null and when accessed with get(0) , it throws AOB exception as its empty. check if you getList populates the Vector list or not