JSP: error page exception.getMessage returning null for setProperty exceptions

K

kaeli

Hey all,

I have a little problem. My error page (JSP) seems to not be getting the
exception text for some reason when my beans throw exceptions in the setters
and I use setProperty. The errors do fine when I use other methods. This is
the only case in which they aren't working.
Here's the setup. Can someone tell me what I'm doing wrong?

In the bean: (many similar methods; this one is generic for illustrative
purposes)
public void setField(String str) throws IllegalArgumentException
{
// limit 10 chars (null allowed)
if (str!= null && str.length() > 10)
{
throw new IllegalArgumentException(
"Field must be 10 characters or less.");
}
this.field = str;
}

In the JSP:
<%@ page isErrorPage="false" errorPage="err.jsp" %>
....
<jsp:useBean id="myBean" class="myPackage.myBean" scope="page" />
<jsp:setProperty name="myBean" property="*" />
<% myBean.testUpdate(s.getPerms()); %>

Err.jsp (note that "exception" is an intrinsic JSP object, like "out")
<p class="bigAttention">Message: <%= exception.getMessage() %></p>

When exceptions are thrown from the testUpdate method in the bean, they
forward just fine to err.jsp. When thrown from the setters, I get null when I
try exception.getMessage (or just JasperException when I do toString).

Sample from using toString:
---------------------------------
Message: org.apache.jasper.JasperException

Stack Trace: org.apache.jasper.JasperException at
org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper
(JspRuntimeLibrary.java:199) at
---------------------------------


When testUpdate fails:
---------------------------------
Message: This operation requires permissions. You either have VIEW
permissions or aren't logged in. Please LOG IN if you haven't, then try
again.

Stack Trace: java.lang.IllegalAccessException: This operation requires
permissions. You either have VIEW permissions or aren't logged in. Please LOG
IN if you haven't, then try again. at
---------------------------------

When I used getMessage, it was similar, but Message was null instead of
JasperException.

WTF?
Anyone?

--
 
J

John C. Bollinger

kaeli said:
Hey all,

I have a little problem. My error page (JSP) seems to not be getting the
exception text for some reason when my beans throw exceptions in the setters
and I use setProperty. The errors do fine when I use other methods. This is
the only case in which they aren't working.
Here's the setup. Can someone tell me what I'm doing wrong?

You are assuming that an exception must have a non-null message. That
is not the case.

I note that the message-less exception you are reporting is a
JasperException, which is generated by the Tomcat JSP runtime engine.
This may be thrown in response to an exception in a setter (in which
case you might be able to get the original exception via getCause()), or
for some other reason.


John Bollinger
(e-mail address removed)
 
K

kaeli

You are assuming that an exception must have a non-null message. That
is not the case.

It is when I set it myself.
The exception that is thrown and that should be reported is the one I posted.

throw new IllegalArgumentException(
"Field must be 10 characters or less.");

This is in testing, so I know for sure what the exception is.
Also, when I use the method instead of the jsp setProperty, it fires off
fine. I'm trying to get code out of my JSP pages and into tags where it
belongs. Right now, the production code sets all object members like
objectName.setField(request.getParameter("fieldName"));
In that case, the error message is done correctly. It is only failing when I
use setProperty.

I note that the message-less exception you are reporting is a
JasperException, which is generated by the Tomcat JSP runtime engine.

I'm not using Tomcat.
I'm using Netscape Enterprise Server. The exception is NOT supposed to be
handled by the jasper engine, which is the point. I don't know why it is
being handled that way. It should not be (or I don't want it to be if for
some reason this is normal with beans). Something is passing it off and I
don't know why.

Thanks, though.

--
 
S

Sudsy

kaeli wrote:
I'm using Netscape Enterprise Server. The exception is NOT supposed to be
handled by the jasper engine, which is the point. I don't know why it is
being handled that way. It should not be (or I don't want it to be if for
some reason this is normal with beans). Something is passing it off and I
don't know why.

Just a "shot in the dark" but I note that IllegalArgumentException
extends RuntimeException. It could well be that the container is
handling it differently than a "normal" application exception, i.e.
one which extends Exception.
Of course, without access to the source...
 
J

John C. Bollinger

kaeli said:
It is when I set it myself.
The exception that is thrown and that should be reported is the one I posted.

throw new IllegalArgumentException(
"Field must be 10 characters or less.");

Perhaps I was too zealous about snipping your original post. Yes, I saw
that that is what your code throws, but it is not what you reported seeing:

[from the original post:]

Sample from using toString:
---------------------------------
Message: org.apache.jasper.JasperException

Stack Trace: org.apache.jasper.JasperException at
org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper
(JspRuntimeLibrary.java:199) at
---------------------------------

As I wrote before, that message shows a JasperException with an empty or
null message.
This is in testing, so I know for sure what the exception is.

If this is in testing, then you are less likely now than at any other
time to know what the exception is. You may have an idea of what the
exception is _supposed to be_, but that's an entirely different thing.
Also, when I use the method instead of the jsp setProperty, it fires off
fine. I'm trying to get code out of my JSP pages and into tags where it
belongs. Right now, the production code sets all object members like
objectName.setField(request.getParameter("fieldName"));
In that case, the error message is done correctly. It is only failing when I
use setProperty.

I observe that the exception in question is being thrown from a method
called "introspectorhelper", and in your example right there you are
setting a bean property from a page parameter with a different name.
(I.e. it should be
objectName.setFieldName(request.getParameter("fieldName")); or
objectName.setField(request.getParameter("field")); for the wildcard
setProperty action to work.) This all leads me to believe that your
page parameter names do not line up with your bean property names, and
that you are indeed getting a different exception than you expect, which
you have not particular reason to expect will have a non-null message.

It is also possible that your object does not comply fully with the
JavaBeans spec (it might have getters and setters for the property that
imply different types, for instance, or that are otherwise incompatible
with the Introspector).
I'm not using Tomcat.

Jasper is the Tomcat JSP runtime engine. Your exception appears to show
that you are using at least that part of Tomcat, as I said.
I'm using Netscape Enterprise Server. The exception is NOT supposed to be
handled by the jasper engine, which is the point.

No, I think you're missing the point, which is that something different
may be happening than you think. My best guess is that your
IllegalArgumentException is never being thrown at all because the the
JSP engine is not even finding the method.
I don't know why it is
being handled that way. It should not be (or I don't want it to be if for
some reason this is normal with beans). Something is passing it off and I
don't know why.

You are making assumptions about what is happening that you have
presented no firm basis for. For example, "something is passing it off"
and "it should not be [handled that way]." I find it highly unlikely
that any exception thrown by your bean would have its message changed by
the JSP container, and indeed, I see no evidence for such a thing.

I was wrong, though, when I characterized the problem as an assumption
that the exception message was non-null. It seems that's just a symptom
of the real problem, which is that you are making a faulty assumption
about what exception you should be getting.


John Bollinger
(e-mail address removed)
 
K

kaeli

kaeli wrote:


Just a "shot in the dark" but I note that IllegalArgumentException
extends RuntimeException. It could well be that the container is
handling it differently than a "normal" application exception, i.e.
one which extends Exception.
Of course, without access to the source...

No, but good try.

I changed it to throw Exception instead, same thing.

It seems to be handling exceptions from beans differently when you use
setProperty. I changed the code from using
<jsp:setProperty name="officeBean" property="*" />
to
<% officeBean.setField(request.getParamater("field")) %>

I got my error right when I did that.
Message: Field must be 10 characters or less.
Stack Trace: java.lang.Exception: Field must be 10 characters or less...

So I tried changing it to use setProperty with just the one field. I thought
maybe it was the asterisk doing funny things.
<% String str = request.getParameter("field"); %>
<jsp:setProperty name="officeBean" property="field" value="<%=str%>" />

No go. Null message from jasper again.

I'm going to Google some more. I wonder if this is a Netscape Enterprise
Server issue...
I don't recall seeing this problem with Tomcat.

--
--
~kaeli~
The Bermuda Triangle got tired of warm weather. It moved to
Finland. Now Santa Claus is missing.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top