Uploaded image for project: 'Apache Jena'
  1. Apache Jena
  2. JENA-489

error message for builtin with wrong number of args is wrong

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • Jena 2.10.0
    • Jena 2.11.0
    • Jena
    • None

    Description

      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:

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

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

              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);
              }
      

      Code that demonstates the misleading message follows:

      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" );
      	}
      }
      

      This throws an exception with a misleading message:

      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)
      

      Attachments

        Activity

          People

            andy Andy Seaborne
            taylorj Joshua Taylor
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 0.05h
                0.05h
                Remaining:
                Remaining Estimate - 0.05h
                0.05h
                Logged:
                Time Spent - Not Specified
                Not Specified