Garret Wilson created JEXL-340:
----------------------------------

             Summary: JexlException message access is incomplete and reversed
                 Key: JEXL-340
                 URL: https://issues.apache.org/jira/browse/JEXL-340
             Project: Commons JEXL
          Issue Type: Improvement
    Affects Versions: 3.1
            Reporter: Garret Wilson


I need to wrap {{JexlException}} and provide a nice error message to the user. 
If I have an expression using a variable {{foobar}} not present in the context, 
here is what {{JexlException.getMessage()}} returns:

{quote}io.guise.mesh.JexlMexlEvaluator.evaluate@1:1 undefined variable 
foobar{quote}

This is not a pretty error message. It has lots of things a user doesn't care 
about. I just want the real error message:

{quote}undefined variable foobar{quote}

But there is no way to get just that simple error message from 
{{JexlException}}. If you look at the source code for 
{{JexlException.getMessage()}}, you'll see that the "simple" message comes from 
{{JexlException.detailedMessage()}}.

Unfortunately {{JexlException.detailedMessage()}} is {{protected}}—there is no 
way to access it from outside. Moreover the semantics of "message" and 
"detailed message" are reversed! The "message" should provide fewer details 
than the "detailed message".

Here is what should be done:

* {{JexlException.getMessage()}} should provide what {{detailedMessage()}} 
provides now. (You'll note that {{detailedMessage()}} already calls 
{{super.getMessage()}}; this criss-cross overriding is not the best practice. 
My suggestion would therefore improve and even reduce the code.)
* A new {{JexlException.getDetailedMessage()}} should provide what 
{{getMessage()}} provides now.

That would be simpler and more correct. And it would give me the simpler error 
message I need.

It's not apparent to me why the current roundabout implementation was used to 
begin with, or what benefit it brings.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to