users@glassfish.java.net

RE: Random NullPointerExceptions from ValueExpression

From: Woods, Michael G <michael.g.woods_at_lmco.com>
Date: Mon, 20 Aug 2007 17:58:49 -0400

I still haven't found a solution to this problem thus far. In my testing
I find that the Servlet returns a valid response the first two times
then getValue() throws a NullPointerException eight times, then two
valid results, then eight failures, etc etc...

 

This is constantly reproducible. I've also tried containing the
following code in a do {...} while (tc == null); however that leads to
an infinite loop. While debugging and stepping through the code, all the
variables have values (except tc) and I can't spot anything much out of
the norm.

 

FacesContext fc = this.getFacesContext(request, response);

if (null != fc) {

        ExpressionFactory expFactory =
fc.getApplication().getExpressionFactory();

        ELContext elc = fc.getELContext();

        ValueExpression valExp = expFactory.createValueExpression(elc,
"#{taskController}", TaskController.class);

        

        try {

            tc = (TaskController) valExp.getValue(elc); //This is where
the code fails

...

...

...

        } catch (NullPointerException e) {

            log.severe("***** ValueExpression.getValue(taskController)
failed again...");

 
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"valExp.getValue() failed");

        }

} else {

 
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"FacesContext was null");

}

 

Anyone have any ideas?

 

Thanks,
Mike Woods

 

________________________________

From: Woods, Michael G
Sent: Thursday, August 16, 2007 12:01 PM
To: users_at_glassfish.dev.java.net
Subject: Random NullPointerExceptions from ValueExpression

 

I have a problem grabbing "TaskController" from my application. Upon
logging into the web app and requesting the servlet that the following
code is running, I randomly get the proper output or a
NullPointerException. The exception occurs in the 5th line of code
listed below:

 

FacesContext fc = FacesContext.getCurrentInstance();

Application app = fc.getApplication();

ExpressionFactory expFactory = app.getExpressionFactory();

ValueExpression valExp =
expFactory.createValueExpression(fc.getELContext(), "#{taskController}",
TaskController.class);

TaskController tc = (TaskController) valExp.getValue(fc.getELContext());

 

tc is null after this, however if I request the link again and again,
I'll get proper output about once every five requests (the very first
request is always correct).

 

I've also tried the deprecated ValueBinding method however that results
in the same situation. Anyone have a suggestion on where to look for the
cause of this problem?

 

Thanks,

Mike Woods