You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2017/11/10 16:06:46 UTC

[4/6] cayenne git commit: CAY-1969 Malformed EJBQL Yields NPE

CAY-1969 Malformed EJBQL Yields NPE


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/9c66242a
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/9c66242a
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/9c66242a

Branch: refs/heads/STABLE-3.1
Commit: 9c66242a1a999dfca0aa62e394db73caa4e47b9b
Parents: 37faf1d
Author: Nikita Timofeev <st...@gmail.com>
Authored: Fri Nov 10 15:45:11 2017 +0300
Committer: Nikita Timofeev <st...@gmail.com>
Committed: Fri Nov 10 15:45:11 2017 +0300

----------------------------------------------------------------------
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |  1 +
 .../apache/cayenne/ejbql/parser/Compiler.java   |  3 +++
 .../ejbql/EJBQLCompiledExpressionTest.java      | 21 ++++++++++++++++++++
 3 files changed, 25 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/9c66242a/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index 569ece0..a8966e5 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -14,6 +14,7 @@ Date: not yet released
 
 Bug Fixes Since 3.1.1:
 
+CAY-1969 Malformed EJBQL Yields NPE
 CAY-2084 ObjectIdQuery - no cache access polymorphism
 CAY-2101 DataContext.currentSnapshot() doesn't set snapshot entity name
 CAY-2137 When generating SQL from EJBQL, use "AND" to separate multiple join conditions

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9c66242a/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java
----------------------------------------------------------------------
diff --git a/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java b/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java
index 30f8189..7d37b80 100644
--- a/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java
+++ b/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java
@@ -312,6 +312,9 @@ class Compiler {
         if (descriptor == null) {
             descriptor = descriptorsById.get(expression.getText());
         }
+        if(descriptor == null) {
+            throw new EJBQLException("the entity variable '" + id +"' does not refer to any entity in the FROM clause");
+        }
         final EntityResult entityResult = new EntityResult(descriptor.getObjectClass());
         final String prefix = "ec" + position + "_";
         final int[] index = {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/9c66242a/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/ejbql/EJBQLCompiledExpressionTest.java
----------------------------------------------------------------------
diff --git a/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/ejbql/EJBQLCompiledExpressionTest.java b/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/ejbql/EJBQLCompiledExpressionTest.java
index 82f6392..0dcea40 100644
--- a/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/ejbql/EJBQLCompiledExpressionTest.java
+++ b/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/ejbql/EJBQLCompiledExpressionTest.java
@@ -140,4 +140,25 @@ public class EJBQLCompiledExpressionTest extends ServerCase {
         assertNotNull(select2.getEntityDescriptor("PaInTinGAlIaS"));
     }
 
+    /**
+     * <p>If an expression has an 'entity variable' used in the SELECT clause then there should be a
+     * corresponding definition for the 'entity variable' in the FROM clause.  This did, at some
+     * point throw an NPE.</p>
+     */
+    public void testMissingEntityBeanVariable() {
+        String ejbql = "SELECT b FROM Artist a";
+        EJBQLQuery query = new EJBQLQuery(ejbql);
+
+        try {
+            runtime.getContext().performQuery(query);
+            fail("expected an instance of " + EJBQLException.class.getSimpleName() + " to have been thrown.");
+        }
+        catch(EJBQLException e) {
+            assertEquals("the entity variable 'b' does not refer to any entity in the FROM clause", e.getUnlabeledMessage());
+        }
+        catch(Throwable th) {
+            fail("expected an instance of " + EJBQLException.class.getSimpleName() + " to have been thrown.");
+        }
+    }
+
 }