}
throw e;
}
assert parser != null:"Could not find result parser";
Result result = null;
try {
result = parser.parse(cmd, entity.getContent(), expectedType);
} catch (IOException e) {
throw new SparqlException("Error reading response from server", e);
}
if (result == null) {
// Don't know how we got here, but parser should have returned a result or thrown an exception.
throw new IllegalStateException("Could not parse result from server response.");
}
// Should never happen because the result format should have been validated against the expected
// class when selecting the format to use for parsing, but check anyways.
if (expectedType != null && !expectedType.getResultClass().isInstance(result)) {
try {
result.close();
} catch (IOException e) {
logger.warn("Error closing result of incorrect type", e);
}
throw new IllegalStateException("Result parsed from server response (" +
result.getClass().getName() + ") does not match expected result type (" + expectedType + ")");
}
return result;
}