Unable to trace

Discussion in 'Java' started by RVic, May 9, 2013.

  1. RVic

    RVic Guest

    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)
    RVic, May 9, 2013
    #1
    1. Advertising

  2. RVic

    Eric Sosman Guest

    On 5/9/2013 12:53 PM, RVic wrote:
    > 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.

    --
    Eric Sosman
    d
    Eric Sosman, May 9, 2013
    #2
    1. Advertising

  3. RVic

    markspace Guest

    On 5/9/2013 9:53 AM, RVic wrote:
    > 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.
    markspace, May 9, 2013
    #3
  4. RVic

    Arne Vajhøj Guest

    On 5/9/2013 12:53 PM, RVic wrote:
    > 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
    Arne Vajhøj, May 10, 2013
    #4
  5. RVic

    RVic Guest

    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.
    RVic, May 10, 2013
    #5
  6. RVic

    RVic Guest

    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>
    RVic, May 10, 2013
    #6
  7. RVic

    RVic Guest

    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
    RVic, May 10, 2013
    #7
  8. RVic

    Eric Sosman Guest

    On 5/10/2013 10:26 AM, RVic wrote:
    > 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.

    --
    Eric Sosman
    d
    Eric Sosman, May 10, 2013
    #8
  9. RVic

    Daniel Pitts Guest

    On 5/10/13 7:43 AM, Eric Sosman wrote:
    > On 5/10/2013 10:26 AM, RVic wrote:
    >> 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;'.)

    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.
    Daniel Pitts, May 10, 2013
    #9
  10. On 10/05/2013 18:52, Daniel Pitts allegedly wrote:
    > 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.

    --
    DF.
    Daniele Futtorovic, May 10, 2013
    #10
  11. RVic

    Daniel Pitts Guest

    On 5/10/13 10:03 AM, Daniele Futtorovic wrote:
    > On 10/05/2013 18:52, Daniel Pitts allegedly wrote:
    >> 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.


    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.
    Daniel Pitts, May 10, 2013
    #11
  12. On 10/05/2013 20:02, Daniel Pitts allegedly wrote:
    > On 5/10/13 10:03 AM, Daniele Futtorovic wrote:
    >> On 10/05/2013 18:52, Daniel Pitts allegedly wrote:
    >>> 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.

    >
    > 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.

    --
    DF.
    Daniele Futtorovic, May 10, 2013
    #12
  13. RVic

    Arne Vajhøj Guest

    On 5/9/2013 10:41 PM, RVic wrote:
    > 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
    Arne Vajhøj, May 13, 2013
    #13
  14. RVic

    RVic Guest

    in <admin: head>
    RVic, May 13, 2013
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rukmal Fernando
    Replies:
    4
    Views:
    850
    Richard Grimes [MVP]
    Oct 27, 2003
  2. Matthias S.
    Replies:
    1
    Views:
    648
    Daniel Fisher\(lennybacon\)
    Nov 30, 2005
  3. Jiho Han
    Replies:
    0
    Views:
    516
    Jiho Han
    Aug 22, 2006
  4. =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=

    Adding my messages to the trace.axd trace?

    =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=, Apr 6, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    594
    =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=
    Apr 6, 2007
  5. Chris Newby
    Replies:
    0
    Views:
    768
    Chris Newby
    Jul 28, 2008
Loading...

Share This Page