test/jdk/java/security/Exceptions/ChainingConstructors.java
author jboes
Fri, 08 Nov 2019 11:15:16 +0000
changeset 59029 3786a0962570
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232853: AuthenticationFilter.Cache::remove may throw ConcurrentModificationException Summary: Change implementation to use iterator instead of plain LinkedList Reviewed-by: dfuchs, vtewari
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4496095
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Add constructors for exception chaining to java.security Exceptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.cert.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.net.ssl.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public class ChainingConstructors {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    private static final String MSG = "msg";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    private static Exception cause = new Exception("cause");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        SecurityException se = new SecurityException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        if (!se.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
            throw new SecurityException("Test 1 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        se = new SecurityException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        if (!se.getMessage().equals(MSG) || !se.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            throw new SecurityException("Test 1 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        DigestException de = new DigestException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        if (!de.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            throw new SecurityException("Test 2 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        de = new DigestException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (!de.getMessage().equals(MSG) || !de.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            throw new SecurityException("Test 2 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        GeneralSecurityException gse = new GeneralSecurityException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        if (!gse.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            throw new SecurityException("Test 3 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        gse = new GeneralSecurityException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        if (!gse.getMessage().equals(MSG) || !gse.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            throw new SecurityException("Test 3 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        InvalidAlgorithmParameterException iape =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                new InvalidAlgorithmParameterException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (!iape.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            throw new SecurityException("Test 4 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        iape = new InvalidAlgorithmParameterException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        if (!iape.getMessage().equals(MSG) || !iape.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            throw new SecurityException("Test 4 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        InvalidKeyException ike = new InvalidKeyException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        if (!ike.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            throw new SecurityException("Test 5 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        ike = new InvalidKeyException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (!ike.getMessage().equals(MSG) || !ike.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            throw new SecurityException("Test 5 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        InvalidKeySpecException ikse = new InvalidKeySpecException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (!ikse.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            throw new SecurityException("Test 6 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        ikse = new InvalidKeySpecException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (!ikse.getMessage().equals(MSG) || !ikse.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            throw new SecurityException("Test 6 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        KeyException ke = new KeyException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        if (!ke.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            throw new SecurityException("Test 7 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        ke = new KeyException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (!ke.getMessage().equals(MSG) || !ke.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            throw new SecurityException("Test 7 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        KeyManagementException kme = new KeyManagementException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (!kme.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            throw new SecurityException("Test 8 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        kme = new KeyManagementException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (!kme.getMessage().equals(MSG) || !kme.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            throw new SecurityException("Test 8 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        KeyStoreException kse = new KeyStoreException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (!kse.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            throw new SecurityException("Test 9 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        kse = new KeyStoreException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (!kse.getMessage().equals(MSG) || !kse.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            throw new SecurityException("Test 9 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        NoSuchAlgorithmException nsae = new NoSuchAlgorithmException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (!nsae.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            throw new SecurityException("Test 10 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        nsae = new NoSuchAlgorithmException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (!nsae.getMessage().equals(MSG) || !nsae.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            throw new SecurityException("Test 10 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        ProviderException pe = new ProviderException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (!pe.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            throw new SecurityException("Test 11 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        pe = new ProviderException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (!pe.getMessage().equals(MSG) || !pe.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            throw new SecurityException("Test 11 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        SignatureException sige = new SignatureException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (!sige.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            throw new SecurityException("Test 12 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        sige = new SignatureException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (!sige.getMessage().equals(MSG) || !sige.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            throw new SecurityException("Test 12 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        CRLException crle = new CRLException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (!crle.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            throw new SecurityException("Test 13 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        crle = new CRLException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (!crle.getMessage().equals(MSG) || !crle.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            throw new SecurityException("Test 13 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        CertificateException ce = new CertificateException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (!ce.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            throw new SecurityException("Test 14 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        ce = new CertificateException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (!ce.getMessage().equals(MSG) || !ce.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            throw new SecurityException("Test 14 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        CertificateParsingException cpe =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                new CertificateParsingException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (!cpe.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            throw new SecurityException("Test 15 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        cpe = new CertificateParsingException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (!cpe.getMessage().equals(MSG) || !cpe.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            throw new SecurityException("Test 15 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        CertificateEncodingException cee =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                new CertificateEncodingException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (!cee.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            throw new SecurityException("Test 16 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        cee = new CertificateEncodingException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (!cee.getMessage().equals(MSG) || !cee.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            throw new SecurityException("Test 16 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        SSLException ssle =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                new SSLException(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (!ssle.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            throw new SecurityException("Test 17 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        ssle =new SSLException(MSG, cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (!ssle.getMessage().equals(MSG) || !ssle.getCause().equals(cause)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            throw new SecurityException("Test 17 failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
}