• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OC4J RELEASE 3 bug

 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using OC4J RELEASE 3. If i close a connection object without opening it.THe method of session bean is rotating in a loop before giving null poiner exception.Is this the problem of oc4j or EJB.
Any suggestion
THanks
kundan
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't do that then!

You did ask for suggestions...

Jules
[ August 14, 2004: Message edited by: Julian Kennedy ]
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kundan,
Could you provide some more info about the EJB so we can further determine the problem? What is the session bean doing? Maybe post a code fragment?
 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi jeanne
Yes My present architechture consist of action class,session bean and DAO.
My session bean has two private methods one method is opening a connection object and closing it inside that method only but the other one is taking connection as parameter.In one particular scenario i needed both the method
so what i did i wrote one more method and called those two from that particular method like the code below
public HashMap getAllData(String param1.String param2) throws ApplicationException
{
Connection con=null;
try{
if(param1.equals("One"))
{
callMeth1();
}
else
{
con = MYConnection.getConnection("my con");
callMeth1();
callMeth2(con);
}
}
catch(Exception e)
{
throw new ApplicationException();
}
finally
{
myConnection.closeConnection();
}

}

If i remove the closeconnection from finally to else loop every thing is fine else every thing is falls in a for loop which ultimately results in null pointer exception.
But i feel it should give some error in case of param1==One rather than falling in for loop .This getAllData is getting called many times for some unknown reason.
On emore bug i found in rel 3, if i put one of the key of HashMap return type as null then it gives EJBUtils.close exception i.e ultimately null pointer exception.When i decomile orianEjb package i founf they have done one mistake by noy checking null before using reflection getClass inside it.
I am waiting for your suggestions
Thanks
kundan varma
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kundan Varma,

Perhaps I should be a little more helpful than in my intial post. The amusing link doesn't seem to be working at the mo anyway. :roll:

What I meant by "don't do that then" is, if there's any doubt, ensure that the connection is not already closed using code like this:


Ideally you should avoid this kind of problem altogether by ensuring that you open and close connections (and other openable and closeable things, like files and transactions) at the same level in your code.

However, taking another quick look at your code, it appears you're getting the connection from some kind of pool (MyConnection). If that's the case then you should probably just be returning the connection to the pool (for someone else to use) rather than closing it.

Note that throwing a NullPointerException in an API method can be legitimate behaviour (i.e. it's not necessarily a bug). Check out the documentation to make sure that it's valid to pass in null.

Please use the UBB CODE tags when posting code as it makes it much easier to read.

Jules

[Corrected typo in code sample]
[ August 15, 2004: Message edited by: Julian Kennedy ]
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kundan,
I would change the code Jules provided to:

Since you only open the connection in one block, it is null in the other. In general, this is a valid pattern because you could have an exception before getting a connection. It is always good to close the connection in a finally block. As you did, you should still call close() even if using a connection pool. The close() call returns the connection to the pool.

Having said that, I would refactor your method to make the problem simpler:

This makes it clearer that the first method gets called regardless of the parameter value. It also allows you to keep the try/catch/finally block consistent with the connection statement. (that is the levels thing Jules was talking about.)
 
JulianInactive KennedyInactive
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Taking Jeanne's refactored example, I'm still unclear on a couple of things. I've highlighted them in the source below:

Some of what I wrote in my previous post was ambiguous, so hopefully, if my assumptions are correct, this should clear it up.

Jules

[ August 15, 2004: Message edited by: Julian Kennedy ]
[ August 15, 2004: Message edited by: Julian Kennedy ]
 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Jeanne
I know my code bugs.THanks for ur help.BUt my question is why oc4j behaves this instead of giving null pointer exception why is that falling in loop before crashing.
Thanks
kundan
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kundan,
I really can't comment on that as the loop isn't in the code snippet you posted.
reply
    Bookmark Topic Watch Topic
  • New Topic