1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.security.*; 25 import java.security.cert.*; 26 import javax.crypto.*; 27 import javax.net.ssl.*; 28 import javax.security.auth.login.*; 29 import java.lang.reflect.*; 30 import java.util.Arrays; 31 32 /* 33 * @test 34 * @bug 4985694 35 * @summary Incomplete spec for most of the getInstances 36 */ 37 /** 38 * A simple test to see what is being thrown when null Strings are passed 39 * to the various getInstance() methods. 40 * 41 * These tests use various algorithm names that don't exist (e.g. "FOO" 42 * Ciphers). Just need something non-null for testing, as the tests will throw 43 * exceptions before trying to instantiate a real object. 44 */ 45 public class GetInstanceNullsEmpties { 46 47 private static final Provider SUN = Security.getProvider("SUN"); 48 49 /* 50 * See if there are more than "expected" number of getInstance() methods, 51 * which will indicate to developers that this test needs an update. 52 */ checkNewMethods(Class<?> clazz, int expected)53 private static void checkNewMethods(Class<?> clazz, int expected) 54 throws Exception { 55 56 long found = Arrays.stream(clazz.getMethods()) 57 .filter(name -> name.getName().equals("getInstance")) 58 .count(); 59 60 if (found != expected) { 61 throw new Exception("Number of getInstance() mismatch: " 62 + expected + " expected, " + found + " found"); 63 } 64 } 65 66 /** 67 * Main loop. 68 */ main(String[] args)69 public static void main(String[] args) throws Exception { 70 71 /* 72 * JCA 73 */ 74 testAlgorithmParameterGenerator(); 75 testAlgorithmParameters(); 76 testCertificateFactory(); 77 testCertPathBuilder(); 78 testCertPathValidator(); 79 testCertStore(); 80 testKeyFactory(); 81 testKeyPairGenerator(); 82 testKeyStore(); 83 testMessageDigest(); 84 testPolicy(); 85 testSecureRandom(); 86 testSignature(); 87 88 /* 89 * JCE 90 */ 91 testCipher(); 92 testExemptionMechanism(); 93 testKeyAgreement(); 94 testKeyGenerator(); 95 testMac(); 96 testSecretKeyFactory(); 97 98 /* 99 * JSSE 100 */ 101 testKeyManagerFactory(); 102 testSSLContext(); 103 testTrustManagerFactory(); 104 105 /* 106 * JGSS 107 * 108 * KeyTab.getInstance doesn't take algorithm names, so we'll 109 * ignore this one. 110 */ 111 testConfiguration(); 112 113 System.out.println("\nTEST PASSED!"); 114 } 115 getInstance(Class clazz, Class... args)116 private static Method getInstance(Class clazz, Class... args) 117 throws Exception { 118 boolean firstPrinted = false; 119 120 System.out.print("\n" + clazz.getName() + "("); 121 for (Class c : args) { 122 System.out.print(firstPrinted 123 ? ", " + c.getName() : c.getName()); 124 firstPrinted = true; 125 } 126 System.out.println("):"); 127 128 return clazz.getMethod("getInstance", args); 129 } 130 run(Method m, Class expectedException, Object... args)131 private static void run(Method m, Class expectedException, 132 Object... args) throws Exception { 133 134 try { 135 m.invoke(null, args); 136 throw new Exception("Didn't throw exception"); 137 } catch (InvocationTargetException ite) { 138 Throwable root = ite.getCause(); 139 if (root instanceof Exception) { 140 Exception e = (Exception) root; 141 if (expectedException.isInstance(e)) { 142 System.out.print("OK "); 143 return; 144 } else { 145 System.out.println( 146 "Unexpected InvocationTargetException!"); 147 throw e; 148 } 149 } 150 throw ite; 151 } 152 } 153 154 /* 155 * Constants so lines aren't so long. 156 */ 157 private static final Class STRING = String.class; 158 private static final Class PROVIDER = Provider.class; 159 testAlgorithmParameterGenerator()160 private static void testAlgorithmParameterGenerator() throws Exception { 161 Class clazz = AlgorithmParameterGenerator.class; 162 Method m; 163 164 checkNewMethods(clazz, 3); 165 166 m = getInstance(clazz, STRING); 167 run(m, NullPointerException.class, (Object) null); 168 run(m, NoSuchAlgorithmException.class, ""); 169 170 m = getInstance(clazz, STRING, STRING); 171 run(m, NullPointerException.class, null, "SUN"); 172 run(m, NoSuchAlgorithmException.class, "", "SUN"); 173 run(m, IllegalArgumentException.class, "FOO", null); 174 run(m, IllegalArgumentException.class, "FOO", ""); 175 176 m = getInstance(clazz, STRING, PROVIDER); 177 run(m, NullPointerException.class, null, SUN); 178 run(m, NoSuchAlgorithmException.class, "", SUN); 179 run(m, IllegalArgumentException.class, "FOO", null); 180 } 181 testAlgorithmParameters()182 private static void testAlgorithmParameters() throws Exception { 183 Class clazz = AlgorithmParameters.class; 184 Method m; 185 186 checkNewMethods(clazz, 3); 187 188 m = getInstance(clazz, STRING); 189 run(m, NullPointerException.class, (Object) null); 190 run(m, NoSuchAlgorithmException.class, ""); 191 192 m = getInstance(clazz, STRING, STRING); 193 run(m, NullPointerException.class, null, "SUN"); 194 run(m, NoSuchAlgorithmException.class, "", "SUN"); 195 run(m, IllegalArgumentException.class, "FOO", null); 196 run(m, IllegalArgumentException.class, "FOO", ""); 197 198 m = getInstance(clazz, STRING, PROVIDER); 199 run(m, NullPointerException.class, null, SUN); 200 run(m, NoSuchAlgorithmException.class, "", SUN); 201 run(m, IllegalArgumentException.class, "FOO", null); 202 } 203 testCertPathBuilder()204 private static void testCertPathBuilder() throws Exception { 205 Class clazz = CertPathBuilder.class; 206 Method m; 207 208 checkNewMethods(clazz, 3); 209 210 m = getInstance(clazz, STRING); 211 run(m, NullPointerException.class, (Object) null); 212 run(m, NoSuchAlgorithmException.class, ""); 213 214 m = getInstance(clazz, STRING, STRING); 215 run(m, NullPointerException.class, null, "SUN"); 216 run(m, NoSuchAlgorithmException.class, "", "SUN"); 217 run(m, IllegalArgumentException.class, "FOO", null); 218 run(m, IllegalArgumentException.class, "FOO", ""); 219 220 m = getInstance(clazz, STRING, PROVIDER); 221 run(m, NullPointerException.class, null, SUN); 222 run(m, NoSuchAlgorithmException.class, "", SUN); 223 run(m, IllegalArgumentException.class, "FOO", null); 224 } 225 testCertPathValidator()226 private static void testCertPathValidator() throws Exception { 227 Class clazz = CertPathValidator.class; 228 Method m; 229 230 checkNewMethods(clazz, 3); 231 232 m = getInstance(clazz, STRING); 233 run(m, NullPointerException.class, (Object) null); 234 run(m, NoSuchAlgorithmException.class, ""); 235 236 m = getInstance(clazz, STRING, STRING); 237 run(m, NullPointerException.class, null, "SUN"); 238 run(m, NoSuchAlgorithmException.class, "", "SUN"); 239 run(m, IllegalArgumentException.class, "FOO", null); 240 run(m, IllegalArgumentException.class, "FOO", ""); 241 242 m = getInstance(clazz, STRING, PROVIDER); 243 run(m, NullPointerException.class, null, SUN); 244 run(m, NoSuchAlgorithmException.class, "", SUN); 245 run(m, IllegalArgumentException.class, "FOO", null); 246 } 247 testCertStore()248 private static void testCertStore() throws Exception { 249 Class clazz = CertStore.class; 250 Method m; 251 CertStoreParameters csp = () -> null; 252 253 checkNewMethods(clazz, 3); 254 255 m = getInstance(clazz, STRING, CertStoreParameters.class); 256 run(m, NullPointerException.class, (Object) null, csp); 257 run(m, NoSuchAlgorithmException.class, "", csp); 258 259 m = getInstance(clazz, STRING, CertStoreParameters.class, STRING); 260 run(m, NullPointerException.class, null, csp, "SUN"); 261 run(m, NoSuchAlgorithmException.class, "", csp, "SUN"); 262 run(m, IllegalArgumentException.class, "FOO", csp, null); 263 run(m, IllegalArgumentException.class, "FOO", csp, ""); 264 265 m = getInstance(clazz, STRING, CertStoreParameters.class, PROVIDER); 266 run(m, NullPointerException.class, null, csp, SUN); 267 run(m, NoSuchAlgorithmException.class, "", csp, SUN); 268 run(m, IllegalArgumentException.class, "FOO", csp, null); 269 } 270 testCertificateFactory()271 private static void testCertificateFactory() throws Exception { 272 Class clazz = CertificateFactory.class; 273 Method m; 274 275 checkNewMethods(clazz, 3); 276 277 m = getInstance(clazz, STRING); 278 run(m, NullPointerException.class, (Object) null); 279 run(m, CertificateException.class, ""); 280 281 m = getInstance(clazz, STRING, STRING); 282 run(m, NullPointerException.class, null, "SUN"); 283 run(m, CertificateException.class, "", "SUN"); 284 run(m, IllegalArgumentException.class, "FOO", null); 285 run(m, IllegalArgumentException.class, "FOO", ""); 286 287 m = getInstance(clazz, STRING, PROVIDER); 288 run(m, NullPointerException.class, null, SUN); 289 run(m, CertificateException.class, "", SUN); 290 run(m, IllegalArgumentException.class, "FOO", null); 291 } 292 testCipher()293 private static void testCipher() throws Exception { 294 Class clazz = Cipher.class; 295 Method m; 296 297 checkNewMethods(clazz, 3); 298 299 /* 300 * Note the Cipher API is spec'd to throw a NoSuchAlgorithmException 301 * for a null transformation. 302 */ 303 m = getInstance(clazz, STRING); 304 run(m, NoSuchAlgorithmException.class, (Object) null); 305 run(m, NoSuchAlgorithmException.class, ""); 306 307 m = getInstance(clazz, STRING, STRING); 308 run(m, NoSuchAlgorithmException.class, null, "SUN"); 309 run(m, NoSuchAlgorithmException.class, "", "SUN"); 310 run(m, IllegalArgumentException.class, "FOO", null); 311 run(m, IllegalArgumentException.class, "FOO", ""); 312 313 m = getInstance(clazz, STRING, PROVIDER); 314 run(m, NoSuchAlgorithmException.class, null, SUN); 315 run(m, NoSuchAlgorithmException.class, "", SUN); 316 run(m, IllegalArgumentException.class, "FOO", null); 317 } 318 testConfiguration()319 private static void testConfiguration() throws Exception { 320 Class clazz = Configuration.class; 321 Method m; 322 Configuration.Parameters cp = new Configuration.Parameters() { 323 }; 324 325 checkNewMethods(clazz, 3); 326 327 m = getInstance(clazz, STRING, Configuration.Parameters.class); 328 run(m, NullPointerException.class, (Object) null, cp); 329 run(m, NoSuchAlgorithmException.class, "", cp); 330 331 m = getInstance(clazz, STRING, Configuration.Parameters.class, STRING); 332 run(m, NullPointerException.class, null, cp, "SUN"); 333 run(m, NoSuchAlgorithmException.class, "", cp, "SUN"); 334 run(m, IllegalArgumentException.class, "FOO", cp, null); 335 run(m, IllegalArgumentException.class, "FOO", cp, ""); 336 337 m = getInstance(clazz, STRING, Configuration.Parameters.class, 338 PROVIDER); 339 run(m, NullPointerException.class, null, cp, SUN); 340 run(m, NoSuchAlgorithmException.class, "", cp, SUN); 341 run(m, IllegalArgumentException.class, "FOO", cp, null); 342 } 343 testExemptionMechanism()344 private static void testExemptionMechanism() throws Exception { 345 Class clazz = ExemptionMechanism.class; 346 Method m; 347 348 checkNewMethods(clazz, 3); 349 350 m = getInstance(clazz, STRING); 351 run(m, NullPointerException.class, (Object) null); 352 run(m, NoSuchAlgorithmException.class, ""); 353 354 m = getInstance(clazz, STRING, STRING); 355 run(m, NullPointerException.class, null, "SUN"); 356 run(m, NoSuchAlgorithmException.class, "", "SUN"); 357 run(m, IllegalArgumentException.class, "FOO", null); 358 run(m, IllegalArgumentException.class, "FOO", ""); 359 360 m = getInstance(clazz, STRING, PROVIDER); 361 run(m, NullPointerException.class, null, SUN); 362 run(m, NoSuchAlgorithmException.class, "", SUN); 363 run(m, IllegalArgumentException.class, "FOO", null); 364 } 365 testKeyAgreement()366 private static void testKeyAgreement() throws Exception { 367 Class clazz = KeyAgreement.class; 368 Method m; 369 370 checkNewMethods(clazz, 3); 371 372 m = getInstance(clazz, STRING); 373 run(m, NullPointerException.class, (Object) null); 374 run(m, NoSuchAlgorithmException.class, ""); 375 376 m = getInstance(clazz, STRING, STRING); 377 run(m, NullPointerException.class, null, "SUN"); 378 run(m, NoSuchAlgorithmException.class, "", "SUN"); 379 run(m, IllegalArgumentException.class, "FOO", null); 380 run(m, IllegalArgumentException.class, "FOO", ""); 381 382 m = getInstance(clazz, STRING, PROVIDER); 383 run(m, NullPointerException.class, null, SUN); 384 run(m, NoSuchAlgorithmException.class, "", SUN); 385 run(m, IllegalArgumentException.class, "FOO", null); 386 } 387 testKeyFactory()388 private static void testKeyFactory() throws Exception { 389 Class clazz = KeyFactory.class; 390 Method m; 391 392 checkNewMethods(clazz, 3); 393 394 m = getInstance(clazz, STRING); 395 run(m, NullPointerException.class, (Object) null); 396 run(m, NoSuchAlgorithmException.class, ""); 397 398 m = getInstance(clazz, STRING, STRING); 399 run(m, NullPointerException.class, null, "SUN"); 400 run(m, NoSuchAlgorithmException.class, "", "SUN"); 401 run(m, IllegalArgumentException.class, "FOO", null); 402 run(m, IllegalArgumentException.class, "FOO", ""); 403 404 m = getInstance(clazz, STRING, PROVIDER); 405 run(m, NullPointerException.class, null, SUN); 406 run(m, NoSuchAlgorithmException.class, "", SUN); 407 run(m, IllegalArgumentException.class, "FOO", null); 408 } 409 testKeyGenerator()410 private static void testKeyGenerator() throws Exception { 411 Class clazz = KeyGenerator.class; 412 Method m; 413 414 checkNewMethods(clazz, 3); 415 416 m = getInstance(clazz, STRING); 417 run(m, NullPointerException.class, (Object) null); 418 run(m, NoSuchAlgorithmException.class, ""); 419 420 m = getInstance(clazz, STRING, STRING); 421 run(m, NullPointerException.class, null, "SUN"); 422 run(m, NoSuchAlgorithmException.class, "", "SUN"); 423 run(m, IllegalArgumentException.class, "FOO", null); 424 run(m, IllegalArgumentException.class, "FOO", ""); 425 426 m = getInstance(clazz, STRING, PROVIDER); 427 run(m, NullPointerException.class, null, SUN); 428 run(m, NoSuchAlgorithmException.class, "", SUN); 429 run(m, IllegalArgumentException.class, "FOO", null); 430 } 431 testKeyManagerFactory()432 private static void testKeyManagerFactory() throws Exception { 433 Class clazz = KeyManagerFactory.class; 434 Method m; 435 436 checkNewMethods(clazz, 3); 437 438 m = getInstance(clazz, STRING); 439 run(m, NullPointerException.class, (Object) null); 440 run(m, NoSuchAlgorithmException.class, ""); 441 442 m = getInstance(clazz, STRING, STRING); 443 run(m, NullPointerException.class, null, "SUN"); 444 run(m, NoSuchAlgorithmException.class, "", "SUN"); 445 run(m, IllegalArgumentException.class, "FOO", null); 446 run(m, IllegalArgumentException.class, "FOO", ""); 447 448 m = getInstance(clazz, STRING, PROVIDER); 449 run(m, NullPointerException.class, null, SUN); 450 run(m, NoSuchAlgorithmException.class, "", SUN); 451 run(m, IllegalArgumentException.class, "FOO", null); 452 } 453 testKeyPairGenerator()454 private static void testKeyPairGenerator() throws Exception { 455 Class clazz = KeyPairGenerator.class; 456 Method m; 457 458 checkNewMethods(clazz, 3); 459 460 m = getInstance(clazz, STRING); 461 run(m, NullPointerException.class, (Object) null); 462 run(m, NoSuchAlgorithmException.class, ""); 463 464 m = getInstance(clazz, STRING, STRING); 465 run(m, NullPointerException.class, null, "SUN"); 466 run(m, NoSuchAlgorithmException.class, "", "SUN"); 467 run(m, IllegalArgumentException.class, "FOO", null); 468 run(m, IllegalArgumentException.class, "FOO", ""); 469 470 m = getInstance(clazz, STRING, PROVIDER); 471 run(m, NullPointerException.class, null, SUN); 472 run(m, NoSuchAlgorithmException.class, "", SUN); 473 run(m, IllegalArgumentException.class, "FOO", null); 474 } 475 testKeyStore()476 private static void testKeyStore() throws Exception { 477 Class clazz = KeyStore.class; 478 Method m; 479 480 /* 481 * There are actually two additional getInstance() methods with File 482 * as the first parameter. 483 */ 484 checkNewMethods(clazz, 5); 485 486 m = getInstance(clazz, STRING); 487 run(m, NullPointerException.class, (Object) null); 488 run(m, KeyStoreException.class, ""); 489 490 m = getInstance(clazz, STRING, STRING); 491 run(m, NullPointerException.class, null, "SUN"); 492 run(m, KeyStoreException.class, "", "SUN"); 493 run(m, IllegalArgumentException.class, "FOO", null); 494 run(m, IllegalArgumentException.class, "FOO", ""); 495 496 m = getInstance(clazz, STRING, PROVIDER); 497 run(m, NullPointerException.class, null, SUN); 498 run(m, KeyStoreException.class, "", SUN); 499 run(m, IllegalArgumentException.class, "FOO", null); 500 } 501 testMac()502 private static void testMac() throws Exception { 503 Class clazz = Mac.class; 504 Method m; 505 506 checkNewMethods(clazz, 3); 507 508 m = getInstance(clazz, STRING); 509 run(m, NullPointerException.class, (Object) null); 510 run(m, NoSuchAlgorithmException.class, ""); 511 512 m = getInstance(clazz, STRING, STRING); 513 run(m, NullPointerException.class, null, "SUN"); 514 run(m, NoSuchAlgorithmException.class, "", "SUN"); 515 run(m, IllegalArgumentException.class, "FOO", null); 516 run(m, IllegalArgumentException.class, "FOO", ""); 517 518 m = getInstance(clazz, STRING, PROVIDER); 519 run(m, NullPointerException.class, null, SUN); 520 run(m, NoSuchAlgorithmException.class, "", SUN); 521 run(m, IllegalArgumentException.class, "FOO", null); 522 } 523 testMessageDigest()524 private static void testMessageDigest() throws Exception { 525 Class clazz = MessageDigest.class; 526 Method m; 527 528 checkNewMethods(clazz, 3); 529 530 m = getInstance(clazz, STRING); 531 run(m, NullPointerException.class, (Object) null); 532 run(m, NoSuchAlgorithmException.class, ""); 533 534 m = getInstance(clazz, STRING, STRING); 535 run(m, NullPointerException.class, null, "SUN"); 536 run(m, NoSuchAlgorithmException.class, "", "SUN"); 537 run(m, IllegalArgumentException.class, "FOO", null); 538 run(m, IllegalArgumentException.class, "FOO", ""); 539 540 m = getInstance(clazz, STRING, PROVIDER); 541 run(m, NullPointerException.class, null, SUN); 542 run(m, NoSuchAlgorithmException.class, "", SUN); 543 run(m, IllegalArgumentException.class, "FOO", null); 544 } 545 testPolicy()546 private static void testPolicy() throws Exception { 547 Class clazz = Policy.class; 548 Method m; 549 Policy.Parameters pp = new Policy.Parameters() { 550 }; 551 552 checkNewMethods(clazz, 3); 553 554 m = getInstance(clazz, STRING, Policy.Parameters.class); 555 run(m, NullPointerException.class, (Object) null, pp); 556 run(m, NoSuchAlgorithmException.class, "", pp); 557 558 m = getInstance(clazz, STRING, Policy.Parameters.class, STRING); 559 run(m, NullPointerException.class, null, pp, "SUN"); 560 run(m, NoSuchAlgorithmException.class, "", pp, "SUN"); 561 run(m, IllegalArgumentException.class, "FOO", pp, null); 562 run(m, IllegalArgumentException.class, "FOO", pp, ""); 563 564 m = getInstance(clazz, STRING, Policy.Parameters.class, PROVIDER); 565 run(m, NullPointerException.class, null, pp, SUN); 566 run(m, NoSuchAlgorithmException.class, "", pp, SUN); 567 run(m, IllegalArgumentException.class, "FOO", pp, null); 568 } 569 testSSLContext()570 private static void testSSLContext() throws Exception { 571 Class clazz = SSLContext.class; 572 Method m; 573 574 checkNewMethods(clazz, 3); 575 576 m = getInstance(clazz, STRING); 577 run(m, NullPointerException.class, (Object) null); 578 run(m, NoSuchAlgorithmException.class, ""); 579 580 m = getInstance(clazz, STRING, STRING); 581 run(m, NullPointerException.class, null, "SUN"); 582 run(m, NoSuchAlgorithmException.class, "", "SUN"); 583 run(m, IllegalArgumentException.class, "FOO", null); 584 run(m, IllegalArgumentException.class, "FOO", ""); 585 586 m = getInstance(clazz, STRING, PROVIDER); 587 run(m, NullPointerException.class, null, SUN); 588 run(m, NoSuchAlgorithmException.class, "", SUN); 589 run(m, IllegalArgumentException.class, "FOO", null); 590 } 591 testSecretKeyFactory()592 private static void testSecretKeyFactory() throws Exception { 593 Class clazz = SecretKeyFactory.class; 594 Method m; 595 596 checkNewMethods(clazz, 3); 597 598 m = getInstance(clazz, STRING); 599 run(m, NullPointerException.class, (Object) null); 600 run(m, NoSuchAlgorithmException.class, ""); 601 602 m = getInstance(clazz, STRING, STRING); 603 run(m, NullPointerException.class, null, "SUN"); 604 run(m, NoSuchAlgorithmException.class, "", "SUN"); 605 run(m, IllegalArgumentException.class, "FOO", null); 606 run(m, IllegalArgumentException.class, "FOO", ""); 607 608 m = getInstance(clazz, STRING, PROVIDER); 609 run(m, NullPointerException.class, null, SUN); 610 run(m, NoSuchAlgorithmException.class, "", SUN); 611 run(m, IllegalArgumentException.class, "FOO", null); 612 } 613 testSecureRandom()614 private static void testSecureRandom() throws Exception { 615 Class clazz = SecureRandom.class; 616 Method m; 617 SecureRandomParameters srp = new SecureRandomParameters() { 618 }; 619 620 checkNewMethods(clazz, 6); 621 622 m = getInstance(clazz, STRING); 623 run(m, NullPointerException.class, (Object) null); 624 run(m, NoSuchAlgorithmException.class, ""); 625 626 m = getInstance(clazz, STRING, STRING); 627 run(m, NullPointerException.class, null, "SUN"); 628 run(m, NoSuchAlgorithmException.class, "", "SUN"); 629 run(m, IllegalArgumentException.class, "FOO", null); 630 run(m, IllegalArgumentException.class, "FOO", ""); 631 632 m = getInstance(clazz, STRING, PROVIDER); 633 run(m, NullPointerException.class, null, SUN); 634 run(m, NoSuchAlgorithmException.class, "", SUN); 635 run(m, IllegalArgumentException.class, "FOO", null); 636 637 m = getInstance(clazz, STRING, SecureRandomParameters.class); 638 run(m, NullPointerException.class, (Object) null, srp); 639 run(m, NoSuchAlgorithmException.class, "", srp); 640 641 m = getInstance(clazz, STRING, SecureRandomParameters.class, STRING); 642 run(m, NullPointerException.class, null, srp, "SUN"); 643 run(m, NoSuchAlgorithmException.class, "", srp, "SUN"); 644 run(m, IllegalArgumentException.class, "FOO", srp, null); 645 run(m, IllegalArgumentException.class, "FOO", srp, ""); 646 647 m = getInstance(clazz, STRING, SecureRandomParameters.class, PROVIDER); 648 run(m, NullPointerException.class, null, srp, SUN); 649 run(m, NoSuchAlgorithmException.class, "", srp, SUN); 650 run(m, IllegalArgumentException.class, "FOO", srp, null); 651 } 652 testSignature()653 private static void testSignature() throws Exception { 654 Class clazz = Signature.class; 655 Method m; 656 657 checkNewMethods(clazz, 3); 658 659 m = getInstance(clazz, STRING); 660 run(m, NullPointerException.class, (Object) null); 661 run(m, NoSuchAlgorithmException.class, ""); 662 663 m = getInstance(clazz, STRING, STRING); 664 run(m, NullPointerException.class, null, "SUN"); 665 run(m, NoSuchAlgorithmException.class, "", "SUN"); 666 run(m, IllegalArgumentException.class, "FOO", null); 667 run(m, IllegalArgumentException.class, "FOO", ""); 668 669 m = getInstance(clazz, STRING, PROVIDER); 670 run(m, NullPointerException.class, null, SUN); 671 run(m, NoSuchAlgorithmException.class, "", SUN); 672 run(m, IllegalArgumentException.class, "FOO", null); 673 } 674 testTrustManagerFactory()675 private static void testTrustManagerFactory() throws Exception { 676 Class clazz = TrustManagerFactory.class; 677 Method m; 678 679 checkNewMethods(clazz, 3); 680 681 m = getInstance(clazz, STRING); 682 run(m, NullPointerException.class, (Object) null); 683 run(m, NoSuchAlgorithmException.class, ""); 684 685 m = getInstance(clazz, STRING, STRING); 686 run(m, NullPointerException.class, null, "SUN"); 687 run(m, NoSuchAlgorithmException.class, "", "SUN"); 688 run(m, IllegalArgumentException.class, "FOO", null); 689 run(m, IllegalArgumentException.class, "FOO", ""); 690 691 m = getInstance(clazz, STRING, PROVIDER); 692 run(m, NullPointerException.class, null, SUN); 693 run(m, NoSuchAlgorithmException.class, "", SUN); 694 run(m, IllegalArgumentException.class, "FOO", null); 695 } 696 } 697