[hibernate-commits] Hibernate SVN: r20707 - in core/trunk: testsuite/src/test/java/org/hibernate/test/hql and 1 other directory.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Sat Sep 25 12:27:10 EDT 2010


Author: steve.ebersole at jboss.com
Date: 2010-09-25 12:27:09 -0400 (Sat, 25 Sep 2010)
New Revision: 20707

Modified:
   core/trunk/core/src/main/antlr/hql-sql.g
   core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
Log:
HHH-2917 - Using subselects as operands for arithmetic operations causes NullPointerException


Modified: core/trunk/core/src/main/antlr/hql-sql.g
===================================================================
--- core/trunk/core/src/main/antlr/hql-sql.g	2010-09-25 15:47:57 UTC (rev 20706)
+++ core/trunk/core/src/main/antlr/hql-sql.g	2010-09-25 16:27:09 UTC (rev 20707)
@@ -579,11 +579,11 @@
 	;
 
 arithmeticExpr
-	: #(PLUS expr expr)         { prepareArithmeticOperator( #arithmeticExpr ); }
-	| #(MINUS expr expr)        { prepareArithmeticOperator( #arithmeticExpr ); }
-	| #(DIV expr expr)          { prepareArithmeticOperator( #arithmeticExpr ); }
-	| #(MOD expr expr)          { prepareArithmeticOperator( #arithmeticExpr ); }
-	| #(STAR expr expr)         { prepareArithmeticOperator( #arithmeticExpr ); }
+    : #(PLUS exprOrSubquery exprOrSubquery)         { prepareArithmeticOperator( #arithmeticExpr ); }
+    | #(MINUS exprOrSubquery exprOrSubquery)        { prepareArithmeticOperator( #arithmeticExpr ); }
+    | #(DIV exprOrSubquery exprOrSubquery)          { prepareArithmeticOperator( #arithmeticExpr ); }
+    | #(MOD exprOrSubquery exprOrSubquery)          { prepareArithmeticOperator( #arithmeticExpr ); }
+    | #(STAR exprOrSubquery exprOrSubquery)         { prepareArithmeticOperator( #arithmeticExpr ); }
 //	| #(CONCAT expr (expr)+ )   { prepareArithmeticOperator( #arithmeticExpr ); }
 	| #(UNARY_MINUS expr)       { prepareArithmeticOperator( #arithmeticExpr ); }
 	| caseExpr

Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java	2010-09-25 15:47:57 UTC (rev 20706)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java	2010-09-25 16:27:09 UTC (rev 20707)
@@ -110,6 +110,24 @@
 		return new FunctionalTestClassTestSuite( ASTParserLoadingTest.class );
 	}
 
+	public void testSubSelectAsArtithmeticOperand() {
+		Session s = openSession();
+		s.beginTransaction();
+
+		// first a control
+		s.createQuery( "from Zoo z where ( select count(*) from Zoo ) = 0" ).list();
+
+		// now as operands singly:
+		s.createQuery( "from Zoo z where ( select count(*) from Zoo ) + 0 = 0" ).list();
+		s.createQuery( "from Zoo z where 0 + ( select count(*) from Zoo ) = 0" ).list();
+
+		// and doubly:
+		s.createQuery( "from Zoo z where ( select count(*) from Zoo ) + ( select count(*) from Zoo ) = 0" ).list();
+
+		s.getTransaction().commit();
+		s.close();
+	}
+
 	public void testJpaTypeOperator() {
 		// just checking syntax here...
 		Session s = openSession();



More information about the hibernate-commits mailing list