Unbalanced # in SQL causes unclear/misleading error message
-----------------------------------------------------------

                 Key: IBATIS-389
                 URL: https://issues.apache.org/jira/browse/IBATIS-389
             Project: iBatis for Java
          Issue Type: Bug
          Components: SQL Maps
    Affects Versions: 2.2.0
            Reporter: Jamison


Below is the stack trace for in exception caused by an unbalanced # in an 
insert statement. The "Error parsing XPath 'blah'" message does not give nearly 
as much information as the parser has available at the time and does not even 
indicate the source of the problem. I have traced the issue back to the use of 
StringTokenizer in InlineParameterMapParser, if this class was changed 
slightly, to catch NoSuchElementException and rethrow SqlMapException with a 
message like "Failed to parse statement [xpath] with id [statement id], check 
inline parameters" or even "Failed to parse SQL in [statement id]" finding the 
problem would be almost effortless. All it needs is a big try-catch block 
around the whole method body.
This code appears to be an failed effort to do this, StringTokenizer picks up 
the sntax error before this:
if (!PARAMETER_TOKEN.equals(token)) {
  throw new SqlMapException("Unterminated inline parameter in mapped statement 
(" + "statement.getId()" + ").");
}

I just lost a good hour trying to find the source of one of these problems, I 
traced the iBatis code to figure out where a NoSuchElementEx _could_ be thrown 
to figure out what would be wrong after 20 minutes of reading my XML/SQL. 
Calling the bug major might seem a bit melodramatic, but I think it is 
important that this gets out in a maint. release soon.

--
Error occurred.  Cause: com.ibatis.common.xml.NodeletException: Error parsing 
XML.  Cause: com.ibatis.common.exception.NestedRuntimeException: Error parsing 
XPath '/sqlMapConfig/sqlMap'.  Cause: com.ibatis.common.xml.NodeletException: 
Error parsing XML.  Cause: com.ibatis.common.exception.NestedRuntimeException: 
Error parsing XPath '/sqlMap/insert'.  Cause: java.util.NoSuchElementException
Caused by: java.util.NoSuchElementException
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error parsing 
XPath '/sqlMap/insert'.  Cause: java.util.NoSuchElementException
Caused by: java.util.NoSuchElementException
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: 
com.ibatis.common.exception.NestedRuntimeException: Error parsing XPath 
'/sqlMap/insert'.  Cause: java.util.NoSuchElementException
Caused by: java.util.NoSuchElementException
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error parsing 
XPath '/sqlMap/insert'.  Cause: java.util.NoSuchElementException
Caused by: java.util.NoSuchElementException
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error parsing 
XPath '/sqlMapConfig/sqlMap'.  Cause: com.ibatis.common.xml.NodeletException: 
Error parsing XML.  Cause: com.ibatis.common.exception.NestedRuntimeException: 
Error parsing XPath '/sqlMap/insert'.  Cause: java.util.NoSuchElementException
Caused by: java.util.NoSuchElementException
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error parsing 
XPath '/sqlMap/insert'.  Cause: java.util.NoSuchElementException
Caused by: java.util.NoSuchElementException
Caused by: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: 
com.ibatis.common.exception.NestedRuntimeException: Error parsing XPath 
'/sqlMap/insert'.  Cause: java.util.NoSuchElementException
Caused by: java.util.NoSuchElementException
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error parsing 
XPath '/sqlMap/insert'.  Cause: java.util.NoSuchElementException
Caused by: java.util.NoSuchElementException
        
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
        
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to