Results parsers must work without handlers

Description

The follow throws a NPE. However, a QueryResultParseException is expected.

ByteArrayOutputStream out = new ByteArrayOutputStream();
TupleQueryResult tqr = new TupleQueryResultImpl(Arrays.asList("x"), Collections.<BindingSet>emptyList());
QueryResultIO.write(tqr, TupleQueryResultFormat.SPARQL, out);

ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
QueryResultIO.createParser(getBooleanFormat()).parse(in);

Environment

None

Activity

Show:
Peter Ansell
June 22, 2013, 5:09 AM

Some (most?/all?) other parsers work without handlers. Ie, they function as verifiers only. So in that respect it is an issue.

However, I may be missing something but I don't immediately see why that code would create unparsable SPARQL Results XML as it is fairly standard to have empty results sets and the format supports them explicitly with an empty results tag.

Peter Ansell
June 23, 2013, 4:40 AM

I think part of the confusion may be that there is no functional distinction between Tuple and Boolean results parsers for either SPARQL Results XML or SPARQL Results JSON, since 2.7.0. Ie, they both work on the same results.

The fact that there was a NullPointerException is an issue and it can be fixed without switching off verification for Tuple results if there is no handler specified. The reason that the error does not appear in the compliance tests is that the compliance tests all use QueryResultIO.parse which sets a handler internally. The workaround for this until 2.7.3 is released, then seems to be, to use QueryResultIO.parse to attempt to parse boolean results.

I have added a test that explicitly does not set any handler as regression tests for the NPE and added a test that explicitly tests for parsing a tuple results set using the deprecated boolean parse method.

Assignee

Peter Ansell

Reporter

James Leigh

Labels

None

Components

Fix versions

Affects versions

Priority

Minor
Configure