You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Marek Šabo (JIRA)" <ji...@apache.org> on 2010/11/23 19:03:22 UTC

[jira] Created: (CAY-1514) ClassCastException when EJQLQuery parameters is null.

ClassCastException when EJQLQuery parameters is null.
-----------------------------------------------------

                 Key: CAY-1514
                 URL: https://issues.apache.org/jira/browse/CAY-1514
             Project: Cayenne
          Issue Type: Bug
          Components: Core Library
    Affects Versions: 3.0.1
         Environment: Tomcat 6.0.26
            Reporter: Marek Šabo


When a parameter in EJBQLQuery is set to null, an error occurs which results in ClassCastException. When parameter is not null query is executed as expected.
It is duplicable with following/similar code:

        EJBQLQuery eq = new EJBQLQuery("SELECT COUNT(u) FROM User u WHERE u.username like :usernam AND u.userInfo.name like :userName");
        eq.setParameter("userName", null);
        eq.setParameter("usernam", "msabo");
        return (Long) DataObjectUtils.objectForQuery(getObjectContext(), eq);

Full stack trace is in attachment.

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


[jira] [Commented] (CAY-1514) ClassCastException when EJQLQuery parameters is null.

Posted by "Dzmitry Kazimirchyk (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1514?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13060093#comment-13060093 ] 

Dzmitry Kazimirchyk commented on CAY-1514:
------------------------------------------

This issue produces ClassCastException for 3.0.x (like in description) and produces NPE for 3.1 version. But the reason of this is the same I suppose.
Any NamedInputParameter according to the current grammar matches PatternValue. So when we use named input parameters in the query parser produces PatternValue object for them and we are getting ClassCastException trying to cast them into NamedInputParameter.
So I've changed parser grammar this way to avoid treating NamedInputParameters as PatternValues.

> ClassCastException when EJQLQuery parameters is null.
> -----------------------------------------------------
>
>                 Key: CAY-1514
>                 URL: https://issues.apache.org/jira/browse/CAY-1514
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Tomcat 6.0.26
>            Reporter: Marek Šabo
>         Attachments: cayST.txt, ejbql-null-parameters.patch, test.patch
>
>
> When a parameter in EJBQLQuery is set to null, an error occurs which results in ClassCastException. When parameter is not null query is executed as expected.
> It is duplicable with following/similar code:
>         EJBQLQuery eq = new EJBQLQuery("SELECT COUNT(u) FROM User u WHERE u.username like :usernam AND u.userInfo.name like :userName");
>         eq.setParameter("userName", null);
>         eq.setParameter("usernam", "msabo");
>         return (Long) DataObjectUtils.objectForQuery(getObjectContext(), eq);
> Full stack trace is in attachment.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Updated: (CAY-1514) ClassCastException when EJQLQuery parameters is null.

Posted by "Marek Šabo (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAY-1514?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Marek Šabo updated CAY-1514:
----------------------------

    Attachment: cayST.txt

Full stack trace of thrown exception.

> ClassCastException when EJQLQuery parameters is null.
> -----------------------------------------------------
>
>                 Key: CAY-1514
>                 URL: https://issues.apache.org/jira/browse/CAY-1514
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Tomcat 6.0.26
>            Reporter: Marek Šabo
>         Attachments: cayST.txt
>
>
> When a parameter in EJBQLQuery is set to null, an error occurs which results in ClassCastException. When parameter is not null query is executed as expected.
> It is duplicable with following/similar code:
>         EJBQLQuery eq = new EJBQLQuery("SELECT COUNT(u) FROM User u WHERE u.username like :usernam AND u.userInfo.name like :userName");
>         eq.setParameter("userName", null);
>         eq.setParameter("usernam", "msabo");
>         return (Long) DataObjectUtils.objectForQuery(getObjectContext(), eq);
> Full stack trace is in attachment.

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


[jira] [Closed] (CAY-1514) ClassCastException when EJQLQuery parameters is null.

Posted by "Andrus Adamchik (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAY-1514?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andrus Adamchik closed CAY-1514.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 3.1M3
                   3.0.3

> ClassCastException when EJQLQuery parameters is null.
> -----------------------------------------------------
>
>                 Key: CAY-1514
>                 URL: https://issues.apache.org/jira/browse/CAY-1514
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Tomcat 6.0.26
>            Reporter: Marek Šabo
>             Fix For: 3.0.3, 3.1M3
>
>         Attachments: cayST.txt, ejbql-null-parameters.patch, test.patch
>
>
> When a parameter in EJBQLQuery is set to null, an error occurs which results in ClassCastException. When parameter is not null query is executed as expected.
> It is duplicable with following/similar code:
>         EJBQLQuery eq = new EJBQLQuery("SELECT COUNT(u) FROM User u WHERE u.username like :usernam AND u.userInfo.name like :userName");
>         eq.setParameter("userName", null);
>         eq.setParameter("usernam", "msabo");
>         return (Long) DataObjectUtils.objectForQuery(getObjectContext(), eq);
> Full stack trace is in attachment.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Commented] (CAY-1514) ClassCastException when EJQLQuery parameters is null.

Posted by "Andrus Adamchik (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1514?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13060050#comment-13060050 ] 

Andrus Adamchik commented on CAY-1514:
--------------------------------------

The test case demonstrates a problem, albeit it seems to be a different one (NPE vs. ClassCastException) :

Caused by: java.lang.NullPointerException
	at org.apache.cayenne.access.jdbc.EJBQLPathTranslator.processLastPathComponent(EJBQLPathTranslator.java:190)
	at org.apache.cayenne.access.jdbc.EJBQLPathAnaliserTranslator.visitPath(EJBQLConditionTranslator.java:1181)
	at org.apache.cayenne.access.jdbc.EJBQLConditionTranslator.processParameter(EJBQLConditionTranslator.java:852)
	at org.apache.cayenne.access.jdbc.EJBQLConditionTranslator.visitPositionalInputParameter(EJBQLConditionTranslator.java:773)
	at org.apache.cayenne.ejbql.parser.EJBQLPositionalInputParameter.visitNode(EJBQLPositionalInputParameter.java:34)

I wonder if we have 2 separate problems at hand, and need an extra test case to reproduce the one described by the Jira reporter. One difference with the test case (that may or may not be relevant) is that path matched against NULL is multi-part, traversing the relationship. 

Re: .jjt patch: I am confused about the assymetry between these 2 chunks:

@@ -693,7 +693,8 @@ void literal_or_param() : { }
 
 void like_expression() #Like : { }
 {
-	string_expression() [<NOT> { jjtThis.not = true; }] <LIKE> pattern_value() 
+	string_expression() [<NOT> { jjtThis.not = true; }] <LIKE> 
+	((input_parameter() [(<ESCAPE> escape_character())]) | pattern_value())  
 }
 
and

@ -1208,8 +1209,7 @@ void positional_input_parameter() #PositionalInputParameter :
 
 void pattern_value() #PatternValue : { }
 {
-	(input_parameter() | string_literal())
-	[(<ESCAPE> escape_character())]
+	string_literal() [(<ESCAPE> escape_character())]
 }

Could you explain the fix?


> ClassCastException when EJQLQuery parameters is null.
> -----------------------------------------------------
>
>                 Key: CAY-1514
>                 URL: https://issues.apache.org/jira/browse/CAY-1514
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Tomcat 6.0.26
>            Reporter: Marek Šabo
>         Attachments: cayST.txt, ejbql-null-parameters.patch, test.patch
>
>
> When a parameter in EJBQLQuery is set to null, an error occurs which results in ClassCastException. When parameter is not null query is executed as expected.
> It is duplicable with following/similar code:
>         EJBQLQuery eq = new EJBQLQuery("SELECT COUNT(u) FROM User u WHERE u.username like :usernam AND u.userInfo.name like :userName");
>         eq.setParameter("userName", null);
>         eq.setParameter("usernam", "msabo");
>         return (Long) DataObjectUtils.objectForQuery(getObjectContext(), eq);
> Full stack trace is in attachment.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] Commented: (CAY-1514) ClassCastException when EJQLQuery parameters is null.

Posted by "Ksenia Khailenko (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1514?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12935062#action_12935062 ] 

Ksenia Khailenko commented on CAY-1514:
---------------------------------------

That is because when EJBQLConditionsTranslator processes the NamedParameter and sees the null value, it expects to see "equals" condition, not "like": EJBQLConditionsTranslator [838-844]

> ClassCastException when EJQLQuery parameters is null.
> -----------------------------------------------------
>
>                 Key: CAY-1514
>                 URL: https://issues.apache.org/jira/browse/CAY-1514
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Tomcat 6.0.26
>            Reporter: Marek Šabo
>         Attachments: cayST.txt
>
>
> When a parameter in EJBQLQuery is set to null, an error occurs which results in ClassCastException. When parameter is not null query is executed as expected.
> It is duplicable with following/similar code:
>         EJBQLQuery eq = new EJBQLQuery("SELECT COUNT(u) FROM User u WHERE u.username like :usernam AND u.userInfo.name like :userName");
>         eq.setParameter("userName", null);
>         eq.setParameter("usernam", "msabo");
>         return (Long) DataObjectUtils.objectForQuery(getObjectContext(), eq);
> Full stack trace is in attachment.

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


[jira] [Commented] (CAY-1514) ClassCastException when EJQLQuery parameters is null.

Posted by "Andrus Adamchik (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1514?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13060320#comment-13060320 ] 

Andrus Adamchik commented on CAY-1514:
--------------------------------------

Sorry couldn't think clearly last night. Thanks for the explanation. It makes sense. Now I finally recall why it didn't work in the first place - JPA spec that was used for the original EJBQL grammar does not support input parameters in the LIKE expression, and is vague on null handling ("If the value of the string_expression or pattern_value is NULL or unknown, the value of the LIKE expression is unknown.")... Now we are departing from it in these edge cases.

> ClassCastException when EJQLQuery parameters is null.
> -----------------------------------------------------
>
>                 Key: CAY-1514
>                 URL: https://issues.apache.org/jira/browse/CAY-1514
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Tomcat 6.0.26
>            Reporter: Marek Šabo
>         Attachments: cayST.txt, ejbql-null-parameters.patch, test.patch
>
>
> When a parameter in EJBQLQuery is set to null, an error occurs which results in ClassCastException. When parameter is not null query is executed as expected.
> It is duplicable with following/similar code:
>         EJBQLQuery eq = new EJBQLQuery("SELECT COUNT(u) FROM User u WHERE u.username like :usernam AND u.userInfo.name like :userName");
>         eq.setParameter("userName", null);
>         eq.setParameter("usernam", "msabo");
>         return (Long) DataObjectUtils.objectForQuery(getObjectContext(), eq);
> Full stack trace is in attachment.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

[jira] [Updated] (CAY-1514) ClassCastException when EJQLQuery parameters is null.

Posted by "Dzmitry Kazimirchyk (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAY-1514?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dzmitry Kazimirchyk updated CAY-1514:
-------------------------------------

    Attachment: ejbql-null-parameters.patch
                test.patch

LIKE expression's parameters are always parsed into PatternValue objects which I think is the reason of the issue.
I suppose we can change grammar for parser generator to fix this.
I've added unit test and patch for trunk, for 3.0 branch it works the same way.

> ClassCastException when EJQLQuery parameters is null.
> -----------------------------------------------------
>
>                 Key: CAY-1514
>                 URL: https://issues.apache.org/jira/browse/CAY-1514
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0.1
>         Environment: Tomcat 6.0.26
>            Reporter: Marek Šabo
>         Attachments: cayST.txt, ejbql-null-parameters.patch, test.patch
>
>
> When a parameter in EJBQLQuery is set to null, an error occurs which results in ClassCastException. When parameter is not null query is executed as expected.
> It is duplicable with following/similar code:
>         EJBQLQuery eq = new EJBQLQuery("SELECT COUNT(u) FROM User u WHERE u.username like :usernam AND u.userInfo.name like :userName");
>         eq.setParameter("userName", null);
>         eq.setParameter("usernam", "msabo");
>         return (Long) DataObjectUtils.objectForQuery(getObjectContext(), eq);
> Full stack trace is in attachment.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira