1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
/*
* Copyright (c) 2003, 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 FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with 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
* @bug 4496095
* @summary Add constructors for exception chaining to java.security Exceptions
*/
import java.security.*;
import java.security.cert.*;
import java.security.spec.*;
import javax.net.ssl.*;
public class ChainingConstructors {
private static final String MSG = "msg";
private static Exception cause = new Exception("cause");
public static void main(String[] args) throws Exception {
SecurityException se = new SecurityException(cause);
if (!se.getCause().equals(cause)) {
throw new SecurityException("Test 1 failed");
}
se = new SecurityException(MSG, cause);
if (!se.getMessage().equals(MSG) || !se.getCause().equals(cause)) {
throw new SecurityException("Test 1 failed");
}
DigestException de = new DigestException(cause);
if (!de.getCause().equals(cause)) {
throw new SecurityException("Test 2 failed");
}
de = new DigestException(MSG, cause);
if (!de.getMessage().equals(MSG) || !de.getCause().equals(cause)) {
throw new SecurityException("Test 2 failed");
}
GeneralSecurityException gse = new GeneralSecurityException(cause);
if (!gse.getCause().equals(cause)) {
throw new SecurityException("Test 3 failed");
}
gse = new GeneralSecurityException(MSG, cause);
if (!gse.getMessage().equals(MSG) || !gse.getCause().equals(cause)) {
throw new SecurityException("Test 3 failed");
}
InvalidAlgorithmParameterException iape =
new InvalidAlgorithmParameterException(cause);
if (!iape.getCause().equals(cause)) {
throw new SecurityException("Test 4 failed");
}
iape = new InvalidAlgorithmParameterException(MSG, cause);
if (!iape.getMessage().equals(MSG) || !iape.getCause().equals(cause)) {
throw new SecurityException("Test 4 failed");
}
InvalidKeyException ike = new InvalidKeyException(cause);
if (!ike.getCause().equals(cause)) {
throw new SecurityException("Test 5 failed");
}
ike = new InvalidKeyException(MSG, cause);
if (!ike.getMessage().equals(MSG) || !ike.getCause().equals(cause)) {
throw new SecurityException("Test 5 failed");
}
InvalidKeySpecException ikse = new InvalidKeySpecException(cause);
if (!ikse.getCause().equals(cause)) {
throw new SecurityException("Test 6 failed");
}
ikse = new InvalidKeySpecException(MSG, cause);
if (!ikse.getMessage().equals(MSG) || !ikse.getCause().equals(cause)) {
throw new SecurityException("Test 6 failed");
}
KeyException ke = new KeyException(cause);
if (!ke.getCause().equals(cause)) {
throw new SecurityException("Test 7 failed");
}
ke = new KeyException(MSG, cause);
if (!ke.getMessage().equals(MSG) || !ke.getCause().equals(cause)) {
throw new SecurityException("Test 7 failed");
}
KeyManagementException kme = new KeyManagementException(cause);
if (!kme.getCause().equals(cause)) {
throw new SecurityException("Test 8 failed");
}
kme = new KeyManagementException(MSG, cause);
if (!kme.getMessage().equals(MSG) || !kme.getCause().equals(cause)) {
throw new SecurityException("Test 8 failed");
}
KeyStoreException kse = new KeyStoreException(cause);
if (!kse.getCause().equals(cause)) {
throw new SecurityException("Test 9 failed");
}
kse = new KeyStoreException(MSG, cause);
if (!kse.getMessage().equals(MSG) || !kse.getCause().equals(cause)) {
throw new SecurityException("Test 9 failed");
}
NoSuchAlgorithmException nsae = new NoSuchAlgorithmException(cause);
if (!nsae.getCause().equals(cause)) {
throw new SecurityException("Test 10 failed");
}
nsae = new NoSuchAlgorithmException(MSG, cause);
if (!nsae.getMessage().equals(MSG) || !nsae.getCause().equals(cause)) {
throw new SecurityException("Test 10 failed");
}
ProviderException pe = new ProviderException(cause);
if (!pe.getCause().equals(cause)) {
throw new SecurityException("Test 11 failed");
}
pe = new ProviderException(MSG, cause);
if (!pe.getMessage().equals(MSG) || !pe.getCause().equals(cause)) {
throw new SecurityException("Test 11 failed");
}
SignatureException sige = new SignatureException(cause);
if (!sige.getCause().equals(cause)) {
throw new SecurityException("Test 12 failed");
}
sige = new SignatureException(MSG, cause);
if (!sige.getMessage().equals(MSG) || !sige.getCause().equals(cause)) {
throw new SecurityException("Test 12 failed");
}
CRLException crle = new CRLException(cause);
if (!crle.getCause().equals(cause)) {
throw new SecurityException("Test 13 failed");
}
crle = new CRLException(MSG, cause);
if (!crle.getMessage().equals(MSG) || !crle.getCause().equals(cause)) {
throw new SecurityException("Test 13 failed");
}
CertificateException ce = new CertificateException(cause);
if (!ce.getCause().equals(cause)) {
throw new SecurityException("Test 14 failed");
}
ce = new CertificateException(MSG, cause);
if (!ce.getMessage().equals(MSG) || !ce.getCause().equals(cause)) {
throw new SecurityException("Test 14 failed");
}
CertificateParsingException cpe =
new CertificateParsingException(cause);
if (!cpe.getCause().equals(cause)) {
throw new SecurityException("Test 15 failed");
}
cpe = new CertificateParsingException(MSG, cause);
if (!cpe.getMessage().equals(MSG) || !cpe.getCause().equals(cause)) {
throw new SecurityException("Test 15 failed");
}
CertificateEncodingException cee =
new CertificateEncodingException(cause);
if (!cee.getCause().equals(cause)) {
throw new SecurityException("Test 16 failed");
}
cee = new CertificateEncodingException(MSG, cause);
if (!cee.getMessage().equals(MSG) || !cee.getCause().equals(cause)) {
throw new SecurityException("Test 16 failed");
}
/*
SSLException ssle =
new SSLException(cause);
if (!ssle.getCause().equals(cause)) {
throw new SecurityException("Test 17 failed");
}
ssle =new SSLException(MSG, cause);
if (!ssle.getMessage().equals(MSG) || !ssle.getCause().equals(cause)) {
throw new SecurityException("Test 17 failed");
}
*/
}
}
|