You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by GitBox <gi...@apache.org> on 2019/04/09 10:08:31 UTC

[GitHub] [jena] afs commented on a change in pull request #553: JENA-1701: Print an error on bad URI string

afs commented on a change in pull request #553: JENA-1701: Print an error on bad URI string
URL: https://github.com/apache/jena/pull/553#discussion_r273418464
 
 

 ##########
 File path: jena-arq/src/main/java/org/apache/jena/sparql/expr/nodevalue/NodeFunctions.java
 ##########
 @@ -421,18 +421,30 @@ public static Node iri(Node n, String baseIRI) {
 
         if ( !iri.isAbsolute() )
             throw new ExprEvalException("Relative IRI string: " + iriStr) ;
-        if ( warningsForIRIs && iri.hasViolation(false) ) {
-            String msg = "unknown violation from IRI library" ;
-            Iterator<Violation> iter = iri.violations(false) ;
-            if ( iter.hasNext() ) {
-                Violation viol = iter.next() ;
-                msg = viol.getShortMessage() ;
+        
+        String msg = getOneViolation(iri, false);
+        if ( msg != null ) {
+            msg = "Bad IRI: " + msg + ": " + iri;
+            Log.error(NodeFunctions.class, msg);
+            //throw new ExprEvalException(msg);
+        } else {
+            if ( warningsForIRIs && iri.hasViolation(false) ) {
+                msg = getOneViolation(iri, true);
+                if ( msg != null )
+                    Log.warn(NodeFunctions.class, "Bad IRI: " + msg + ": " + iri) ;
             }
-            Log.warn(NodeFunctions.class, "Bad IRI: " + msg + ": " + iri) ;
         }
         return NodeFactory.createURI(iri.toString()) ;
     }
 
+    private static String getOneViolation(IRI iri, boolean includeWarnings) {
+        Iterator<Violation> iter = iri.violations(includeWarnings);
+        if ( ! iter.hasNext() )
+            return null; 
+        Violation viol = iter.next() ;
+        return viol.getShortMessage() ;
+    }
+
     // The Jena version can be slow to inityailise (but is pure java)
 
 Review comment:
   Yes - I've removed the whole comment and commented code.  It is not true nowadays because Java got better at what was the slow point of initialization.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services