rvesse 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_r273371200
 
 

 ##########
 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:
   Random unrelated typo here if you feel like fixing it

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to