< prev index next >

src/java.base/share/classes/java/security/SecureRandom.java

Print this page
rev 51919 : 8215281: Use String.isEmpty() when applicable in java.base
Reviewed-by: dfuchs, alanb


 925      * by the {@code securerandom.strongAlgorithms} Security property
 926      *
 927      * @throws NoSuchAlgorithmException if no algorithm is available
 928      *
 929      * @see Security#getProperty(String)
 930      *
 931      * @since 1.8
 932      */
 933     public static SecureRandom getInstanceStrong()
 934             throws NoSuchAlgorithmException {
 935 
 936         String property = AccessController.doPrivileged(
 937             new PrivilegedAction<>() {
 938                 @Override
 939                 public String run() {
 940                     return Security.getProperty(
 941                         "securerandom.strongAlgorithms");
 942                 }
 943             });
 944 
 945         if ((property == null) || (property.length() == 0)) {
 946             throw new NoSuchAlgorithmException(
 947                 "Null/empty securerandom.strongAlgorithms Security Property");
 948         }
 949 
 950         String remainder = property;
 951         while (remainder != null) {
 952             Matcher m;
 953             if ((m = StrongPatternHolder.pattern.matcher(
 954                     remainder)).matches()) {
 955 
 956                 String alg = m.group(1);
 957                 String prov = m.group(3);
 958 
 959                 try {
 960                     if (prov == null) {
 961                         return SecureRandom.getInstance(alg);
 962                     } else {
 963                         return SecureRandom.getInstance(alg, prov);
 964                     }
 965                 } catch (NoSuchAlgorithmException |




 925      * by the {@code securerandom.strongAlgorithms} Security property
 926      *
 927      * @throws NoSuchAlgorithmException if no algorithm is available
 928      *
 929      * @see Security#getProperty(String)
 930      *
 931      * @since 1.8
 932      */
 933     public static SecureRandom getInstanceStrong()
 934             throws NoSuchAlgorithmException {
 935 
 936         String property = AccessController.doPrivileged(
 937             new PrivilegedAction<>() {
 938                 @Override
 939                 public String run() {
 940                     return Security.getProperty(
 941                         "securerandom.strongAlgorithms");
 942                 }
 943             });
 944 
 945         if (property == null || property.isEmpty()) {
 946             throw new NoSuchAlgorithmException(
 947                 "Null/empty securerandom.strongAlgorithms Security Property");
 948         }
 949 
 950         String remainder = property;
 951         while (remainder != null) {
 952             Matcher m;
 953             if ((m = StrongPatternHolder.pattern.matcher(
 954                     remainder)).matches()) {
 955 
 956                 String alg = m.group(1);
 957                 String prov = m.group(3);
 958 
 959                 try {
 960                     if (prov == null) {
 961                         return SecureRandom.getInstance(alg);
 962                     } else {
 963                         return SecureRandom.getInstance(alg, prov);
 964                     }
 965                 } catch (NoSuchAlgorithmException |


< prev index next >