No Exception in the application, but in the server !!

I get the following message from the server log every time I operate my Login.jsp page. But the login activity is done as expected. (All "catch" blocks in the page contain proper server logs, and none of them are appearing in the message from the server log-that means no exceptions are thrown from my page !!)

[#|2006-07-22T10:10:17.468+0100|SEVERE|sun-appserver-pe8.2|javax.enterprise. system.container.web|_ThreadID=16;|WebModule[/Myproject]null

java.lang.NullPointerException

at com.sun.rave.web.ui.appbase.AbstractPageBean.afterPhase(AbstractPageBean.java:1 47)

at com.sun.rave.web.ui.appbase.faces.ViewHandlerImpl.afterPhase(ViewHandlerImpl.ja va:441)

at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:235)

at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja va:25)

at java.lang.reflect.Method.invoke(Method.java:585)

at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)

at java.security.AccessController.doPrivileged(Native Method)

at javax.security.auth.Subject.doAsPrivileged(Subject.java:517)

at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)

at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFil terChain.java:257)

at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterCha in.java:55)

at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.ja va:161)

at java.security.AccessController.doPrivileged(Native Method)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain .java:157)

at com.sun.rave.web.ui.util.UploadFilter.doFilter(UploadFilter.java:194)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFil terChain.java:210)

at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterCha in.java:55)

at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.ja va:161)

at java.security.AccessController.doPrivileged(Native Method)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain .java:157)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java: 263)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)

at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextVal ve.java:225)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java: 173)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:13 2)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:551)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:933)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:189)

at com.sun.enterprise.web.connector.grizzly.ProcessorTask.doProcess(ProcessorTask. java:604)

at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.ja va:475)

at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask .java:371)

at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:264)

at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:281)

at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:83)

|#]

Any help to solve this issue is very much appreciated.

Thanks.

[4260 byte] By [MISS_DUKE] at [2007-11-26 8:57:51]
# 1

Is there a particular exit condition for the page that causes this? In other words, do you only see this if the login is unsuccessful and you are navigating to another page? The exception is in the RENDER_RESPONSE afterphase condition. Are you doing any forwards or redirects?

Thanks!

-David

DavidBotterill at 2007-7-6 22:58:48 > top of Java-index,Development Tools,Java Tools...
# 2

Thanks very much David.Botterill !

Your clue is very helpful to find the cause of the error. Actually I do redirect inside a "try" block which is in a button action method. If I comment off the redirect code the particular Exception is not thrown.

But now I have 2 type of questions:

(1) Why can't I redirect from a "try" block?

(2) (Tough question) How you are able to interpret the error message exacetly? What can I do to increase my knowledge to this level? (I am educated to postgraduate level in Internet applications development)

I mostly expect answer for question 2.

Thanks.

MISS_DUKE at 2007-7-6 22:58:48 > top of Java-index,Development Tools,Java Tools...
# 3

> But now I have 2 type of questions:

>

> (1) Why can't I redirect from a "try" block?

I'd have to see more of the code to try and figure this out.

>

> (2) (Tough question) How you are able to interpret

> the error message exacetly? What can I do to increase

> my knowledge to this level? (I am educated to

> postgraduate level in Internet applications

> development)

Here were some clues that I found that might help you in the future.

Clue 1. If you go into the code of the Page bean and click on AbstractPageBean then right-click->go to->source, you'll see the source code for AbstractPageBean. Looking at the exception

java.lang.NullPointerException

at com.sun.rave.web.ui.appbase.AbstractPageBean.afterPhase(AbstractPageBean.java:147)

You can see the problem line in this snippet:

public void afterPhase(PhaseEvent event) {

...

146} else if (PhaseId.RENDER_RESPONSE.equals(phaseId)) {

147if (!FacesContext.getCurrentInstance().getResponseComplete()) {

148afterRenderResponse();

One can easily deduce that the NPE comes from FaceContext.getCurrentInstance().

Clue 2. So next I wondered what would cause a page to not be in a FacesContext. I then looked at the article I wrote "The Java Studio Creator 2 Application Model" (http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/app _model.html ) to see where this afterphase in the RenderResponse phase would happen. I'm not a JSF expert and I use this document many times to help find my way. After looking at the document I thought about the "redirect" and "forward" scenario.

Would you please email me as much code as you can so I can see if there is a test case to repeat the NPE? If I can repeat it, I can file a defect to at least get the NPE fixed and some better error messages.

Lastly, please check out Winston Prakash's blog (http://blogs.sun.com/roller/page/winston?entry=relative_url_problems_forward_v s) and Jayashri Visvanathan's (http://blogs.sun.com/roller/page/jayashri?entry=when_and_how_to_redirect) blog on redirects and forwards.

Cheers!

-David

DavidBotterill at 2007-7-6 22:58:48 > top of Java-index,Development Tools,Java Tools...
# 4

Hi David.Botterill !

Thank you very much for your detailed reply. The information given is very very useful to me.

This is my login code:

public String loginImageHyperlink_action() {

String username= loginUsername.getText().toString().toLowerCase();

String password=loginPassword.getText().toString().toLowerCase();

try {

RowKey userRowKey = loginDp.findFirst

(new String[] { "login.EMAIL", "login.PASSWORD" },

new Object[] {username, password} );

if (userRowKey == null) {

error("Invalid username or Password.");

return null;

}else{

setValue("#{sessionScope.username}", username) ;

afterLoginPage(); //If this line if comment off no exception in thrown

}

} catch (Exception e) {

log(" ERROR !! (Login.jspf/loginImageHyperlink_action()/catch block ", e);

error("Cannot perform login.");

return null;

}

return null;

}

public void afterLoginPage(){

String fromUrl=(String)getValue("#{sessionScope.fromUrl}");

if(fromUrl!=null){

try{

this.getExternalContext().redirect(fromUrl);

}catch (IOException e){

log(" ERROR !! (Header.jspf/afterLoginPage()/catch block_1 ", e);

}

}else{

try{

this.getExternalContext().redirect("../home/Home_2.jsp");

}catch (IOException e){

log(" ERROR !! (Header.jspf/afterLoginPage()/catch block_2 ", e);

}

}

}

Thanks.

MISS_DUKE at 2007-7-6 22:58:48 > top of Java-index,Development Tools,Java Tools...
# 5

I have fixed this issue:

In the method afterLoginPage() I use a session attribute "fromUrl". Exception is thrown if the "fromUrl" is formed like this:

FacesContext fc =this.getFacesContext();

String viewId = fc.getViewRoot().getViewId();

setValue("#{sessionScope.fromUrl}", "../faces"+viewId);

Exception is NOT thrown if the "fromUrl" is formed like this:

FacesContext fc=this.getFacesContext();

String viewId =fc.getViewRoot().getViewId();

//setValue("#{sessionScope.fromUrl}", "../faces"+viewId);

setValue("#{sessionScope.fromUrl}", ".."+viewId);

Thanks.

MISS_DUKE at 2007-7-6 22:58:48 > top of Java-index,Development Tools,Java Tools...
# 6

I was having the same issue when opening JavaScript pop-up windows. When the window was opened using window.open('faces/RoomList.jsp'....etc I got the NPE. After reading this I changed to just using window.open('RoomList.jsp'...etc, and it doesn't throw the NPE anymore.

cheers,

Paul

UVic_Paul at 2007-7-6 22:58:48 > top of Java-index,Development Tools,Java Tools...