Persistent ClassCastExceptions using QueryResultWriters.write

We're having persistent (but not necessarily consistent) ClassCastExceptions in our Java JBoss application when trying to write query results to a byte stream.

The trace is :

Unhandled exception from service: java.lang.ClassCastException: Cannot cast to
	at java.lang.Class.cast(
	.... (our code line here)

The calls are generally of the form :

ByteArrayOutputStream os = new ByteArrayOutputStream();
QueryResultFormat format = QueryResultFormats.forMime("application/sparql-results+json");
SelectQuery squery = query ...);
SelectQueryResult result = squery.execute();
QueryResultWriters.write(result, os, format.get());
String outResult = new String(os.toByteArray(), Charsets.UTF_8);

outResult is then returned in the HTTP Response with the correct MIME type encoding back to the calling RESTful client.

Similar code is used in a few methods and once the error occurs then all executions of this type of code throws the exception.

The queries are fairly simple "SELECT" queries that return mostly text values that have worked for the last year or so.
The exceptions have only started since we've upgraded the Stardog server to 7.0.2.

Sometimes restarting the JBoss server (occasionally a few times might be required) will "clear" the error, but it often soon reappears.
Restarting the Stardog server has no effect.
There are no server errors logged to stardog.log.

We know that queries are working - other methods that run queries but don't use QueryResultWriters (ie build a bespoke result using .hasNext() ) work as expected.

Any thoughts on resolving this would be very much appreciated!


Hi Chris,

It looks like this call is the problem:


This may return either SELECT or ASK formats. I'll bring this up internally but in the meantime you can use the constant QueryResultFormats.JSON which is the SELECT format.


Thanks Jess, I'll give that a try.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.