#84 DefaultPrefixManager return empty localnames as "foaf:null"


DefaultPrefixManager gave me "foaf:null" for this code:

public void getPrefixIRIEmpty() throws Exception {
DefaultPrefixManager pm = new DefaultPrefixManager();
pm.setPrefix("foaf:", "http://xmlns.com/foaf/0.1/");
assertEquals("foaf:", pm.getPrefixIRI(IRI.create("http://xmlns.com/foaf/0.1/")));

This is not a valid result, it should either return "null" or "foaf:". This causes problems when importing the FOAF ontology, as in Turtle it gets serialised as

@prefix foaf: <http://xmlns.com/foaf/0.1/> .
# ..
owl:imports foaf:null .


  • Stian Soiland-Reyes

    (From mailing list:)

    I've investigated this bug, and it is caused by not doing a null-check on the result of XMLUtils.getNCNameSuffix()

    This seems to be used several places, often doing things like:

    localname = XMLUtils.getNCNameSuffix(iri);
    return prefix + ":" + localname;

    As long as getNCNameSuffix may return null, this can lead to undesirable outcomes.

    Some formats like Turtle do support an empty localname in these cases, but the getPrefixIRI is also used by formats that don't support it, like RDF/XML and the Manchester syntax. Therefore the safest bet is to just return null for those. these fixes also means that the prefix manager won't claim to be able to prefix URIs that would lead to invalid localnames either, like <http://example.com/123> or <http://example.com/test?>

    I have therefore prepared a patch set that fixes this:


    I based this on the master branch at git://owlapi.git.sourceforge.net/gitroot/owlapi/owlapi - but I guess you may cherrypick it into the other branches.

    You might notice that QNameShortFormProvider here throws an IllegalArgumentException. I know this is not ideal, but I think it is better than returning invalid results. QNameShortFormProvider seem to be mainly only used by OWLTutorialSyntaxObjectRenderer and a few test cases, so I don't think it's much to worry about.

    Feel free to use the patch, my work is technically (C) University of Manchester, but let me know if you want to use this and need me to sign any copyright assignment forms.

    Stian Soiland-Reyes, myGrid team
    School of Computer Science
    The University of Manchester

  • Ignazio Palmisano

    • assigned_to: nobody --> ignazio1977
    • status: open --> open-accepted
  • Ignazio Palmisano

    I have updated the code to deal with the above test. Other changes feel more like interface changes best left for next version. Thanks for the suggestions.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks