Unable to trace

R

RVic

Related to my previous post here, I have a simple piece of code in a servlet:

HttpServletRequest request = RequestData.getRequest();
HttpServletResponse response = RequestData.getResponse();
request.getRequestDispatcher("/something").forward(request, response);

The last line of which throws an error (below) which I am unable to trace further from this line in the stack. The error is :

javax.el.ELException: Cannot convert beta of type class java.lang.String toclass com.cblnet.web.data.Env

and com.cblnet.web.data.Env is:

public enum Env {
local,
mirror,
production;
}

But if you look at the stack trace, below (the last line in it is the last line in my simple three lines of code, the request.getRequestDispatcher().forward() ) I have no way to trace what is causing this -- can anyone shed any light here for me on how to track down this frustrating offender? Thanksin advance, RVic


2013-05-09 11:22:23,425 ERROR [ajp-bio-9509-exec-4] [Page] Error forwardingrequest to display JSP.
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.servlet.jsp.JspException: javax.el.ELException: Cannot convert beta of type class java.lang.String to class com.cblnet.web.data.Env
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at com.cblnet.web.view.Page.forward(Page.java:73)
 
E

Eric Sosman

Related to my previous post here, I have a simple piece of code in a servlet:

HttpServletRequest request = RequestData.getRequest();
HttpServletResponse response = RequestData.getResponse();
request.getRequestDispatcher("/something").forward(request, response);

The last line of which throws an error (below) which I am unable to trace further from this line in the stack. The error is :

javax.el.ELException: Cannot convert beta of type class java.lang.String to class com.cblnet.web.data.Env

and com.cblnet.web.data.Env is:

public enum Env {
local,
mirror,
production;
}

Just a guess: What happens if you change the Env enum to

public enum Env {
local,
mirror,
production,
beta; // this is the guess
}

? If somebody somewhere calls Env.valueOf("beta") they should get
an IllegalArgumentException (using the original Env), but perhaps
they're catching it and throwing an ElException instead.
 
M

markspace

The last line of which throws an error (below) which I am unable to
trace further from this line in the stack. The error is :
But if you look at the stack trace,


I have to somewhat doubt your premise. If you look at the stack trace,
it looks to me like the dispatch succeeded, and you got an error
somewhere after that.

This line here seems to say that you're in a filter, running code:
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)


And then you seem to dispatch to a servlet:
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


And then you run a JSP file. Etc. I'm not sure how to find out exactly
what file you're running though. That might take a little research and
experimentation.
 
A

Arne Vajhøj

Related to my previous post here, I have a simple piece of code in a servlet:

HttpServletRequest request = RequestData.getRequest();
HttpServletResponse response = RequestData.getResponse();
request.getRequestDispatcher("/something").forward(request, response);

The last line of which throws an error (below) which I am unable to trace further from this line in the stack. The error is :

javax.el.ELException: Cannot convert beta of type class java.lang.String to class com.cblnet.web.data.Env

and com.cblnet.web.data.Env is:

public enum Env {
local,
mirror,
production;
}

But if you look at the stack trace, below (the last line in it is the last line in my simple three lines of code, the request.getRequestDispatcher().forward() ) I have no way to trace what is causing this -- can anyone shed any light here for me on how to track down this frustrating offender? Thanks in advance, RVic


2013-05-09 11:22:23,425 ERROR [ajp-bio-9509-exec-4] [Page] Error forwarding request to display JSP.
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.servlet.jsp.JspException: javax.el.ELException: Cannot convert beta of type class java.lang.String to class com.cblnet.web.data.Env
at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
at com.cblnet.web.view.Page.forward(Page.java:73)

How does the JSP page you forward to look like?

Does it refer to "beta" anywhere?

Arne
 
R

RVic

I have jsp's that DO refer to 'beta' but not the jsp's being forwarded to here. Simply, it is calling this jsp:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="cn" %>
<%@ taglib tagdir="/WEB-INF/tags/admin" prefix="admin" %>
<%@ taglib tagdir="/WEB-INF/tags/footer" prefix="footer" %>
<%@ taglib tagdir="/WEB-INF/tags/header" prefix="header" %>
<%@ taglib tagdir="/WEB-INF/tags/sidebar" prefix="sidebar" %>

<%--@elvariable id="bodyUrl" type="java.lang.String"--%>
<%--@elvariable id="user" type="com.capablenet.domain.User"--%>


















">view site

















Where bodyUrl is this jsp:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

Administration | Access Denied





${text}





We're sorry, the page you are trying to reach is part of a restricted portion of our site.
You are not currently logged on with proper permissions to view it.




If you believe you should have permissions to view this area, please send us ">Feedback.
 
R

RVic

I have jsp's that DO refer to 'beta' but not the jsp's being forwarded to here. Simply, it is calling this jsp:
'<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
'<%@ taglib tagdir="/WEB-INF/tags" prefix="cn" %>
'<%@ taglib tagdir="/WEB-INF/tags/admin" prefix="admin" %>
'<%@ taglib tagdir="/WEB-INF/tags/footer" prefix="footer" %>
'<%@ taglib tagdir="/WEB-INF/tags/header" prefix="header" %>
'<%@ taglib tagdir="/WEB-INF/tags/sidebar" prefix="sidebar" %>
'
'<%--@elvariable id="bodyUrl" type="java.lang.String"--%>
'<%--@elvariable id="user" type="com.capablenet.domain.User"--%>
'
'<cn:html>
' <admin:head/>
' <body id="admin">
' <div id="container">
' <div id="header" style="float:left;">
' <admin:adminNav/>
' </div>
' <br class="clear"/>
'
' <div id="site_info">
' <header:communityBrand/>
' <div id="site-links">
' <a id="viewsite" href="<c:url value="/"/>">view site</a>
' </div>
' <admin:currentUser user="${user}"/>
' </div>
' <div id="main-content">
' <div id="inner-content">
' <c:import url="${bodyUrl}"/>
' <br class="clear"/>
' </div>
' </div>
' <footer:footer/>
' </div>
' </body>
'</cn:html>

Where ${bodyURL} is:

'<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
'
'<h1 class="title">Administration | <span>Access Denied</span></h1>
'
'<c:choose>
' <c:when test="${!empty text}">
' <p>
' ${text}
' </p>
' </c:when>
' <c:eek:therwise>
' <p><strong>
' We're sorry, the page you are trying to reach is part of a restricted 'portion of our site.
' You are not currently logged on with proper permissions to view it.
' </strong></p>
'
' <p>
' If you believe you should have permissions to view this area, please 'send us <a href="<c:url value="/help/feedback"/>">Feedback</a>.
' </p>
' </c:eek:therwise>
'</c:choose>
 
R

RVic

I got it. Thanks for pointing me in the right direction Eric -- the Env enum needed the enumeration 'beta' in it.

Thanks for your help guys, I am most grateful. RVic
 
E

Eric Sosman

I got it. Thanks for pointing me in the right direction Eric -- the Env enum needed the enumeration 'beta' in it.

Thanks for your help guys, I am most grateful. RVic

That's probably not the end of your problems, just a clue
about their mechanism. Adding a `beta' value to the enum means
that Env.valueOf("beta") will now return Env.beta instead of
throwing an exception. That's all fine and dandy, but what will
the rest of the code do when it encounters this new Env.beta
object? For example, there may be something like

Env env = Env.valueOf(someString);
switch (env) {
case local:
// ...
break;
case mirror:
// ...
break;
case production:
// ...
break;
}

A "beta" value will no longer cause an exception in this code,
but whatever was supposed to have been done by the switch block
will remain un-done ... (This is one reason I think it's almost
always a good idea to have a `default:' label in every switch,
even if all it does is `assert false;'.)

You don't have a cure yet (not for sure, anyhow): You just
have the beginnings of a diagnosis.
 
D

Daniel Pitts

That's probably not the end of your problems, just a clue
about their mechanism. Adding a `beta' value to the enum means
that Env.valueOf("beta") will now return Env.beta instead of
throwing an exception. That's all fine and dandy, but what will
the rest of the code do when it encounters this new Env.beta
object? For example, there may be something like

Env env = Env.valueOf(someString);
switch (env) {
case local:
// ...
break;
case mirror:
// ...
break;
case production:
// ...
break;
}

A "beta" value will no longer cause an exception in this code,
but whatever was supposed to have been done by the switch block
will remain un-done ... (This is one reason I think it's almost
always a good idea to have a `default:' label in every switch,
even if all it does is `assert false;'.)
Or make the enum an abstract base class and have all behavior defined in
the enum itself.

For example, using them as a flyweight:
<http://virtualinfinity.net/wordpress/program-design/2007/10/22/using-enums-as-a-flyweight-pattern/>

Switching on an enum is dangerous business, just for the reason Eric is
demonstrating. Someone adds a new enum, and switch logic no longer
handles every case. If I do happen to use an enum and have a switch
statement for it, I *always* have a default case. Sometimes that default
is "throw new UnsupportedOperationException();" Other times that default
is something that is "sensible" if an override isn't specified.
 
D

Daniele Futtorovic

Switching on an enum is dangerous business, just for the reason Eric is
demonstrating. Someone adds a new enum, and switch logic no longer
handles every case. If I do happen to use an enum and have a switch
statement for it, I *always* have a default case. Sometimes that default
is "throw new UnsupportedOperationException();" Other times that default
is something that is "sensible" if an override isn't specified.

Crossing the street is dangerous business, too.
 
D

Daniel Pitts

Crossing the street is dangerous business, too.

Switching on an enum is more likely to result in an accident. One can
look both ways before crossing the street, but the breaking of a switch
statement can happen years after you wrote it. It would be like getting
hit by a bus a month after you crossed its path.
 
D

Daniele Futtorovic

Switching on an enum is more likely to result in an accident. One can
look both ways before crossing the street, but the breaking of a switch
statement can happen years after you wrote it. It would be like getting
hit by a bus a month after you crossed its path.

I would also strongly advise, when writing a switch on an enum, to
account for all possible (future) cases, possibly using a throw in the
default clause, or some similar means. That being said, this goes for
switches on other types as well; and either way a switch might
purposively and gracefully cover only part of the possible values.

What I disagree with is what I construe as an implication that one
should steer clear from switches on enums because of those "risks". Such
switches are no more and no less "dangerous" than the vast majority of
code constructs. And they rank firmly among the Very Useful ones.
 
A

Arne Vajhøj

I have jsp's that DO refer to 'beta' but not the jsp's being forwarded to here. Simply, it is calling this jsp:
....

Apparently the problem has been solved.

But I am a bit puzzled.

The problem happened in some servlet code that forwarded to a JSP page.

If neither that servlet or that JSP page referred to beta - then where
did the call that try to parse "beta" occur??

Arne
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top