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 to the 39 * 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 */ 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 */ 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 116 private static Method getInstance(Class clazz, Class... args) throws Exception { 117 boolean firstPrinted = false; 118 119 System.out.print("\n" + clazz.getName() + "("); 120 for (Class c : args) { 121 System.out.print(firstPrinted 122 ? ", " + c.getName() : c.getName()); 123 firstPrinted = true; 124 } 125 System.out.println("):"); 126 127 return clazz.getMethod("getInstance", args); 128 } 129 130 private static void run(Method m, Class expectedException, 131 Object... args) throws Exception { 132 133 try { 134 m.invoke(null, args); 135 throw new Exception("Didn't throw exception"); 136 } catch (InvocationTargetException ite) { 137 Throwable root = ite.getCause(); 138 if (root instanceof Exception) { 139 Exception e = (Exception) root; 140 if (expectedException.isInstance(e)) { 141 System.out.print("OK "); 142 return; 143 } else { 144 System.out.println("Unexpected InvocationTargetException!"); 145 throw e; 146 } 147 } 148 throw ite; 149 } 150 } 151 152 /* 153 * Constants so lines aren't so long. 154 */ 155 private static final Class STRING = String.class; 156 private static final Class PROVIDER = Provider.class; 157 158 private static void testAlgorithmParameterGenerator() throws Exception { 159 Class clazz = AlgorithmParameterGenerator.class; 160 Method m; 161 162 checkNewMethods(clazz, 3); 163 164 m = getInstance(clazz, STRING); 165 run(m, NullPointerException.class, (Object) null); 166 run(m, NoSuchAlgorithmException.class, ""); 167 168 m = getInstance(clazz, STRING, STRING); 169 run(m, NullPointerException.class, null, "SUN"); 170 run(m, NoSuchAlgorithmException.class, "", "SUN"); 171 run(m, IllegalArgumentException.class, "FOO", null); 172 run(m, IllegalArgumentException.class, "FOO", ""); 173 174 m = getInstance(clazz, STRING, PROVIDER); 175 run(m, NullPointerException.class, null, SUN); 176 run(m, NoSuchAlgorithmException.class, "", SUN); 177 run(m, IllegalArgumentException.class, "FOO", null); 178 } 179 180 private static void testAlgorithmParameters() throws Exception { 181 Class clazz = AlgorithmParameters.class; 182 Method m; 183 184 checkNewMethods(clazz, 3); 185 186 m = getInstance(clazz, STRING); 187 run(m, NullPointerException.class, (Object) null); 188 run(m, NoSuchAlgorithmException.class, ""); 189 190 m = getInstance(clazz, STRING, STRING); 191 run(m, NullPointerException.class, null, "SUN"); 192 run(m, NoSuchAlgorithmException.class, "", "SUN"); 193 run(m, IllegalArgumentException.class, "FOO", null); 194 run(m, IllegalArgumentException.class, "FOO", ""); 195 196 m = getInstance(clazz, STRING, PROVIDER); 197 run(m, NullPointerException.class, null, SUN); 198 run(m, NoSuchAlgorithmException.class, "", SUN); 199 run(m, IllegalArgumentException.class, "FOO", null); 200 } 201 202 private static void testCertPathBuilder() throws Exception { 203 Class clazz = CertPathBuilder.class; 204 Method m; 205 206 checkNewMethods(clazz, 3); 207 208 m = getInstance(clazz, STRING); 209 run(m, NullPointerException.class, (Object) null); 210 run(m, NoSuchAlgorithmException.class, ""); 211 212 m = getInstance(clazz, STRING, STRING); 213 run(m, NullPointerException.class, null, "SUN"); 214 run(m, NoSuchAlgorithmException.class, "", "SUN"); 215 run(m, IllegalArgumentException.class, "FOO", null); 216 run(m, IllegalArgumentException.class, "FOO", ""); 217 218 m = getInstance(clazz, STRING, PROVIDER); 219 run(m, NullPointerException.class, null, SUN); 220 run(m, NoSuchAlgorithmException.class, "", SUN); 221 run(m, IllegalArgumentException.class, "FOO", null); 222 } 223 224 private static void testCertPathValidator() throws Exception { 225 Class clazz = CertPathValidator.class; 226 Method m; 227 228 checkNewMethods(clazz, 3); 229 230 m = getInstance(clazz, STRING); 231 run(m, NullPointerException.class, (Object) null); 232 run(m, NoSuchAlgorithmException.class, ""); 233 234 m = getInstance(clazz, STRING, STRING); 235 run(m, NullPointerException.class, null, "SUN"); 236 run(m, NoSuchAlgorithmException.class, "", "SUN"); 237 run(m, IllegalArgumentException.class, "FOO", null); 238 run(m, IllegalArgumentException.class, "FOO", ""); 239 240 m = getInstance(clazz, STRING, PROVIDER); 241 run(m, NullPointerException.class, null, SUN); 242 run(m, NoSuchAlgorithmException.class, "", SUN); 243 run(m, IllegalArgumentException.class, "FOO", null); 244 } 245 246 private static void testCertStore() throws Exception { 247 Class clazz = CertStore.class; 248 Method m; 249 CertStoreParameters csp = () -> null; 250 251 checkNewMethods(clazz, 3); 252 253 m = getInstance(clazz, STRING, CertStoreParameters.class); 254 run(m, NullPointerException.class, (Object) null, csp); 255 run(m, NoSuchAlgorithmException.class, "", csp); 256 257 m = getInstance(clazz, STRING, CertStoreParameters.class, STRING); 258 run(m, NullPointerException.class, null, csp, "SUN"); 259 run(m, NoSuchAlgorithmException.class, "", csp, "SUN"); 260 run(m, IllegalArgumentException.class, "FOO", csp, null); 261 run(m, IllegalArgumentException.class, "FOO", csp, ""); 262 263 m = getInstance(clazz, STRING, CertStoreParameters.class, PROVIDER); 264 run(m, NullPointerException.class, null, csp, SUN); 265 run(m, NoSuchAlgorithmException.class, "", csp, SUN); 266 run(m, IllegalArgumentException.class, "FOO", csp, null); 267 } 268 269 private static void testCertificateFactory() throws Exception { 270 Class clazz = CertificateFactory.class; 271 Method m; 272 273 checkNewMethods(clazz, 3); 274 275 m = getInstance(clazz, STRING); 276 run(m, NullPointerException.class, (Object) null); 277 run(m, CertificateException.class, ""); 278 279 m = getInstance(clazz, STRING, STRING); 280 run(m, NullPointerException.class, null, "SUN"); 281 run(m, CertificateException.class, "", "SUN"); 282 run(m, IllegalArgumentException.class, "FOO", null); 283 run(m, IllegalArgumentException.class, "FOO", ""); 284 285 m = getInstance(clazz, STRING, PROVIDER); 286 run(m, NullPointerException.class, null, SUN); 287 run(m, CertificateException.class, "", SUN); 288 run(m, IllegalArgumentException.class, "FOO", null); 289 } 290 291 private static void testCipher() throws Exception { 292 Class clazz = Cipher.class; 293 Method m; 294 295 checkNewMethods(clazz, 3); 296 297 /* 298 * Note the Cipher API is spec'd to throw a NoSuchAlgorithmException 299 * for a null transformation. 300 */ 301 m = getInstance(clazz, STRING); 302 run(m, NoSuchAlgorithmException.class, (Object) null); 303 run(m, NoSuchAlgorithmException.class, ""); 304 305 m = getInstance(clazz, STRING, STRING); 306 run(m, NoSuchAlgorithmException.class, null, "SUN"); 307 run(m, NoSuchAlgorithmException.class, "", "SUN"); 308 run(m, IllegalArgumentException.class, "FOO", null); 309 run(m, IllegalArgumentException.class, "FOO", ""); 310 311 m = getInstance(clazz, STRING, PROVIDER); 312 run(m, NoSuchAlgorithmException.class, null, SUN); 313 run(m, NoSuchAlgorithmException.class, "", SUN); 314 run(m, IllegalArgumentException.class, "FOO", null); 315 } 316 317 private static void testConfiguration() throws Exception { 318 Class clazz = Configuration.class; 319 Method m; 320 Configuration.Parameters cp = new Configuration.Parameters() { 321 }; 322 323 checkNewMethods(clazz, 3); 324 325 m = getInstance(clazz, STRING, Configuration.Parameters.class); 326 run(m, NullPointerException.class, (Object) null, cp); 327 run(m, NoSuchAlgorithmException.class, "", cp); 328 329 m = getInstance(clazz, STRING, Configuration.Parameters.class, STRING); 330 run(m, NullPointerException.class, null, cp, "SUN"); 331 run(m, NoSuchAlgorithmException.class, "", cp, "SUN"); 332 run(m, IllegalArgumentException.class, "FOO", cp, null); 333 run(m, IllegalArgumentException.class, "FOO", cp, ""); 334 335 m = getInstance(clazz, STRING, Configuration.Parameters.class, 336 PROVIDER); 337 run(m, NullPointerException.class, null, cp, SUN); 338 run(m, NoSuchAlgorithmException.class, "", cp, SUN); 339 run(m, IllegalArgumentException.class, "FOO", cp, null); 340 } 341 342 private static void testExemptionMechanism() throws Exception { 343 Class clazz = ExemptionMechanism.class; 344 Method m; 345 346 checkNewMethods(clazz, 3); 347 348 m = getInstance(clazz, STRING); 349 run(m, NullPointerException.class, (Object) null); 350 run(m, NoSuchAlgorithmException.class, ""); 351 352 m = getInstance(clazz, STRING, STRING); 353 run(m, NullPointerException.class, null, "SUN"); 354 run(m, NoSuchAlgorithmException.class, "", "SUN"); 355 run(m, IllegalArgumentException.class, "FOO", null); 356 run(m, IllegalArgumentException.class, "FOO", ""); 357 358 m = getInstance(clazz, STRING, PROVIDER); 359 run(m, NullPointerException.class, null, SUN); 360 run(m, NoSuchAlgorithmException.class, "", SUN); 361 run(m, IllegalArgumentException.class, "FOO", null); 362 } 363 364 private static void testKeyAgreement() throws Exception { 365 Class clazz = KeyAgreement.class; 366 Method m; 367 368 checkNewMethods(clazz, 3); 369 370 m = getInstance(clazz, STRING); 371 run(m, NullPointerException.class, (Object) null); 372 run(m, NoSuchAlgorithmException.class, ""); 373 374 m = getInstance(clazz, STRING, STRING); 375 run(m, NullPointerException.class, null, "SUN"); 376 run(m, NoSuchAlgorithmException.class, "", "SUN"); 377 run(m, IllegalArgumentException.class, "FOO", null); 378 run(m, IllegalArgumentException.class, "FOO", ""); 379 380 m = getInstance(clazz, STRING, PROVIDER); 381 run(m, NullPointerException.class, null, SUN); 382 run(m, NoSuchAlgorithmException.class, "", SUN); 383 run(m, IllegalArgumentException.class, "FOO", null); 384 } 385 386 private static void testKeyFactory() throws Exception { 387 Class clazz = KeyFactory.class; 388 Method m; 389 390 checkNewMethods(clazz, 3); 391 392 m = getInstance(clazz, STRING); 393 run(m, NullPointerException.class, (Object) null); 394 run(m, NoSuchAlgorithmException.class, ""); 395 396 m = getInstance(clazz, STRING, STRING); 397 run(m, NullPointerException.class, null, "SUN"); 398 run(m, NoSuchAlgorithmException.class, "", "SUN"); 399 run(m, IllegalArgumentException.class, "FOO", null); 400 run(m, IllegalArgumentException.class, "FOO", ""); 401 402 m = getInstance(clazz, STRING, PROVIDER); 403 run(m, NullPointerException.class, null, SUN); 404 run(m, NoSuchAlgorithmException.class, "", SUN); 405 run(m, IllegalArgumentException.class, "FOO", null); 406 } 407 408 private static void testKeyGenerator() throws Exception { 409 Class clazz = KeyGenerator.class; 410 Method m; 411 412 checkNewMethods(clazz, 3); 413 414 m = getInstance(clazz, STRING); 415 run(m, NullPointerException.class, (Object) null); 416 run(m, NoSuchAlgorithmException.class, ""); 417 418 m = getInstance(clazz, STRING, STRING); 419 run(m, NullPointerException.class, null, "SUN"); 420 run(m, NoSuchAlgorithmException.class, "", "SUN"); 421 run(m, IllegalArgumentException.class, "FOO", null); 422 run(m, IllegalArgumentException.class, "FOO", ""); 423 424 m = getInstance(clazz, STRING, PROVIDER); 425 run(m, NullPointerException.class, null, SUN); 426 run(m, NoSuchAlgorithmException.class, "", SUN); 427 run(m, IllegalArgumentException.class, "FOO", null); 428 } 429 430 private static void testKeyManagerFactory() throws Exception { 431 Class clazz = KeyManagerFactory.class; 432 Method m; 433 434 checkNewMethods(clazz, 3); 435 436 m = getInstance(clazz, STRING); 437 run(m, NullPointerException.class, (Object) null); 438 run(m, NoSuchAlgorithmException.class, ""); 439 440 m = getInstance(clazz, STRING, STRING); 441 run(m, NullPointerException.class, null, "SUN"); 442 run(m, NoSuchAlgorithmException.class, "", "SUN"); 443 run(m, IllegalArgumentException.class, "FOO", null); 444 run(m, IllegalArgumentException.class, "FOO", ""); 445 446 m = getInstance(clazz, STRING, PROVIDER); 447 run(m, NullPointerException.class, null, SUN); 448 run(m, NoSuchAlgorithmException.class, "", SUN); 449 run(m, IllegalArgumentException.class, "FOO", null); 450 } 451 452 private static void testKeyPairGenerator() throws Exception { 453 Class clazz = KeyPairGenerator.class; 454 Method m; 455 456 checkNewMethods(clazz, 3); 457 458 m = getInstance(clazz, STRING); 459 run(m, NullPointerException.class, (Object) null); 460 run(m, NoSuchAlgorithmException.class, ""); 461 462 m = getInstance(clazz, STRING, STRING); 463 run(m, NullPointerException.class, null, "SUN"); 464 run(m, NoSuchAlgorithmException.class, "", "SUN"); 465 run(m, IllegalArgumentException.class, "FOO", null); 466 run(m, IllegalArgumentException.class, "FOO", ""); 467 468 m = getInstance(clazz, STRING, PROVIDER); 469 run(m, NullPointerException.class, null, SUN); 470 run(m, NoSuchAlgorithmException.class, "", SUN); 471 run(m, IllegalArgumentException.class, "FOO", null); 472 } 473 474 private static void testKeyStore() throws Exception { 475 Class clazz = KeyStore.class; 476 Method m; 477 478 /* 479 * There are actually two additional getInstance() methods with File 480 * as the first parameter. 481 */ 482 checkNewMethods(clazz, 5); 483 484 m = getInstance(clazz, STRING); 485 run(m, NullPointerException.class, (Object) null); 486 run(m, KeyStoreException.class, ""); 487 488 m = getInstance(clazz, STRING, STRING); 489 run(m, NullPointerException.class, null, "SUN"); 490 run(m, KeyStoreException.class, "", "SUN"); 491 run(m, IllegalArgumentException.class, "FOO", null); 492 run(m, IllegalArgumentException.class, "FOO", ""); 493 494 m = getInstance(clazz, STRING, PROVIDER); 495 run(m, NullPointerException.class, null, SUN); 496 run(m, KeyStoreException.class, "", SUN); 497 run(m, IllegalArgumentException.class, "FOO", null); 498 } 499 500 private static void testMac() throws Exception { 501 Class clazz = Mac.class; 502 Method m; 503 504 checkNewMethods(clazz, 3); 505 506 m = getInstance(clazz, STRING); 507 run(m, NullPointerException.class, (Object) null); 508 run(m, NoSuchAlgorithmException.class, ""); 509 510 m = getInstance(clazz, STRING, STRING); 511 run(m, NullPointerException.class, null, "SUN"); 512 run(m, NoSuchAlgorithmException.class, "", "SUN"); 513 run(m, IllegalArgumentException.class, "FOO", null); 514 run(m, IllegalArgumentException.class, "FOO", ""); 515 516 m = getInstance(clazz, STRING, PROVIDER); 517 run(m, NullPointerException.class, null, SUN); 518 run(m, NoSuchAlgorithmException.class, "", SUN); 519 run(m, IllegalArgumentException.class, "FOO", null); 520 } 521 522 private static void testMessageDigest() throws Exception { 523 Class clazz = MessageDigest.class; 524 Method m; 525 526 checkNewMethods(clazz, 3); 527 528 m = getInstance(clazz, STRING); 529 run(m, NullPointerException.class, (Object) null); 530 run(m, NoSuchAlgorithmException.class, ""); 531 532 m = getInstance(clazz, STRING, STRING); 533 run(m, NullPointerException.class, null, "SUN"); 534 run(m, NoSuchAlgorithmException.class, "", "SUN"); 535 run(m, IllegalArgumentException.class, "FOO", null); 536 run(m, IllegalArgumentException.class, "FOO", ""); 537 538 m = getInstance(clazz, STRING, PROVIDER); 539 run(m, NullPointerException.class, null, SUN); 540 run(m, NoSuchAlgorithmException.class, "", SUN); 541 run(m, IllegalArgumentException.class, "FOO", null); 542 } 543 544 private static void testPolicy() throws Exception { 545 Class clazz = Policy.class; 546 Method m; 547 Policy.Parameters pp = new Policy.Parameters() { 548 }; 549 550 checkNewMethods(clazz, 3); 551 552 m = getInstance(clazz, STRING, Policy.Parameters.class); 553 run(m, NullPointerException.class, (Object) null, pp); 554 run(m, NoSuchAlgorithmException.class, "", pp); 555 556 m = getInstance(clazz, STRING, Policy.Parameters.class, STRING); 557 run(m, NullPointerException.class, null, pp, "SUN"); 558 run(m, NoSuchAlgorithmException.class, "", pp, "SUN"); 559 run(m, IllegalArgumentException.class, "FOO", pp, null); 560 run(m, IllegalArgumentException.class, "FOO", pp, ""); 561 562 m = getInstance(clazz, STRING, Policy.Parameters.class, PROVIDER); 563 run(m, NullPointerException.class, null, pp, SUN); 564 run(m, NoSuchAlgorithmException.class, "", pp, SUN); 565 run(m, IllegalArgumentException.class, "FOO", pp, null); 566 } 567 568 private static void testSSLContext() throws Exception { 569 Class clazz = SSLContext.class; 570 Method m; 571 572 checkNewMethods(clazz, 3); 573 574 m = getInstance(clazz, STRING); 575 run(m, NullPointerException.class, (Object) null); 576 run(m, NoSuchAlgorithmException.class, ""); 577 578 m = getInstance(clazz, STRING, STRING); 579 run(m, NullPointerException.class, null, "SUN"); 580 run(m, NoSuchAlgorithmException.class, "", "SUN"); 581 run(m, IllegalArgumentException.class, "FOO", null); 582 run(m, IllegalArgumentException.class, "FOO", ""); 583 584 m = getInstance(clazz, STRING, PROVIDER); 585 run(m, NullPointerException.class, null, SUN); 586 run(m, NoSuchAlgorithmException.class, "", SUN); 587 run(m, IllegalArgumentException.class, "FOO", null); 588 } 589 590 private static void testSecretKeyFactory() throws Exception { 591 Class clazz = SecretKeyFactory.class; 592 Method m; 593 594 checkNewMethods(clazz, 3); 595 596 m = getInstance(clazz, STRING); 597 run(m, NullPointerException.class, (Object) null); 598 run(m, NoSuchAlgorithmException.class, ""); 599 600 m = getInstance(clazz, STRING, STRING); 601 run(m, NullPointerException.class, null, "SUN"); 602 run(m, NoSuchAlgorithmException.class, "", "SUN"); 603 run(m, IllegalArgumentException.class, "FOO", null); 604 run(m, IllegalArgumentException.class, "FOO", ""); 605 606 m = getInstance(clazz, STRING, PROVIDER); 607 run(m, NullPointerException.class, null, SUN); 608 run(m, NoSuchAlgorithmException.class, "", SUN); 609 run(m, IllegalArgumentException.class, "FOO", null); 610 } 611 612 private static void testSecureRandom() throws Exception { 613 Class clazz = SecureRandom.class; 614 Method m; 615 SecureRandomParameters srp = new SecureRandomParameters() { 616 }; 617 618 checkNewMethods(clazz, 6); 619 620 m = getInstance(clazz, STRING); 621 run(m, NullPointerException.class, (Object) null); 622 run(m, NoSuchAlgorithmException.class, ""); 623 624 m = getInstance(clazz, STRING, STRING); 625 run(m, NullPointerException.class, null, "SUN"); 626 run(m, NoSuchAlgorithmException.class, "", "SUN"); 627 run(m, IllegalArgumentException.class, "FOO", null); 628 run(m, IllegalArgumentException.class, "FOO", ""); 629 630 m = getInstance(clazz, STRING, PROVIDER); 631 run(m, NullPointerException.class, null, SUN); 632 run(m, NoSuchAlgorithmException.class, "", SUN); 633 run(m, IllegalArgumentException.class, "FOO", null); 634 635 m = getInstance(clazz, STRING, SecureRandomParameters.class); 636 run(m, NullPointerException.class, (Object) null, srp); 637 run(m, NoSuchAlgorithmException.class, "", srp); 638 639 m = getInstance(clazz, STRING, SecureRandomParameters.class, STRING); 640 run(m, NullPointerException.class, null, srp, "SUN"); 641 run(m, NoSuchAlgorithmException.class, "", srp, "SUN"); 642 run(m, IllegalArgumentException.class, "FOO", srp, null); 643 run(m, IllegalArgumentException.class, "FOO", srp, ""); 644 645 m = getInstance(clazz, STRING, SecureRandomParameters.class, PROVIDER); 646 run(m, NullPointerException.class, null, srp, SUN); 647 run(m, NoSuchAlgorithmException.class, "", srp, SUN); 648 run(m, IllegalArgumentException.class, "FOO", srp, null); 649 } 650 651 private static void testSignature() throws Exception { 652 Class clazz = Signature.class; 653 Method m; 654 655 checkNewMethods(clazz, 3); 656 657 m = getInstance(clazz, STRING); 658 run(m, NullPointerException.class, (Object) null); 659 run(m, NoSuchAlgorithmException.class, ""); 660 661 m = getInstance(clazz, STRING, STRING); 662 run(m, NullPointerException.class, null, "SUN"); 663 run(m, NoSuchAlgorithmException.class, "", "SUN"); 664 run(m, IllegalArgumentException.class, "FOO", null); 665 run(m, IllegalArgumentException.class, "FOO", ""); 666 667 m = getInstance(clazz, STRING, PROVIDER); 668 run(m, NullPointerException.class, null, SUN); 669 run(m, NoSuchAlgorithmException.class, "", SUN); 670 run(m, IllegalArgumentException.class, "FOO", null); 671 } 672 673 private static void testTrustManagerFactory() throws Exception { 674 Class clazz = TrustManagerFactory.class; 675 Method m; 676 677 checkNewMethods(clazz, 3); 678 679 m = getInstance(clazz, STRING); 680 run(m, NullPointerException.class, (Object) null); 681 run(m, NoSuchAlgorithmException.class, ""); 682 683 m = getInstance(clazz, STRING, STRING); 684 run(m, NullPointerException.class, null, "SUN"); 685 run(m, NoSuchAlgorithmException.class, "", "SUN"); 686 run(m, IllegalArgumentException.class, "FOO", null); 687 run(m, IllegalArgumentException.class, "FOO", ""); 688 689 m = getInstance(clazz, STRING, PROVIDER); 690 run(m, NullPointerException.class, null, SUN); 691 run(m, NoSuchAlgorithmException.class, "", SUN); 692 run(m, IllegalArgumentException.class, "FOO", null); 693 } 694 }