jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [4/5] jena git commit: JENA-1372: Improve error handling.
Date Sat, 19 Aug 2017 17:00:42 GMT
JENA-1372: Improve error handling.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/6b2b54fa
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/6b2b54fa
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/6b2b54fa

Branch: refs/heads/master
Commit: 6b2b54fa3199f239e42852592e17cce98b0d8557
Parents: 5a81057
Author: Andy Seaborne <andy@apache.org>
Authored: Fri Aug 18 16:52:16 2017 +0100
Committer: Andy Seaborne <andy@apache.org>
Committed: Fri Aug 18 16:52:16 2017 +0100

----------------------------------------------------------------------
 .../jena/sparql/function/library/FN_Apply.java  | 17 ++++++------
 .../function/library/TestFnFunctions.java       | 29 +++++++++++++++++---
 2 files changed, 34 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/6b2b54fa/jena-arq/src/main/java/org/apache/jena/sparql/function/library/FN_Apply.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/function/library/FN_Apply.java
b/jena-arq/src/main/java/org/apache/jena/sparql/function/library/FN_Apply.java
index 4f766fa..6539416 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/function/library/FN_Apply.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/function/library/FN_Apply.java
@@ -24,13 +24,13 @@ import org.apache.jena.atlas.lib.Cache ;
 import org.apache.jena.atlas.lib.CacheFactory ;
 import org.apache.jena.graph.Node ;
 import org.apache.jena.sparql.expr.ExprEvalException ;
+import org.apache.jena.sparql.expr.ExprException ;
 import org.apache.jena.sparql.expr.ExprList ;
 import org.apache.jena.sparql.expr.NodeValue ;
 import org.apache.jena.sparql.function.Function ;
 import org.apache.jena.sparql.function.FunctionBase ;
 import org.apache.jena.sparql.function.FunctionFactory ;
 import org.apache.jena.sparql.function.FunctionRegistry ;
-import org.apache.jena.sparql.sse.builders.ExprBuildException ;
 import org.apache.jena.sparql.util.Context ;
 
 /** XPath and XQuery Functions and Operators 3.1
@@ -44,28 +44,30 @@ public class FN_Apply extends FunctionBase {
     @Override
     public void checkBuild(String uri, ExprList args) {
         if ( args.isEmpty() )
-            throw new ExprBuildException("fn:apply: no function to call (minimum number of
args is one)");
+            throw new ExprException("fn:apply: no function to call (minimum number of args
is one)");
     }
     @Override
     public NodeValue exec(List<NodeValue> args) {
         if ( args.isEmpty() )
-            throw new ExprBuildException("fn:apply: no function to call (minimum number of
args is one)");
+            throw new ExprException("fn:apply: no function to call (minimum number of args
is one)");
         NodeValue functionId = args.get(0);
         List<NodeValue> argExprs = args.subList(1,args.size()) ; 
         ExprList exprs = new ExprList();
-        argExprs.forEach((a)->exprs.add(a));
+        argExprs.forEach(exprs::add);
         Node fnNode = functionId.asNode();
         
         if ( fnNode.isBlank() ) 
-            throw new ExprBuildException("fn:apply: function id is a blank node (must be
a URI)");        
+            throw new ExprEvalException("fn:apply: function id is a blank node (must be a
URI)");        
         if ( fnNode.isLiteral() )
-            throw new ExprBuildException("fn:apply: function id is a literal (must be a URI)");
+            throw new ExprEvalException("fn:apply: function id is a literal (must be a URI)");
         if ( fnNode.isVariable() )
             // Should not happen ... but ...
-            throw new ExprBuildException("fn:apply: function id is an unbound variable (must
be a URI)");
+            throw new ExprEvalException("fn:apply: function id is an unbound variable (must
be a URI)");
         if ( fnNode.isURI() ) {
             String functionIRI = fnNode.getURI();
             Function function = cache1.getOrFill(functionIRI, ()->buildFunction(functionIRI));
+            if ( function == null )
+                throw new ExprEvalException("fn:apply: Unknown function: <"+functionId+">");
             if ( function instanceof FunctionBase ) {
                 // Fast track.
                 return ((FunctionBase)function).exec(argExprs);
@@ -92,5 +94,4 @@ public class FN_Apply extends FunctionBase {
             registry = FunctionRegistry.get() ;
         return registry ;
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/jena/blob/6b2b54fa/jena-arq/src/test/java/org/apache/jena/sparql/function/library/TestFnFunctions.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/test/java/org/apache/jena/sparql/function/library/TestFnFunctions.java
b/jena-arq/src/test/java/org/apache/jena/sparql/function/library/TestFnFunctions.java
index 493f501..933f11c 100644
--- a/jena-arq/src/test/java/org/apache/jena/sparql/function/library/TestFnFunctions.java
+++ b/jena-arq/src/test/java/org/apache/jena/sparql/function/library/TestFnFunctions.java
@@ -21,8 +21,8 @@ package org.apache.jena.sparql.function.library;
 import static org.apache.jena.sparql.function.library.LibTest.test;
 
 import org.apache.jena.sparql.expr.ExprEvalException ;
+import org.apache.jena.sparql.expr.ExprException ;
 import org.apache.jena.sparql.expr.VariableNotBoundException ;
-import org.apache.jena.sparql.sse.builders.ExprBuildException ;
 import org.apache.jena.system.JenaSystem ;
 import org.junit.Test ;
 
@@ -34,20 +34,20 @@ public class TestFnFunctions {
         test("fn:apply(math:sqrt, 9)", "3.0e0");
     }
     
-    // Under arity
+    // Under-arity
     @Test(expected=ExprEvalException.class)
     public void apply_2() {
         test("fn:apply(math:sqrt)", "3.0e0");
     }
 
-    // Over arity
+    // Over-arity
     @Test(expected=ExprEvalException.class)
     public void apply_3() {
         test("fn:apply(math:sqrt, 9, 10)", "3.0e0");
     }
 
     // Not a URI.
-    @Test(expected=ExprBuildException.class)
+    @Test(expected=ExprEvalException.class)
     public void apply_4() {
         test("fn:apply('bicycle', 9, 10)", "3.0e0");
     }
@@ -57,8 +57,29 @@ public class TestFnFunctions {
         test("fn:apply(?var)", "3.0e0");
     }
     
+    @Test(expected=ExprEvalException.class)
+    public void apply_6() {
+        test("fn:apply(<x:unregistered>)", "false");
+    }
+
+    @Test(expected=ExprException.class)
+    public void apply_7() {
+        test("fn:apply()", "false");
+    }
+
     @Test
     public void collationKey_1() {
         test("fn:collation-key('foo', 'en') = 'Zm9vQGVu'^^xsd:base64Binary");
     }
+    
+    @Test(expected=ExprEvalException.class)
+    public void collationKey_2() {
+        test("fn:collation-key('foo', 22) = 'Zm9vQGVu'^^xsd:base64Binary");
+    }
+
+    @Test(expected=ExprEvalException.class)
+    public void collationKey_3() {
+        test("fn:collation-key(<x:bar>, 'en') = 'Zm9vQGVu'^^xsd:base64Binary");
+    }
+
 }


Mime
View raw message