[ 
https://issues.apache.org/jira/browse/JENA-2192?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17439212#comment-17439212
 ] 

Henry Kuijpers commented on JENA-2192:
--------------------------------------

Thanks for your feedback [~andy], I just created a ticket for the NPE that we 
encountered: https://issues.apache.org/jira/browse/JENA-2193 So let's deal with 
that in that ticket.

I agree that NPEs should not happen. However, in our case, the NPE did happen 
because the input document was incorrect. It was an XML document, but it 
probably wasn't complying exactly to the RDF standard. So, I'm not sure if our 
input was *so* incorrect, that the use-case falls outside of what JENA is 
generally expected to be able to handle. On the other hand, it is a form of 
input that can lead to an NPE and as you said (and I agree), it should be 
impossible for that to happen.

I guess that's where it comes to the discussion about checked vs unchecked 
exceptions. I do not agree with your view on this subject, but I think it's a 
very opinionated subject, so let's not do a deepdive into that discussion.

I think it all comes down to the following: How much of a "normal" situation is 
it, that parsing a document can result in an error? Is that really a 
programmer's mistake? Or is it something that could occur even if the 
programmer did just fine? Related to this, org.w3c classes do throw 
ParseException etc. 

> JENA's Model#read should throw checked exception(s) instead of 
> RuntimeException(s)
> ----------------------------------------------------------------------------------
>
>                 Key: JENA-2192
>                 URL: https://issues.apache.org/jira/browse/JENA-2192
>             Project: Apache Jena
>          Issue Type: Improvement
>          Components: Jena
>    Affects Versions: Jena 4.2.0
>            Reporter: Henry Kuijpers
>            Priority: Major
>
> We have noticed that, when parsing a document using JENA's Model#read, a) 
> there are no checked exceptions specified and b) when parsing fails, runtime 
> exceptions are thrown.
> This makes it a bit cumbersome to catch cases where parsing goes wrong. One 
> option is to wrap the statement in try/catch RuntimeException, however, this 
> doesn't seem to be a good practice (and Sonar complains to us about it).
> We've seen some cases:
> * Malformed XML (normal XML parsers would fail also)
> * NPEs (in case the RDF standard is not properly followed and/or elements are 
> pointing to unexisting items)
> I realize that adding a throws-declaration in the parse-method would be an 
> API change, but as long as that is put in the release notes and done with a 
> major version increase, I think that should be fine.
> WDYT?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to