src/java.base/share/classes/java/net/URISyntaxException.java
author alanb
Mon, 29 Apr 2019 09:03:06 +0100
branchniosocketimpl-branch
changeset 57341 733e9746d615
parent 47216 71c04702a3d5
child 57956 e0b8b019d2f5
permissions -rw-r--r--
More cleanup and test improvements
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
     2
 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1334
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1334
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1334
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1334
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1334
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.net;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * Checked exception thrown to indicate that a string could not be parsed as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * URI reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @author Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @see URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
public class URISyntaxException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    extends Exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
{
1334
21b652819b97 6746836: java.net exception classes don't specify serialVersionUID
chegar
parents: 2
diff changeset
    41
    private static final long serialVersionUID = 2137979680897488891L;
21b652819b97 6746836: java.net exception classes don't specify serialVersionUID
chegar
parents: 2
diff changeset
    42
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    private String input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * Constructs an instance from the given input string, reason, and error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * @param  input   The input string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @param  reason  A string explaining why the input could not be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * @param  index   The index at which the parse error occurred,
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
    53
     *                 or {@code -1} if the index is not known
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * @throws  NullPointerException
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
    56
     *          If either the input or reason strings are {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @throws  IllegalArgumentException
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
    59
     *          If the error index is less than {@code -1}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public URISyntaxException(String input, String reason, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        super(reason);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        if ((input == null) || (reason == null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        if (index < -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        this.input = input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        this.index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * Constructs an instance from the given input string and reason.  The
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
    73
     * resulting object will have an error index of {@code -1}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param  input   The input string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param  reason  A string explaining why the input could not be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @throws  NullPointerException
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
    79
     *          If either the input or reason strings are {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public URISyntaxException(String input, String reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        this(input, reason, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Returns the input string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @return  The input string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public String getInput() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Returns a string explaining why the input string could not be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @return  The reason string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public String getReason() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return super.getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Returns an index into the input string of the position at which the
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
   105
     * parse error occurred, or {@code -1} if this position is not known.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @return  The error index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public int getIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Returns a string describing the parse error.  The resulting string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * consists of the reason string followed by a colon character
19069
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
   116
     * ({@code ':'}), a space, and the input string.  If the error index is
1d9cb0d080e3 8021833: javadoc cleanup in java.net
juh
parents: 5506
diff changeset
   117
     * defined then the string {@code " at index "} followed by the index, in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * decimal, is inserted after the reason string and before the colon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @return  A string describing the parse error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public String getMessage() {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 19069
diff changeset
   124
        StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        sb.append(getReason());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (index > -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            sb.append(" at index ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            sb.append(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        sb.append(": ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        sb.append(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
}