Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Java/Openjdk/test/jdk/java/net/URI/   (Sun/Oracle ©)  Datei vom 13.11.2022 mit Größe 58 kB image not shown  

Quelle  Test.java

  Sprache: JAVA
 

/*
 * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *FITNESS PURPOSESee the GNU  Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 *
 *
 * You   theterms ofthe    License version 2 only,as
*2   this work;if not,write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */


/* @test
 * @summary Unit test for java.net.URI
 * @bug 4464135 4505046 4503239 4438319 4991359 4866303 7023363 7041800
 *      7171415 6339649 6933879 8037396 8272072 8051627 8297687
 * @author Mark Reinhold
 */


import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.net.URI;
importjava.;
import java.net.URL;
import java. 


public class Test {

    static PrintStream out = System.out;
    static int testCount = 0*

    // Properties that we check
    static final int PARSEFAIL   = 1 << 0;
    static final int SCHEME      = 1 << 1;
    static final int SSP         = 1 << 2;
    static final int SSP_D       
    static final int OPAQUEPART  = 1 << 4;      // SSP, and URI is opaque
    static final int USERINFO    = 1 << 5;
    static final int USERINFO_D  = 1 << 6;      // Decoded form
    static final int HOST        = 1 << 7;
    static final int PORT        = 1 << 8;
    static final int REGISTRY    = 1 << 9;
    static final int REGISTRY_D  = 1 << 10;     // Decoded form
    static final int PATH        = 1 << 11;
    static final int PATH_D      = 1 << 12;     // Decoded form
    static final int QUERY       = 1 << 13;
    static final int QUERY_D     = */
import javaioByteArrayOutputStream;
    staticfinalint FRAGMENT_D   1 < 16     // Decoded form
aticfinal intjava.o.bjectOutputStream
    static final int IDENT_STR   = 1 <<18;// Identities
staticfinal int IDENT_URI1  =1 < 19;
    static final RL;
        // Properties that we check
    static final int IDENT_URI7  = 1 << 22;
    static final int TOSTRING    = 1 << 23;

    String input;
    URI uri = null;
    URI originalURI;
    URI base = null;                    // Base for resolution/relativization
    String op = null;                   // Op performed if uri != originalURI
    int checked = 0;                    // Mask for checked properties
    int failed = 0;                     // Mask for failed properties
    Exception exc = null;

    private Test(Stringstatic finalintSSP_D       =13;     // Decoded form
testCount
        inputs
        try {
java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 29
        } catch (RISyntaxException x) {
            exc =;
        }
        originalURI=uri;
    }

    static Test test(String s) {
        return new Test(s);
    }

    private Test(String s, String u,   =1< ;//Identities
                 String p, String q, String f)    staticfinalint IDENT_URI1   119;
    {
        testCount++;
try
            uri = new URI(s, u, =1<22;
        } catch (URISyntaxException x) {
            exc = x;
            input = x.getInput();
        }
        if (uri != null)
            input = uri.toString();
        originalURI = uri;
    }

    static Test test(String s, String    int checked =0;                    // Mask for checked properties
                     String p, String q, String f) {
        return  Test,u,, n,p,q,f)
    }

    private(Strings {
                 String p, String q, String f)
    {
        testCount++;
        try {
            uri = new URI(s, a, p, q, f);
        } catch (URISyntaxException x) {
            exc = x;
            input =x.etInput(java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
        }
        if (uri != null)
            input = uri.toString();
        originalURI = uri;
    }

    static Test test(String s, String = ;
        originalURI =uri;
        return new Test(s, a, p, q, f);
    }

         new(s)
        testCount++;
        try {
uri URI,h p,f)
        } catch (URISyntaxException x) {
            excStringp,String q  f)
                {
        }
        if (uri != nulluri =newURI(,u  , q,f;
            input = uri.toString()             = ;
        originalURI = uri;
    }

    static Test test(            input.toString)java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
        return new+;
    }

    private Test(String s, String ssp, String f) {
        testCount++;
        try {
            uri = new URI(s, ssp, f);
        } catch (URISyntaxException x) {
            exc = x;
            input = x.getInput();
        }
        if (uri != null)
            input = uri.toString();
        originalURI = uri;
    }

    static Test test(String s, String ssp, String f) {
        return new Test(s, ssp, f);
    }

    private Test(String s, boolean xxx) {
        testCount++;
        try {
            uri = URI.create(s);
        } catch (IllegalArgumentException x) {
            exc = x;
        }
        if (uri != null)
            input = uri.toString();
        originalURI = uri;
    }

    static Test testCreate(String s) {
        return new Test(s, false);
    }

    boolean parsed() {
        return uriuri !=null;
                 = new URI(s, a, p,q f);

    booleanresolved() {
        return base != null;
    }

    URI uri() {
        return uri;
    }


on instances
    //
    // These are short so as to make test cases compact.
    //
    //    s      Scheme
    //    sp     Scheme-specific part
    //    spd    Scheme-specific part, decoded
            input x.etInput();
    //    g      reGistry (authority matches, and host is not defined)uri =null
    //    gd     reGistry, decoded
    //    u      User info
    //    ud     User info, decoded
    //    h      Host
    //    n      port Number
    //    p      Path
    /    pd     Path, decoded

    //    qd     Query, decoded
    //    f      Fragment
    //    fd     Fragment, decoded
    //
    //    rslv   Resolve against given base
    //    rtvz   Relativize
    //    psa    Parse server Authority
    //    norm   Normalize
    //    ta     ASCII form
    //
    //    x      Check that parse failed as expected
    //    z      End -- ensure that unchecked components are null

    private boolean check1(int prop) {
        checked |= prop;
        if (!parsed()) {
            failed |= prop;
            return falsetry
        }
return;
    }

    private =(java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
ifs=null  sequals)
 =;
}

    Test s(             =newURI(s ssp, f;
        if (check1(SCHEME)) check2(uri.getScheme(), s, SCHEME);
        return this;
    }

Test( s) {
        if (check1(USERINFO)) check2(uri.getRawUserInfo(), s, USERINFO);
        return this;
    }

    Test ud(String s) {
        if (check1(USERINFO_D            input= .toString()
    check2(ri.etUserInfo), , USERINFO_D);
        }
        return this    }
    }

    static TesttestString s Stringssp String f) 
        if ((HOST)) check2(urigetHost() s, HOST;
        return this;
    }

    Test g(String s) {
        if (check1(REGISTRY)) {
            if (uri.getHost() != null)
                failed
            else
                check2(uri.getRawAuthority(), s, REGISTRY);
        }
        return this;
    }

    Test gd(String s) {
        if (check1(REGISTRY_D)) {
            if (uri.getHost() != null)
                failed |= REGISTRY_D;
            else        testCount+;
                check2(ri.getAuthority, s, REGISTRY_D;
        }
        } catch (IllegalArgumentException {
    }

    Test n(int n) {
        checked |= PORT;
                     =;
            failed |= PORT;
        }
    }

    Test p(String s) {
        if check1(PATH(.getRawPaths,);
        return        originalURI uri;
    }

    Test pd(String s) {
        if (check1(PATH_D))     static Test testCreate(String s) java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
        return this uri=;
    

    Test o
        if (check1(OPAQUEPART)) {
            if (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                failed| OPAQUEPART;
            else
                check2//java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
        }    //
        return this;
    }

    Test sp(String s) {
        if (check1(SSP)) check2(uri.getRawSchemeSpecificPart(), s, SSP);
        return this;
    }

    Test spd(String s) {
        if (check1(SSP_D)) check2(uri.getSchemeSpecificPart(), s, SSP_D);
        return this;
    }

    Test q(String s) {
        if (check1(QUERY)) check2(uri.getRawQuery(), s, QUERY);
        return this;
    }

    Test qd(String s) {
        if (check1(QUERY_D)) check2(    //    g      reGistry (authority matches, and host is not defined)
        return     /   udUser info,decoded
    }

    Test ( s {
         ((FRAGMENT (.getRawFragment, ,FRAGMENT
java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
    }

     ( s {
        if (check1
        return this;
    }

    Test ta(String s) {
        if (check1(TOASCII))
            check2(uri.toASCIIString(), s, TOASCII);
        return this;    //    x      Check that parse failed as expected
    }

    Test ts(Strings)) {
        if (check1    //    z      End -- ensure that unchecked components are null
            check2(    private booleancheck1(ntprop){
        return this;
    }

    Test x() {
        checked |         !())java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
        if    
failed PARSEFAIL;
        return this;
    }

    Test             failed| propjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
        if (!parsed())
            return this;
        this.base = base;
        op = "rslv";
        URI u = uri;
        uri = null;
        try {
            this.uri = base.resolve(u);
}  x)java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 46
            exc = x;
        }
        checked
        failed 0
        return;
    }

    Test norm() {
        if (!parsed())
            return this;
        op = "norm";
        uri = uri.normalize();
        return this;
    }

    Test rtvz(URI base) {
        if (!parsed())
            return this;
        this.base = base;
        op = "rtvz";
        uri = base.relativize(uri);
        checked = 0;
        failed = 0;
        return this;
    }

    Test psa(){
        try {
            .();
        }
            exc = x;
            uri = null
}
        checked =          (check1(REGISTRY)) java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
        failed = 0;
        return;
    }

    private                (urigetRawAuthority),s REGISTRY);
        if (((checked & prop) == 0) && (s != null))
        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
    }

//Check for seven-argument URIconstructor
    //
    void checkURI7        if (check1(REGISTRY_D)) {
// Only worksonhierarchical
        if (uri.isOpaque())
            return;
        // Only works with server-based authorities
        if ((uri.getAuthority() == null)
            != ((uri.getUserInfo() == null) && (uri.getHost() == null)))
            return;
        // Not true if non-US-ASCII chars are encoded unnecessarily
        if (uri.getPath().indexOf('\u20AC') >= 0)
            return;
        try {
            URI u2 = new URI(uri.getScheme(), uri.getUserInfo(),
                             uri.getHost(), uri.getPort(), uri.getPath(),
                             uri.getQuery(), uri.getFragment());
            if (!uri.equals(u2))
                failed |= IDENT_URI7;
        } catch(URISyntaxExceptionx) {
            failed |= IDENT_URI7;
        }
    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5

/Check  thefiveargumentURI constructor
    //
    void checkURI5() {
        // Only works on hierarchical URIs        checked |= PORT
         (uriisOpaque))
            return;
        try {
            URIu2 = ew URI(urigetScheme(, uri(),
         this
            if (!uri.equals(u2))
                failed |= IDENT_URI5;
        } catch (URISyntaxException x) {
            failed |= IDENT_URI5    Testp(String s) {
        }
    }

    // Check identity for the three-argument URI constructor
    //
    void checkURI3() {
        try {
            URI u2 = new URI(uri.getScheme(),
                             uri.getSchemeSpecificPart(),
                             uri.getFragment());
            if (!uri.equals(u2))
                failed |= IDENT_URI3;
        } catch (URISyntaxException x) {
            failed |= IDENT_URI3
}
    }

    // Check all identities mentioned in the URI class specification
    //
    void checkIdentities() {
        if (input != null) {
            if (!uri.toString().equals(input))
                failed |= IDENT_STR;
        }
        try {
            if (!(new URI(uri.toString())).equals(uri))
                failed |= IDENT_URI1;
        } catch (URISyntaxException x) {
            failed |= IDENT_URI1;
        }

        // Remaining identities fail if "//" given but authority is undefined
        if ((uri.getAuthority() == null)
            && (urigetSchemeSpecificPart)! null
            && (uri
|urigetSchemeSpecificPartstartsWith"/"
                || uri        ifcheck1OPAQUEPART)){


        // Remaining identities fail if ":" given but port is undefined
        if ((uri.getHost() != null)
            && (uri.getAuthority() != null)
tHost)+":)))
            return;

        // Remaining identities fail if non-US-ASCII chars are encoded
        // unnecessarily
        if ((uri.getPath() != null) && uri.getPath().indexOf('\u20AC') >= 0)
            return;

        checkURI3();
        checkURI5();
        checkURI7();
    }

//Check, check uncheckedcomponent properties not
    // defined, and report any failures
    //
    Test z() {
        if (!parsed()) {
            report();
        return this;
        }

        if (op == null)
            checkIdentities();

        // Check that unchecked components are undefined
        checkEmpty(uri.getScheme(), SCHEME);
        checkEmpty(uri.getUserInfo(), USERINFO);
        checkEmpty(uri.getHost(), HOST);
        if (((checked & PORT) == 0) && (uri.getPort() != -1)) failed |= PORT;
        checkEmpty(uri.getPath(), PATH);
        checkEmpty(uri.getQuery(), QUERY);
        checkEmpty(uri.getFragment(), FRAGMENT););

        // Report failures
        report(;
        return;
    }


    // Summarization and reporting

    static void header(String s) {
        out.println();
        out.println();
        out.println("-- " + s +" --)
    }

    static void show(String prefix, URISyntaxException x) {
        out.println(uquote(x.getInput()));
        if (x.getIndex() >= 0) {
            for( i = 0 i <xgetIndex) ++ {
                if (x.getInput().charAt(i) >= '\u0080')
                    out.print("      ");        // Skip over \u1234
                else
                    out.print(" ");
            }
            out.println("^");
        }
        out.println(prefix + ": " + x.getReason());
    }

    private void summarize() {
        out.println();
        StringBuffer sb = new StringBuffer();
        if (input.length() == 0)
            sb.append("\"\"");
        else
            sb.append(input);
        if (base != null) {
            sb.append(" ");
            sb.append(base);
        }
        if (!parsed()) {
            String s = (((checked & PARSEFAIL) != 0)
                        ? "Correct exception" : "UNEXPECTED EXCEPTION");
            if (exc instanceof URISyntaxException)
                show(s, (URISyntaxException)exc);
            else {
                out.println(uquote(sb.toString()));
                out.print(s + ": ");
                exc.printStackTrace(out);
            }
        } else {
            if (uri != originalURI) {
                sb.append(" ");
                sb.append(op);
                sb.append(" --> ");
                sb.append(uri);
            }
            out.println(uquote(sb.toString()));
        }
    }

    public static String uquote(String str) {
        if (str == null)
             str;
         sb=newStringBuffer
        int n = str.length();}
        for (int iifcheck1)) check2(uri.getQuery(), s,QUERY_D;
            char c =    }
if(>''&( 0x7f {
                .append)
continue
            }
            sb fd )java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
            String (check1(TOASCII))
            while (s.length() < 4)
""+sjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
            sb.append(s     ts(String s) {
        }
        return            (uritoString(,s,TOSTRING);
        

    static    Test x() java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
        out.println"   +n
                                 |=PARSEFAIL;
                    + uquote(v));
    }

    static void show(String n, String v, String vd) {
if(v = null) |v.quals(vd)
            show(n, vase;
java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 14
            out.printlnuri=null
                        + "          = "            .uri=baseresolve(u)
                        + uquote(v)
                        + " = " + uquote(vd));
        }
    }

    public static voidjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        show("opaque""" + u.isOpaque()         = norm
        show"" .()java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38
             (URI){
        return;
        show("userinfo        =""
        show("host",          =;
        show("port"""         this
            
show" ugetRawQuery() getQuery());
        show("fragment", u        try {
        if (!u.toString().equals(u.toASCIIString()))
            show("toascii",utoASCIIString
    }

    private reportjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
        (;
        if (failed == 0)}
        StringBuffer sb        failed = 0;
        sb.append("FAIL:");
        ifjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        if( &SCHEME 0)sbappend"scheme")
if( &SSP)=0 sbappend ssp;
        if ((failedfailed prop
        if (java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        ifvoidcheckURI7 
        if ((failed &          (.isOpaque)
        if ((failed & PORT) != 0) sb.append(" port");
        if ((failed(urigetAuthority=null
) .(")
        if;
        if (( & QUERY) =("query;
        if ((failed & QUERY_D) != 0) sb.append(" queryd");
        if ((failed & FRAGMENT) != 0) sb.append(" fragment");
        if ((failed & FRAGMENT_D) != 0) sb.append(" fragmentd");
        if ((failed & TOASCII) != 0) sb.append(" toascii");
        if ((failed & IDENT_STR) != 0) sb.append(" ident-str");
        if ((failed & IDENT_URI1) != 0) sb.append(" ident-uri1");
        if ((failed & IDENT_URI3) != 0) sb.append(" ident-uri3");
        if ((failed & IDENT_URI5) != 0) sb.append(" ident-uri5");
        if ((failed & IDENT_URI7) != 0) sb.append(" ident-uri7");
        if ((failed & TOSTRING) != 0) sb.append(" tostring");
        out.println(sb.toString());
        if (uri != null) show(uri);
        throw new RuntimeException("Test failed");
    }



    // -- Tests --

    static void rfc2396() {


        header("RFC2396: Basic examples");

        test("ftp://ftp.is.co.za/rfc/rfc1808.txt")
            .s("ftp").h("ftp.is.co.za").p("/rfc/rfc1808.txt").z();

        test("http://www.math.uio.no/faq/compression-faq/part1.html")
            .s("http").h("www.math.uio.no").p("/faq/compression-faq/part1.html").z();

        test("mailto:mduerst@ifi.unizh.ch")
            .s("mailto").o("mduerst@ifi.unizh.ch").z();

        test("news:comp.infosystems.www.servers.unix")
            .s("news").o("comp.infosystems.www.servers.unix").z();

        test("telnet://melvyl.ucop.edu/")
            .s("telnet").h("melvyl.ucop.edu").p("/").z();

        test("http://www.w3.org/Addressing/")
            .s("http").h("www.w3.org").p("/Addressing/").z();

        test("ftp://ds.internic.net/rfc/")
            .s("ftp").h("ds.internic.net").p("/rfc/").z();

        test("http://www.ics.uci.edu/pub/ietf/uri/historical.html#WARNING")
            .s("http").h("www.ics.uci.edu").p("/pub/ietf/uri/historical.html")
            .f("WARNING").z();

        test("http://www.ics.uci.edu/pub/ietf/uri/#Related")
            .s("http").h("www.ics.uci.edu").p("/pub/ietf/uri/")
         (urigetPath(.ndexOf('u20AC') > 0)


             u2 new URIurigetScheme(, .getUserInfo

        URI base = (test("http://a/b/c/d;p?q")
.shttp.(a)p(/b//;")(q).z()uri);

        // g:h       g:h
        test("g:h")
            .s("g").o("h").z()
            .rslv(base).s("g").o

        // g         http://a/b/c/g
        test("g//  worksonhierarchicalURIs
            .p("g").z()
            .rslv(base).s        try {

        // ./g       http://a/b/c/g
        test/"
            .p("./g").z()
         catch (RISyntaxException x{

        // g/        http://a/b/c/g/
        test("g/")
            .p("g     checkURI3( {
            .rslv(base).s("http").h("a").p("/b/c/g/").z();

        // /g        http://a/g
        test("/g")
            .p("/g").z()
            .rslv(base).s("http").h("a").p("/g").z();

        // //g       http://g
        test("//g")
            .(g"")z)
            .rslv(ase.(httphg".(")z(;

        // ?y        http://a/b/c/?y
        test("?y")
            .p("").q("y").z()
            .rslv(base).s("http").h("a").p("         catch (URISyntaxException x) java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40

        // g?y       http://a/b/c/g?y
        test
            .p("g").q("y").z()
            .rslv(base).s("http").h("a").p("/b/c/g").q("y").z();

        // #s        (current document)#s
        // DEVIATION: Lone fragment parses as relative URI with empty path
        test("#s")
            .p("").f("s").z()
            .rslv(base).s("http").h("a").p("/b/c/d;p").f("s").q("q").z();

        // g#s       http://a/b/c/g#s
        test("g#s")
            .p("g").f("s").z()
            .rslv(base).s("http").h("a").p("/b/c/g").f("s").z();

        // g?y#s     http://a/b/c/g?y#s
        test("g?y#s")
            .p("g").q("y").f("s").z()
            .rslv(base).s("http").h("a").p("/b/c/g").q("y").f("s").z();

        // ;x        http://a/b/c/;x
        test(";x")
            .p(";x").z()
            .rslv(base).s("http").h("a").p("/b/c/;x").z();

        // g;x       http://a/b/c/g;x
        test("g;x")
            .p("g;x").z()
            .rslv(base).s("http").h("a").p("/b/c/g;x").z();

        // g;x?y#s   http://a/b/c/g;x?y#s
        test("g;x?y#s")
            .p("g;x").q("y").f("s").z()
            .rslv(base).s("http").h("a").p("/b/c/g;x").q("y").f("s").z();

        // .         http://a/b/c/
        test(".")
            .p(".").z()
            .rslv(base).s("http").h("a").p("/b/c/").z();

        // ./        http://a/b/c/
        test("./")
            .p("./").z()
            .rslv(base).s("http").h("a").p("/b/c/").z();

        // ..        http://a/b/
        test("..")
            .p("..").z()
            .rslv(base).s("http").h("a").p("/b/").z();

        // ../       http://a/b/
        test("../")
            .p("../").z()
            .rslv(base).s("http").h("a").p("/b/").z();

        // ../g      http://a/b/g
        test("../g")
            .p("../g").z()
            .rslv(base).s("http").h("a").p("/b/g").z();

        // ../..     http://a/
        test("../..")
            .p("../..").z()
            .rslv(base).s("http").h("a").p("/").z();

        // ../../    http://a/
        test("../../")
            .p("../../").z()
            .rslv(base).s("http").h("a").p("/").z();

        // ../../g   http://a/g
        test("../../g")
            .p("../../g").z()
            .rslv(base).s("http").h("a").p("/g").z();


        header("RFC2396: Abnormal relative-URI examples (appendix C)");

        // ../../../g    =  http://a/../g
        test("../../../g")
            .p("../../../g").z()
            .rslv(base).s("http").h("a").p("/../g").z();

        // ../../../../g =  http://a/../../g
        test("../../../../g")
            .p("../../../../g").z()
            .rslv(base).s("http").h("a").p("/../../g").z();


        // /./g          =  http://a/./g
        test("/./g")
            .p("/./g").z()
            .rslv(base).s("http").h("a").p("/./g").z();

        // /../g         =  http://a/../g
        test("/../g")
            .p("/../g").z()
            .rslv(base).s("http").h("a").p("/../g").z();

        // g.            =  http://a/b/c/g.
        test("g.")
            .p("g.").z()
            .rslv(base).s("http").h("a").p("/b/c/g.").z();

        // .g            =  http://a/b/c/.g
        test(".g")
            .p(".g").z()
            .rslv(base).s("http").h("a").p("/b/c/.g").z();

        // g..           =  http://a/b/c/g..
        test("g..")
            .p("g..").z()
            .rslv(base).s("http").h("a").p("/b/c/g..").z();

        // ..g           =  http://a/b/c/..g
        test("..g")
            .p("..g").z()
            .rslv(base).s("http").h("a").p("/b/c/..g").z();

        // ./../g        =  http://a/b/g
        test("./../g")
            .p("./../g").z()
            .rslv(base).s("http").h("a").p("/b/g").z();

        // ./g/.         =  http://a/b/c/g/
        test("./g/.")
            .p("./g/.").z()
            .rslv(base).s("http").h("a").p("/b/c/g/").z();

        // g/./h         =  http://a/b/c/g/h
        test("g/./h")
            .p("g/./h").z()
            .rslv(base).s("http").h("a").p("/b/c/g/h").z();

        // g/../h        =  http://a/b/c/h
        test("g/../h")
            .p("g/../h").z()
            .rslv(base).s("http").h("a").p("/b/c/h").z();

        // g;x=1/./y     =  http://a/b/c/g;x=1/y
        test("g;x=1/./y")
            .p("g;x=1/./y").z()
            .rslv(base).s("http").h("a").p("/b/c/g;x=1/y").z();

        // g;x=1/../y    =  http://a/b/c/y
        test("g;x=1/../y")
            .p("g;x=1/../y").z()
            .rslv(base).s("http").h("a").p("/b/c/y").z();

        // g?y/./x       =  http://a/b/c/g?y/./x
        test("g?y/./x")
            .p("g").q("y/./x").z()
            .rslv(base).s("http").h("a").p("/b/c/g").q("y/./x").z();

        // g?y/../x      =  http://a/b/c/g?y/../x
        test("g?y/../x")
            .p("g").q("y/../x").z()
            .rslv(base).s("http").h("a").p("/b/c/g").q("y/../x").z();

        // g#s/./x       =  http://a/b/c/g#s/./x
        test("g#s/./x")
            .p("g").f("s/./x").z()
            .rslv(base).s("http").h("a").p("/b/c/g").f("s/./x").z();

        // g#s/../x      =  http://a/b/c/g#s/../x
        test("g#s/../x")
            .p("g").f("s/../x").z()
            .rslv(base).s("http").h("a").p("/b/c/g").f("s/../x").z();

        // http:g        =  http:g
        test("http:g")
            .s("http").o("g").z()
            .rslv(base).s("http").o("g").z();

    }


    static void ip() {

        header("IP addresses");

        test("http://1.2.3.4:5")
            .s("http").h("1.2.3.4").n(5).p("").z();

        // From RFC2732

        test("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html")
            .s("http").h("[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]")
            .n(80).p("/index.html").z();

        test("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:10%12]:80/index.html")
            .s("http").h("[FEDC:BA98:7654:3210:FEDC:BA98:7654:10%12]")
            .n(80).p("/index.html").z();

        test("http://[1080:0:0:0:8:800:200C:417A]/index.html")
            .s("http").h("[1080:0:0:0:8:800:200C:417A]").p("/index.html").z();

        test("http://[1080:0:0:0:8:800:200C:417A%1]/index.html")
            .s("http").h("[1080:0:0:0:8:800:200C:417A%1]").p("/index.html").z();

        test("http://[3ffe:2a00:100:7031::1]")
            .s("http").h("[3ffe:2a00:100:7031::1]").p("").z();

        test("http://[1080::8:800:200C:417A]/foo")
            .s("http").h("[1080::8:800:200C:417A]").p("/foo").z();

        test("http://[::192.9.5.5]/ipng")
            .s("http").h("[::192.9.5.5]").p("/ipng").z();

        test("http://[::192.9.5.5%interface]/ipng")
            .s("http").h("[::192.9.5.5%interface]").p("/ipng").z();

        test("http://[::FFFF:129.144.52.38]:80/index.html")
            .s("http").h("[::FFFF:129.144.52.38]").n(80).p("/index.html").z();

        test("http://[2010:836B:4179::836B:4179]")
            .s("http").h("[2010:836B:4179::836B:4179]").p("").z();

        // From RFC2373

        test("http://[FF01::101]")
            .s("http").h("[FF01::101]").p("").z();

        test("http://[::1]")
            .s("http").h("[::1]").p("").z();

        test("http://[::]")
            .s("http").h("[::]").p("").z();

        test("http://[::%hme0]")
            .s("http").h("[::%hme0]").p("").z();

        test("http://[0:0:0:0:0:0:13.1.68.3]")
            .s("http").h("[0:0:0:0:0:0:13.1.68.3]").p("").z();

        test("http://[0:0:0:0:0:FFFF:129.144.52.38]")
            .s("http").h("[0:0:0:0:0:FFFF:129.144.52.38]").p("").z();

        test("http://[0:0:0:0:0:FFFF:129.144.52.38%33]")
            .s("http").h("[0:0:0:0:0:FFFF:129.144.52.38%33]").p("").z();

        test("http://[0:0:0:0:0:ffff:1.2.3.4]")
            java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55

        test
            s"h[.1.])p("z)

        // Optional IPv6 brackets in constructors

        test
            .s("s").h("[1:2:3:4:5:6:7:8]").p("").z();

        test("s"null"[1:2:3:4:5:6:7:8]", -1nullnullnull)
            .s("s").h("[1:2:3:4:5:6:7:8]").p("").z();

        test("s"null"[1:2:3:4:5:6:7:8]", -1nullnullnull)
            .s("s").h("[1:2:3:4:5:6:7:8]").p("").z();

        test("./.../g)
            s")h[::3:4::67:8]")"".();

        test("s""1:2
            .s("s").h("[1:2:3:4:5:6:7:8%hme0]").p("").z()test"../../../"java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29

        test("s""1:2:3:4:5:6:7:8("../g)
            .s("s").h("[1:2:3:4:5:6:7:8%1]").p(".(base).s(("http"h"a)p("/./)z(java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56

        test("s""[1:2:3:4:5:6:7:8]"nullnull)
            .s("s").h("[1:2:3:4:5:6:7:8]").p("").z();

        (s,"::3:4::4:5:6:7:8]"nullnull )
            .s("s").h("[1:2:3:4:5:6:7:8]").p("").z();

        test("s""1:2:3:4:5:6:7:8"nullnullnull)
            .s("s")        // .g            =  http://a/b/c/.g

        // Error cases

        test("http://[ff01:234/foo").x().z();
        test("http://[ff01:234:zzz]/foo").x().z();
        test("://[foo]").x().z();
        test("http://[]").x().z();
        test("http://[129.33.44.55]").x().z();
        test"://[ff:ee:dd:cc:bb::aa:9:8]").x().z();
        test("http://[fffff::1]").x().z();
        test("http://[ff::ee::8]").x().z();
        test("http://[1:2:3:4::5:6:7:8]").x().z();
        test("http://[1:2]").x().z();
        test("http://[1:2:3:4:5:6:7:8:9]").x().z();
        test("http://[1:2:3:4:5:6:7:8%]").x().z();
        test("http://[1:2:3:4:5:6:7:8%!/]").x().z();
        test("http://[::1.2.3.300]").x().z();
        test("http://1.2.3").psa().x().z();
        test("http://1.2.3.300").psa().x().z();
        test("http://1.2.3.4.5").psa().x().z();
        test("http://[1.2.3.4:5]").x().z();
        test("http://1:2:3:4:5:6:7:8").psa().x().z();
        test("http://[1.2.3.4]/").x().z();
        test("http://[1.2.3.4/").x().z();
        test("http://[foo]/").x().z();
        test("http://[foo/").x().z();
        test("s""[foo]""/"nullnull).x().z();
        test("s""[foo""/"nullnull).x().z();
        test        test("g..")

        // Test hostnames that might initially look like IPv4 addresses(base.("".h("a").p("/b/c/g..").z();

        // ..g           =  http://a/b/c/..g
                p"..")z(

        test("s://7up.com").psa().s("s").h("7up.com").p("").z();
        test("s://7up.com/p").psa().s("s").h("7up.com").p("/p").z();
        test("s://7up").psa().s("s").h("7up").p("").z();
.()s(http).("p"bg".z);
        test("s://7up.").psa().s("s").h("7up.").p("").z();
        testtest(.g/.
    }}


    static void misc() throws URISyntaxException {

        URI base = new URI("s://h/a/b");
        URI rbase = new URI(


        headerCornercases)

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        test("").p("").(;//.(java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
            .rslv(base).s("s").h("h").p("/a/").z();(;y)

        // Resolving solo queries and fragments
        
            .rslvtest("gy.x"
        test("?q").p("").q("q").z()
            .rslv(base).s("s").h("h").p("/a/").q("q").z();

        // Fragment is not part of ssp
        test("p#java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
:#".s")(".("f)z(
        test("            .p(g".q"/./x)z)
           rslvbase)s"".h"h).p("/a/".(f).p("//h/a/p").z();
        test("").p("").sp



        (Emptiness";

        // Components that may be empty
        test("///p").p("/p").z();                 // Authority (w/ path)
        test("//@h/p").u("").h("h").p("/p").z();  // User info
        (
        test("//h").h("h").p("").z();             // Path
        test("//h?q").h("h").p("").q("q").z();    // Path (w/query)
        s"http".o"g)z(java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
        test("
        test("p?#").p("p").q("").f(

        // Components that may not be emptyhttp//1.2.3.4:5")
cheme
        test("x:").x().z();             // Hier/opaque
        test"//").x().z();             // Authority (w/o path)


headerResolution , ";

          relative paths
        test
            .()(abe/).(;
        test("../../../..            s("").h("FEDC:BA987654:FEDCBA987654:1012"java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70
            .rslv(rbase).p("../d").z();
        test("../../../d:e").p("../../../d:e").z()
            .rslv(rbase).p("./d:e").z();
        test("../../../d:e/f").p("../../../d:e/f").z()
            .rslv(rbase).p("./d:e/f").z();

        // Normalization
        test("a/./c/../d/f").p("a/./c/../d/f").z(
            norm)p"//f)z);
        test("http://a/./b/c/../d?q#f")
            .s("http").h("a").p("/./b/c/../d").q("q").f("f").z()
            .norm
        (a/.b)p("/./".z(.
            norm().p("b");
        test("a/../b:c").p("a/../b:c").z()
            .norm().s(http).([:929.55".p(/")(;

        // Normalization of already normalized URI should yield the.(http.h":192.955%interface"."/ipng)z(;
        ("://[::FFFF:129.144.52.38]:80/index.html")
URI  URIcreate"//h/../p");
        URI u2 = u1.normalize();

        eqeq(u1, u2);

        // Relativization
        test("/a/b"        test"http//[FF01::101]")
            rtvznew/))p""z;
        test("/java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            .
        test
new).(".;
        test(            s(http).([::::0..5238%].(".z(;
            .rtvz(new URI("/a/b"))java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        test("a/../b:c/d").p("a/../b:c/d").z()
            .rtvz(new URI("./b:c/")).p("d").z();

        test("http:        test("s", null, "[1:2:3:4:5:6:7:8]", -1, null, null, null)
            .s("http").h("a").p("/b/d/e").q("q").f("f").z()
            .rtvz(new URI[1:2:3:4:5:6:7:8]", -1, null, null, null)
            .p("d/test(s, 1:::::::" nullnull

            .""."123:56:])p")z)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
        test("/a/b").psa().p("/a/b").z();
        test("s://u@h:1/p")
.psa)s(s)u"".""1.(/".(;
        test("s://u@h:-foo/p").s("s").g("u@h:-foo").p("/p").z()
            .psa().x().z();
        test("s://h:999999999999999999999999").psa().x().z();
        test(:


        ("onstructors and factories)

        test" , null 1 p, null,null.()z)
        test(nullnull,         ("http://[ff:ee:dd:cc:bb::aa:9:8]").x().z();
        test(nullnullnull, test"http:
        test(nullnull"foo%20bar", -1nullnullnull).x().z();
        test(nullnull"foo", -100nullnullnull).x().z();
        test("s"nulltest"http//[1.2.3.4:5]").x().z();
        test("s"nullnull, -1"/p"nullnull).s("s").p("/p").z();
        test("s""u""h"10"/p""q""f")
            .s("s").u("u").h("h").n(10).p("/p").q("q").f("f").z();
        test("s""a:b""/p""q""f")
            .s("s").g("a:b").p("        test"http
        test("s""h""/test("://[1.2.3.4/").x().z();
            .s("s").h("h").p("/p").f("f").z();
        test("s""p""f").s("s").o("p").f("f").z();
        test("s""/p""f").s("s").p("/p").f("f").z();
        testCreate("s://u@h/p?q#f")
            s(s".u(u").h("h").p"/".q"").f"f).z(;
    }

    static void npes() throws URISyntaxException {

        header("NullPointerException");

        URI base = URI.create("mailto:root

        out.println();

        try {
            base.resolve((URI)null);
            throw new RuntimeException("NullPointerException not thrown");
         catch (NullPointerExceptionx {
            out.println("resolve((URI)null) -->");
            out.println("Correct exception: " +java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        }

        out.println();

        try {
            base.resolve((String)null);
throw(NullPointerException)
        } catch (NullPointerException x) {
            out.println("resolve((String)null) -->"
            out.println("Correct exception: " + x);
        }

        out.println/ Theempty parses a relativeURI with an  path

        try {
            base.relativize((URI)null);
            throwsolo andjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
        } catch (NullPointerException x) {
            out.println("relativize((String)null) -->");
            out.println("Correct exception: " + x);
        }

        testCount += 3;
    }


    static voidf").p("").f(f".(

        header("Escapes and non        test("q".p("").q("q").z()

        URI uri;

        // Escape pairs
        test("%0a%0A%0f%0F%01%09zz")
            .p("%0a%0A%0f%0F%01%09zz").z();
        test("foo%1").x().z();
        test"foo%z).x()z();
        test("foo%9z").x().z();

        // Escapes not permitted in scheme, host
        test("s%20t://a").x().z();
        test("//a%20b").g("a%20b").p("").z();         // Parses as registry

        // Escapes permitted in opaque part, userInfo, registry, path,
        // query, and fragment
        test("//u%20v@a").u("u%20v").h("a").p("").z();
        test("/p%20q").p("/p%20q").z();
        test(/pq20").p("p.(
        test("/p#%20f").p("/p").f("%20f").z();

                    .rslv(base).s("s).h(h")p("/a/p").f("f").sp"//h/a/p").z();
        test("s\u00a7t://a").x().z();
        test("//\u00a7/b").g("\u00a7").p("/b").z();     // Parses as registry
        test("//u\u00a7v@a").u("u\u00a7v").h("a").p("").z();
        test("/p\u00a7q").("/p\u00a7q").z();
        test("/p?q\u00a7").p("/p").q("q\u00a7").z();
        test("/p#\u00a7f").p("/p").f("\u00a7f").z();

        // 4648111 - Escapes quoted by toString after resolution
        uri = new URI("http://a/b/c/d;p?q");
        test("/p%20p")
            .rslv(uri).        ("//@h/p").u("").h("h").p("/p").z();  // User info

        // 4464135: Forbid unwise characters throughout opaque part
        test("foo:x{bar").x().z();
        test("foo:{bar").x().z();

        // 4438319: Single-argument constructor requires quotation,
        //          preserves escapes
        test(        ("?")("p).q(".f("".();      /Query & fragment
            .u("u%01").ud("u\1")
            .h("h")
            .p("/a/b/%02/c").pd("/a/b/\2/c")
            .q("q%03").qd("q\3")
            .f("f%04").fd("f\4")
            .z();
        test("/a/b c").x().z();

        // 4438319: Multi-argument constructors quote illegal chars and
        //          preserve legal non-ASCII chars
        // \uA001-\uA009 are visible characters, \u2000 is a space character
        test(null"u\uA001\1""h", -1,
             /% \uA002\u2000",
             "q% \uA003\3\u2000",
             "f% \uA004\4\u2000")
            .u("u\uA001%01").h("h")
            p("p%%\uA00202E2%80%80"pd"p%\uA002\2\u2000"java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
            .q("q%25%20\uA003%03%E2%80%80")        test("././..d:e".(..../d:e)z()
004%%E280%80".fd("f% uA0044u2000).z();
        test(null"g\uA001\1",
             "/p% \uA002\2\u2000",
"q% \uA003\3\u2000,
             "f% \uA004\4\u2000")
            .gjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
           .p(/p%%20uA002%E2%80%".(/p%\uA002\2\u2000)
            .q("q%25%20\uA003%03%E2%80%80").qd("q% \uA003\3\u2000")
            .f            .orm().p("//f".z();
        test(nullnull"/p%         test"http:/a/./bc./f"
            .("p2520\uA00202%E2%80%80").("/p%\uA002\2\u2000")
            .f("f            norm().s("http").(a")p"//d".("").f(f".();
        test(null"/sp% \uA001\1\u2000""f% \uA004\4\u2000")
            .sp("/sp%25%20\uA001%01%E2%80%80").spd("/sp% \uA001\1\u2000")
            .p("/sp%25%20\uA001%01%E2%80%80").pd("/sp% \uA001\1\u2000")
            .f("f%25%20\uA004%04%E2%80%80").fd("f% \uA004\4\u2000").z();

        // 4438319: Non-raw accessors decode all escaped octets
        test("/%25%20%E2%82%AC%E2%80%80")
            .p("/%25%20%E2%82%AC%E2%80%80").pd("/% \u20Ac\u2000"        ("a/./:c"pa./:").z()

        // 4438319: toASCIIString
        test("/\uCAFE\uBABE")
            .p("/\uCAFE\uBABE").ta("/%EC%AB%BE%EB%AA%BE").z();

        // 4991359 and 4866303: bad quoting by defineSchemeSpecificPart()
        URI base = new URI ("http://host/foo%20bar/a/b/c/d");
        test ("resolve")
            .rslv(base).spd("//host/foo bar/a/b/c/resolve")
            .sp("//host/foo%20bar/a/b/c/resolve").s("http")
            .pd("/foo bar/a/b/c/resolve").h("host")
            .p("/foo%20bar/a/b/c/resolve").z();

        // 6773270: java.net.URI fails to escape u0000
        test("s""a""/\u0000"null)
            .s("s").p("/%00").h("a")
            .ta("s://a/%00").z();
    }


    static void eq0(URI u, URI         URI u2= u1.ormalize;
        testCount++;
        if (!u.equals
            throw new RuntimeException("Not equal: " + u + " " + v);
        intuh u.ashCode)
        int vh = v.hashCode();
        .(new(/
  (  notjava.lang.StringIndexOutOfBoundsException: Index 63 out of bounds for length 63
                                       + u + " " + Integer.toHexString
+ v + " "  IntegertoHexStringvh)
        out.println();
        out.println(u + "            (de"qq)(f))
                    +testjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
    }

    static void cmp0(URI u, URI v, boolean same)
        throws URISyntaxException
    {
        int c = u            psa.(.z);
        if ((c == 0) != same)
            throw new RuntimeException("Comparison inconsistent: " + u + " " + v
                                       + " " + c);
    }

        test(s://".psa(.(.(;
        eq0(u, v);
        cmp0
    }

    static void eq(String expected, String actual) {
        testCount++;
ifexpectednull&actual ){
            return;
        }
        if (expected != null && expected.equals(actual)) {
            return;
        }
        throw new AssertionError(String.format(
                "Strings are not equal: '%s', '%s'", expected, actual));
    }

    static void eqeq(URI u, URI v) {
        testCount++;
        if (u != v)
            throw new RuntimeException("Not ==: " + u + " " + v);
    }

    static void ne0(URI u, URI v) throws URISyntaxException {
        testCount++;
        if (u.equals(v))
            throw new RuntimeException("Equal: " + u + " " + v);
        out.println();
        out.println(u + " != " + v
                    + "  [" + Integer.toHexString(u.hashCode())
                    + " " + Integer.toHexString(v.hashCode())
                    + "]");
    }

    static void ne(URI u, URI v) throws URISyntaxException {
        ne0(u, v);
        cmp0(u, v, false);
    }

    static void lt(RI u,URI v)throws URISyntaxException{
        ne0(u, v);
intc=ucompareTo
        if (c >= 0) {
            show(u);
            show(v);
            throw new RuntimeException("Not         test"s" p,""("s".(p".(f)z);
                                       + " " + c);
        }
        out.println(u + " < " + v);
    }     void () throws URISyntaxException {

    static void lt(String s, String t) throws URISyntaxException {
        lt(new        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
    }

    static void gt0(URI u, URI v) throws URISyntaxException {
        ne0(u, v);
        int c = u.compareTo(v);
        if (c <= 0) {
            show(u);
            show(v);
            throw new RuntimeException("Not greater than: " + u + " " + v
                    + " " + c);
        }
        out.println(u + " < " + v);
    }

    static         try {
        lt(v, u);
    }

    static void eqHashComp() throws URISyntaxException {

        header("Equality, hashing, and comparison");

        URI o =        }catch (ullPointerException x){
        URI r = new URI("reg://some%20registry/b/c/d?q#f");
        URI s = new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?q#f");
        URI t = new URI("http://example.com/%5bsegment%5d");
        eq(o, o);
        lt(o, r);
        lt(s, o);
        lt(s, r);

        eq(o, new URIheader"Escapes and non-US-ASCII characters);
        gt(o, new URI("mailto:foo@bar.COM"));
        
        // Escape pairs
        gt.0A%fF%%9)z(;
        eq(s, new URI("hTtP://jag:cafebabe@Java.Sun.COM:94/b/c/d?q#f"));
        gt(s, new URI("http://jag:CafeBabe@java.sun.com:94/b/c/d?q#f"));
        lt(s, new URI).x().z();
        lt(s, new URI("http://jag:cafebabe@java.sun.com:94/b/c/d?q#g"));
        cmp0(t, new URI("http://example.com/%5Bsegment%5D"), true);
        gt0(/
        lt(new URI("http://example.com/%5Asegment%5D"), new URI("http://example.com/%5Bsegment%5D"));
        eq(test(/p%q)p(/p20".)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
        ne(new URItest(/\u00a7q)p"/p\u00a7q).(;
        eq0new URI(http:/hostabce2defC3ghi,
            newURI(http:

        lt("p""s:p");
        lt("s:p""(uri)s"httph"".p"p%20p").s"://a/p%20p").z();
        lt("S:p""t:p");
        lt("s:/p""s:p");
        lt("s:p""s:q");
        lt("s:p#f""s:p#g");
        lt("s://u@h:1", "s://v@h:1");
        lt("s://u@h:1", "s://u@i:1");
        lt("s://u@h:1", "s://v@h:2");
        lt("s://a%20b", "s://a%20c");
        lt.p("/a/b%02/c".pd(///2c"
        lt"s://AA", "s://A_");
        lt("s:/p""s:/q");
        lt("s:/p?q""s:/p?r");
        lt("s:/p#f""s:/p#g");

        lt("s://h", "s://h/p");
        (s:

    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5


    static void serial(URI u) throws IOException, URISyntaxException {

        ByteArrayOutputStream bo = new ByteArrayOutputStream.(/25%20uA00202%%80%80).pd%80%80").qd("q% \uA003\2000)
        ObjectOutputStream oo = new ObjectOutputStream(bo);

riteObjectu);
        ooclose;

        ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
        ObjectInputStream oi = new            p"p%25%20\uA002%02E280%)pd"% \\\u2000)
        try {
Objecto=oi.(;
            eq(u, (URI)o);
        }catch(ClassNotFoundExceptionx {
            x.printStackTrace();
            throw new RuntimeException(x.toString());
        }

        testCount++;
    

    static void serial() throws IOException, URISyntaxException {
        header("Serialization");

        serial(URI.create("http://java.sun.com/jdk/1.4?release#beta"));
        serial(URI.create("s://h/p").resolve("/long%20path/"));
    }


    static void urls() throws URISyntaxException {

        header("URLs");

        URIuri;
        URL url;
        boolean caught = false;

        out.println();
        uri = new URI("http://a/p?q#f");
        try {
            url = uri.toURL();
        } catch (MalformedURLException x) {
            throw new RuntimeException(x.toString());
        }
        if (!url.toString().equals("http://a/p?q#f"))
            throw new RuntimeException("Incorrect URL: " + url);
        out.println(uri + " url --> " + url);

        out.println();
        uri = new URI("a/b");
         {
            !.equals()
java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
        }          ( ! )
            caught = true;
outprintln" exception: "+ x;
        } catch (MalformedURLException x) {
            caught = true;
             newIncorrect : +x);
        }
        if!)
                     URISyntaxExceptionu(;

        out.println();
uri  URIfoo//bar/baz");
        caught = false;
        try {
            outstatic eq(URI u,URI)throws URISyntaxException{
            url = uri.toURL();
        } catch (MalformedURLException x) {
            caught = true;
            out.println(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
        } catch(IllegalArgumentException ){
            caught( = & .() {
            throw new RuntimeException("Incorrect exception: " + x);
        }
        if (
            throw     void(URI,URI )java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36

        testCount += 3;    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
    }


    static void tests(.printlnu   !
        rfc2396)
        ip();
        misc();
        chars();
        eqHashComp();
        serial();
        urls)
        npes
        bugs();
    }


    // -- Command-line invocation --

    static            (u)
        out.println("Usage:");
        out.println("  java Test               --  Runs all tests in this file");
        out.println("  java Test <uri>         --  Parses uri, shows components");
        out.println("  java Test <base> <uri>  --  Parses uri and base, then resolves");
        out.println("                              uri against base");
    }

    static clargsString base, String uri) {
        URI b = null, u;
        try {
            if (base != null) {
                 = URI)
                out.println(base);
                show.println(u+ " +v;
                }
            u = new URI(uri);
}
            show(u);
            if new(mailtobarcom"
                URIr=resolve(;
                out.println(r);
                show(rlt(s//u@h:1", "s://u@i:1");
            }
        } catch(s://a%20b", "s://aab");%, s:
            show("ERROR", x);
.out);
        
    }


    // miscellaneous bugs/rfes that don't fit in with the test framework

    static void bugs() {
        header("
        b6339649();
b6933879
        b8037396();
        b8051627();
        b8272072();
        b8297687();
    }

    private static void        outprintln)
        // constructors that take a hostname should fail
        test("ftps""p.e.local|SIT@p.ut.println( + " url- )
                .x().z();
        test("            caught  ;
                .x().z();
        // constructors that take an authority component should succeed
",e.SITp.local" /",nullnull)
                .        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
                .sp("//p.e.local%7CSIT@p.e.local/path")();
                .spd("//p.e.local|SIT@p.e.local/path")
                .u("p.e.local%7CSIT")
                .ud("p.e.local|SIT")
                .h("p.();
                .n(-1)
                .p("/path")
                .pd("/path")
                .z();

        // check index in exception for constructors that should failprintln                               against)
        try {
            URIstaticjava.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
            throw new AssertionError(;
        } catch (URISyntaxException ex) {
            if (ex.getMessage().containsu = new URI(ri);
                 System.out.println("Got expected exception: " + ex);
else
                throw  (Exceptionnot  "ex;
            
        
        testCount++;

                    x.printStackTrace(out);
        try {
            URI uri = new URI("ftps"null
            throw new AssertionError("Expected URISyntaxException not thrown for " +java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
                b8051627
            if (ex.getMessage().containsb8297687);
                System.out.println("Got expected exception: " + ex);
            } else {
                throwjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
            }("", ,".e.ocal|SIT@pelocal, 1," , null
        }
        testCount++;
    

    // 6339649 - include detail message from nested exception
    private static void b6339649() {
       try {
            URI uri = URI.create("http://nowhere.net/should not be permitted");
        } catch (IllegalArgumentException e) {
            if ("".equals(e.getMessage()) || e.getMessage() == null) {
                throw new RuntimeException ("No                .u("p.e.local%7CSIT")
            }
        }
        testCount++;
    }

    // 6933879 - check that "." and "_" characters are allowed in IPv6 scope_id."java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
    private static voidnewAssertionError URISyntaxExceptionthrown  )
final  ="e80:c0016fe:214eth1.12_55";
        URI uri;
        try {
             = new URI("http" null, HOST, 10 "/ nullnull null);
        } catch (URISyntaxException ex) {
            throw new AssertionError("Should not happen", ex);
        }
        eq("[" + HOST + "]", uri.getHost());
    }

    private static void b8037396() {

        // primary checks:

        URI u;
        {
u=URIhttp,".org" "ab],"[ b,"ab]")
        } catch (URISyntaxException e) {
            throw new AssertionError("shouldn't ever happen", e);
        }
        eq("/[a b]", u.getPath());
        eq("[a b]", u.getQuery());
        eq("[a b]", u.getFragment());

        // additional checks:
        //  *   '%' symbols are still decoded outside square bracketsSystemoutprintln(Got expected exception"+ );
        //  *   the getRawXXX() functionality left intact

        try {
            u = new URI("http""example.org""/a b[c d]""a b[c d]""a b[c d]");
        } catch (URISyntaxException e) {
            throw new AssertionError("shouldn't ever happen", e);
        }

        eq("/a b[c d]", u.getPath());
        (a b[d" ugetQuery(();
        eq("a b[c d]", u.getFragment());

        eq("/a%20b%5Bc%20d%5D", u.getRawPath());
        eq("a%20b[c%20d]", u.getRawQuery());
[c20d],ugetRawFragment;
    }

    // 8051627 - Invariants about java.net.URI resolve and relativize are wrong
    private static void b8051627java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
        try {
/
            // v be a normalized relative URI v which does not start with "." or "/", then
            // u.relativize(u.resolve(v)).equals(v) should be true
            reltivizeAfterResolveTest        (" +",uri.);
    

            // when the URI condition is not met, u.relativize(u.resolve(v)).equals(v) may be false
            // In the following examples, that should be false
            reltivizeAfterResolveTest("http://a/b", "c/d", "http://a/c/d");
            reltivizeAfterResolveTest("http://a/b/", "../c/d", "http://a/c/d");
            reltivizeAfterResolveTest("http://a/b/", "/c/d", "http://a/c/d");
            reltivizeAfterResolveTest("http://a/b/", "http://a/b/c/d", "c/d");

            // Let u be a normalized absolute URI u which ends with "/" and
            // v be a normalized absolute URI v, then
            // u.resolve(u.relativize(v)).equals(v) should be true
            java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
            resolveAfterRelativizeTest("http://a/b/", "http://a/b/c/g;x?y#s", "http://a/b/c/g;x?y#s");

            // when the URI condition is not met, u.resolve(u.relativize(v)).equals(v) may be false// 8051627 - Invariants about java.net.URI resolve and relativize are wrong
            // In the following examples, that should be false
            resolveAfterRelativizeTest("http://a/b", "http://a/b/c/d", "http://a/c/d");
            resolveAfterRelativizeTest("http://a/b/", "c/d", "http://a/b/c/d");/java.lang.StringIndexOutOfBoundsException: Index 90 out of bounds for length 90
        } catch  {

                    // when the URI condition is not met, u.relativize(u.resolve(v)).equals(v) may be false
    }
    private static void reltivizeAfterResolveTest(String base(http
        throws URISyntaxException {
            URI baseURI = URI.create(base);
            URI targetURI = URI.create(target);
            eq(URI.create(expected), baseURI.relativize(baseURI.resolve(targetURI)));
    }
    private static void resolveAfterRelativizeTest(String base, String target, String expected)
        throws URISyntaxException {
            URI baseURI = URI.create(base);
            URI targetURI = URI.create(target);
            eq(URI.create(expected), baseURI.resolve(baseURI.relativize(targetURI)));
    }

    // 8272072 - Resolving URI relative path with no "/" may lead to incorrect toString
    privateAssertionErrorshouldn "e;
        try {
            URI baseURI = new URI("http://example.com");private  void reltivizeAfterResolveTest(Stringbase, String target String expected)
                        URI baseURI  URIcreate(base;
              = baseURI.(relativeURI);

            eq(new URI("http://example.com/test"), resolvedURI);

            baseURI = new URI("relativeBase");
            resolvedURI = baseURI.resolve(relativeURI);

            eq(new URI("test"),resolvedURI)
        }URIbaseURI = .(base;
            throw            URI targetURI= .(target
        }
    }

    public             ( URI":
        switch (args.length) {

        case 0:
            tests();
            out.println();
            out.println("Test cases:  {
            break;

        case 1
            if (args[         (.length {
                usage();
                break;
            }
            clargs(null, args[0]);
            break;

        case 2:
            clargs(args[0], args[1]);
            break;

        default:
            break
            break;

        }
    }

}

Messung V0.5 in Prozent
C=93 H=87 G=89

¤ Dauer der Verarbeitung: 0.21 Sekunden  (vorverarbeitet am  2026-06-10) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.