Joshua Taylor created JENA-489:
----------------------------------

             Summary: error message for builtin with wrong number of args is 
wrong
                 Key: JENA-489
                 URL: https://issues.apache.org/jira/browse/JENA-489
             Project: Apache Jena
          Issue Type: Bug
          Components: Jena
    Affects Versions: Jena 2.10.0
            Reporter: Joshua Taylor
            Priority: Trivial
             Fix For: Jena 2.10.2


The message for a syntax error in the rule parser when a builtin is used in a 
backwards rule with the wrong number of arguments is wrong.  The message is 
generated in emitBody(Functor functor) in RuleClauseCode by these lines:

{noformat}
                throw new LPRuleSyntaxException("Wrong number of arguments to 
functor " + functor.getName() 
                                                  + " expected " + 
functor.getArgLength(), rule);
{noformat}


Instead of functor.getArgLength() should be builtin.getArgLength(). In context 
these are:

{noformat}
        void emitBody(Functor functor) {
            Node[] fargs = functor.getArgs();
            Builtin builtin = functor.getImplementor();
            if (builtin == null) {
                throw new LPRuleSyntaxException("Unknown builtin operation " + 
functor.getName(), rule);
            }
            if (builtin.getArgLength() != 0 && builtin.getArgLength() != 
fargs.length) {
                throw new LPRuleSyntaxException("Wrong number of arguments to 
functor " + functor.getName() 
                                                  + " expected " + 
functor.getArgLength(), rule);
            }
            for (int i = 0; i < fargs.length; i++) {
                Node node = fargs[i];
                // We optionally force an eager dereference of variables here.
                // We used to force this but the current builtin implementations
                // now robust against it (the do a deref themselves anyway).
                 emitBodyPut(node, i, true);
            }
            code[p++] = CALL_BUILTIN;
            code[p++] = (byte)fargs.length;
            args.add(builtin);
        }
{noformat}

Code that demonstates the misleading message follows:

{noformat}
import com.hp.hpl.jena.rdf.model.InfModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
import com.hp.hpl.jena.reasoner.rulesys.Rule;
import com.hp.hpl.jena.reasoner.rulesys.builtins.Sum;
import com.hp.hpl.jena.vocabulary.RDF;

public class JenaBuiltinErrorMessageExample {
        static String rules = "" +
                        "[(?x thriceValue ?vvv) <-\n" +
                        " (?x rdf:value ?v)\n" +
                        " sum(?v,?v,?v,?vvv)]\n" +
                        "";
        Sum sum;
        public static void main( String[] args ) {
                GenericRuleReasoner reasoner = new GenericRuleReasoner( 
Rule.parseRules( rules ));
                Model base = ModelFactory.createDefaultModel();
                base.createResource().addLiteral( RDF.value, 10 );
                InfModel inf = ModelFactory.createInfModel( reasoner, base );
                inf.write( System.out, "N3" );
        }
}
{noformat}

This throws an exception with a misleading message:

{noformat}
Exception in thread "main" 
com.hp.hpl.jena.reasoner.rulesys.impl.LPRuleSyntaxException: Syntax error in 
backward rule: [ (?x thriceValue ?vvv) <- (?x rdf:value ?v) sum(?v ?v ?v ?vvv) ]
Wrong number of arguments to functor sum expected 4
        at 
com.hp.hpl.jena.reasoner.rulesys.impl.RuleClauseCode$CompileState.emitBody(RuleClauseCode.java:607)
        at 
com.hp.hpl.jena.reasoner.rulesys.impl.RuleClauseCode.compile(RuleClauseCode.java:213)
        at 
com.hp.hpl.jena.reasoner.rulesys.impl.LPRuleStore.compileAll(LPRuleStore.java:249)
        at 
com.hp.hpl.jena.reasoner.rulesys.impl.LPRuleStore.codeFor(LPRuleStore.java:99)
        at 
com.hp.hpl.jena.reasoner.rulesys.impl.LPRuleStore.codeFor(LPRuleStore.java:119)
        at 
com.hp.hpl.jena.reasoner.rulesys.impl.LPInterpreter.<init>(LPInterpreter.java:91)
        at 
com.hp.hpl.jena.reasoner.rulesys.impl.LPBRuleEngine.find(LPBRuleEngine.java:109)
        at 
com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph.findWithContinuation(FBRuleInfGraph.java:575)
        at 
com.hp.hpl.jena.reasoner.rulesys.FBRuleInfGraph.graphBaseFind(FBRuleInfGraph.java:606)
        at 
com.hp.hpl.jena.reasoner.BaseInfGraph.graphBaseFind(BaseInfGraph.java:370)
        at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:266)
        at 
com.hp.hpl.jena.graph.compose.DisjointUnion.graphBaseFind(DisjointUnion.java:39)
        at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:266)
        at 
com.hp.hpl.jena.graph.impl.GraphBase.graphBaseFind(GraphBase.java:287)
        at com.hp.hpl.jena.graph.impl.GraphBase.find(GraphBase.java:284)
        at 
com.hp.hpl.jena.rdf.model.impl.ModelCom.listStatements(ModelCom.java:449)
        at 
com.hp.hpl.jena.rdf.model.impl.ModelCom.listStatements(ModelCom.java:455)
        at 
com.hp.hpl.jena.n3.N3JenaWriterPP.prepareLists(N3JenaWriterPP.java:81)
        at com.hp.hpl.jena.n3.N3JenaWriterPP.prepare(N3JenaWriterPP.java:67)
        at 
com.hp.hpl.jena.n3.N3JenaWriterCommon.processModel(N3JenaWriterCommon.java:275)
        at 
com.hp.hpl.jena.n3.N3JenaWriterCommon.write(N3JenaWriterCommon.java:197)
        at 
com.hp.hpl.jena.n3.N3JenaWriterCommon.write(N3JenaWriterCommon.java:209)
        at com.hp.hpl.jena.n3.N3JenaWriter.write(N3JenaWriter.java:171)
        at com.hp.hpl.jena.rdf.model.impl.ModelCom.write(ModelCom.java:327)
        at 
JenaBuiltinErrorMessageExample.main(JenaBuiltinErrorMessageExample.java:20)
{noformat}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to