You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by rv...@apache.org on 2015/01/14 11:32:31 UTC

[89/93] [abbrv] jena git commit: JENA-846 : retain maximum compatibility for checked exceptions.

JENA-846 : retain maximum compatibility for checked exceptions.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/2941cf75
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/2941cf75
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/2941cf75

Branch: refs/heads/hadoop-rdf
Commit: 2941cf75412e8ddb75f18aad8b6673b73737cf51
Parents: 067e099
Author: Andy Seaborne <an...@apache.org>
Authored: Mon Jan 12 20:18:36 2015 +0000
Committer: Andy Seaborne <an...@apache.org>
Committed: Mon Jan 12 20:18:36 2015 +0000

----------------------------------------------------------------------
 .../src/main/java/org/apache/jena/iri/IRI.java  |  4 ++-
 .../org/apache/jena/iri/impl/AbsIRIImpl.java    | 27 +++++++++++++-------
 2 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/2941cf75/jena-iri/src/main/java/org/apache/jena/iri/IRI.java
----------------------------------------------------------------------
diff --git a/jena-iri/src/main/java/org/apache/jena/iri/IRI.java b/jena-iri/src/main/java/org/apache/jena/iri/IRI.java
index 8fbe519..209803f 100644
--- a/jena-iri/src/main/java/org/apache/jena/iri/IRI.java
+++ b/jena-iri/src/main/java/org/apache/jena/iri/IRI.java
@@ -20,6 +20,7 @@ package org.apache.jena.iri;
 
 import java.net.MalformedURLException ;
 import java.net.URI ;
+import java.net.URISyntaxException ;
 import java.net.URL ;
 import java.util.Iterator ;
 
@@ -410,8 +411,9 @@ abstract public class IRI  extends AbsIRIFactoryImpl implements IRIFactoryI, IRI
      * Converts the IRI to an ASCII string, and then to a java.net.URI.
      * 
      * @return a URL corresponding to this IRI.
+     * @throws URISyntaxException If IDNA conversion failed.
      */
-    abstract public URI toURI() ;
+    abstract public URI toURI() throws URISyntaxException ;
 
     /**
      * Resolves an IRI against this one.

http://git-wip-us.apache.org/repos/asf/jena/blob/2941cf75/jena-iri/src/main/java/org/apache/jena/iri/impl/AbsIRIImpl.java
----------------------------------------------------------------------
diff --git a/jena-iri/src/main/java/org/apache/jena/iri/impl/AbsIRIImpl.java b/jena-iri/src/main/java/org/apache/jena/iri/impl/AbsIRIImpl.java
index 2416bf2..76d9f1b 100644
--- a/jena-iri/src/main/java/org/apache/jena/iri/impl/AbsIRIImpl.java
+++ b/jena-iri/src/main/java/org/apache/jena/iri/impl/AbsIRIImpl.java
@@ -268,9 +268,12 @@ abstract public class AbsIRIImpl extends  IRI implements
     }
 
     @Override
-    public URI toURI() {
-        String x = createASCIIString() ;
-        return URI.create(x) ;
+    public URI toURI() throws URISyntaxException {
+        try {
+            String x = createASCIIString() ;
+            return new URI(x) ;
+        } catch (MalformedIDNException ex) 
+        { throw new URISyntaxException(toDisplayString(), ex.getMessage()) ; }
     }
 
     // TODO ToAsciiMask
@@ -283,14 +286,14 @@ abstract public class AbsIRIImpl extends  IRI implements
             | (1l << DOUBLE_DASH_IN_REG_NAME);
 */
     @Override
-    public String toASCIIString() {
+    public String toASCIIString() throws MalformedIDNException {
         if (hasExceptionMask(ToAsciiMask)) {
             return createASCIIString();
         }
         return toString();
     }
 
-    private String createASCIIString() {
+    private String createASCIIString() throws MalformedIDNException {
         StringBuffer asciiString = new StringBuffer();
 
         if (has(SCHEME)) {
@@ -323,7 +326,7 @@ abstract public class AbsIRIImpl extends  IRI implements
         return asciiString.toString();
     }
 
-    private void regNameToAscii(StringBuffer asciiString, String host) {
+    private void regNameToAscii(StringBuffer asciiString, String host) throws MalformedIDNException  {
         if ((errors(HOST) & ToAsciiMask) == 0) {
             asciiString.append(host);
             return;
@@ -331,9 +334,15 @@ abstract public class AbsIRIImpl extends  IRI implements
         asciiString.append(domainToAscii(host));
     }
 
-    static CharSequence domainToAscii(String host) {
-        
-        return IDNP.toASCII(host, IDN.USE_STD3_ASCII_RULES|IDN.ALLOW_UNASSIGNED);
+    private static CharSequence domainToAscii(String host) throws MalformedIDNException {
+        try {
+            return IDNP.toASCII(host, IDN.USE_STD3_ASCII_RULES|IDN.ALLOW_UNASSIGNED);
+            // IDNP (patched IDN) throws IlleaglArgimentException
+            
+        } catch (IllegalArgumentException ex) {
+            // IDNP (patched IDN) throws IlleaglArgumentException
+            throw new MalformedIDNException(ex) ; 
+        }
         /*
         int u[] = new int[host.length()];
         for (int i = 0; i < host.length(); i++)