H
HalcyonWild
Hi,
I am facing a strange problem and I cannot find the reason. I have a
calling method, processOrder() in a plain java file in which I am doing
this.
public Order processOrder()
{
Customer c = null;
if (orderType.equals("typeA")
{
processA(c, orderManager);
}
else if (orderType.equals("typeB")
{
processB(c, orderManager);
}
logger.log("customer is "+c);
//this prints null. though i populate it in process methods.
}
private void processB(Customer c, OrderManager orderMgr)
{
-- some lines --
c = CustomerBean.getCustomerByID(orderMgr.getCustomerId());
//this is a session Bean.
logger.log("customer in process method = "+c); //prints fine
}
I wonder what am I doing wrong. How can c become null in the calling
method. I am getting a nullpointer exception for sub. Am I missing
something very fundamental. Or is it some strange behaviour of session
beans. References are passed for objects in Java. So c should retain
its value. I have come across very similar situations and this has
worked for me. I checked if I am making c = null anywhere, but that is
not the case. Also the logs show c just before return in called method.
And immediately, I log c in the calling method, which shows null. This
happens for both processA and processB methods, and they are similar,
with some extra processing for processA.
Thanks,
Halcyon
I am facing a strange problem and I cannot find the reason. I have a
calling method, processOrder() in a plain java file in which I am doing
this.
public Order processOrder()
{
Customer c = null;
if (orderType.equals("typeA")
{
processA(c, orderManager);
}
else if (orderType.equals("typeB")
{
processB(c, orderManager);
}
logger.log("customer is "+c);
//this prints null. though i populate it in process methods.
}
private void processB(Customer c, OrderManager orderMgr)
{
-- some lines --
c = CustomerBean.getCustomerByID(orderMgr.getCustomerId());
//this is a session Bean.
logger.log("customer in process method = "+c); //prints fine
}
I wonder what am I doing wrong. How can c become null in the calling
method. I am getting a nullpointer exception for sub. Am I missing
something very fundamental. Or is it some strange behaviour of session
beans. References are passed for objects in Java. So c should retain
its value. I have come across very similar situations and this has
worked for me. I checked if I am making c = null anywhere, but that is
not the case. Also the logs show c just before return in called method.
And immediately, I log c in the calling method, which shows null. This
happens for both processA and processB methods, and they are similar,
with some extra processing for processA.
Thanks,
Halcyon