< prev index next >

src/java.base/share/classes/sun/security/provider/ConfigFile.java

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


 609             if ("file".equalsIgnoreCase(url.getProtocol())) {
 610                 // Compatibility notes:
 611                 //
 612                 // Code changed from
 613                 //   String path = url.getFile().replace('/', File.separatorChar);
 614                 //   return new FileInputStream(path);
 615                 //
 616                 // The original implementation would search for "/tmp/a%20b"
 617                 // when url is "file:///tmp/a%20b". This is incorrect. The
 618                 // current codes fix this bug and searches for "/tmp/a b".
 619                 // For compatibility reasons, when the file "/tmp/a b" does
 620                 // not exist, the file named "/tmp/a%20b" will be tried.
 621                 //
 622                 // This also means that if both file exists, the behavior of
 623                 // this method is changed, and the current codes choose the
 624                 // correct one.
 625                 try {
 626                     return url.openStream();
 627                 } catch (Exception e) {
 628                     String file = url.getPath();
 629                     if (url.getHost().length() > 0) {  // For Windows UNC
 630                         file = "//" + url.getHost() + file;
 631                     }
 632                     if (debugConfig != null) {
 633                         debugConfig.println("cannot read " + url +
 634                                             ", try " + file);
 635                     }
 636                     return new FileInputStream(file);
 637                 }
 638             } else {
 639                 return url.openStream();
 640             }
 641         }
 642 
 643         private String expand(String value)
 644             throws PropertyExpander.ExpandException, IOException {
 645 
 646             if (value.isEmpty()) {
 647                 return value;
 648             }
 649 
 650             if (!expandProp) {
 651                 return value;
 652             }
 653             String s = PropertyExpander.expand(value);
 654             if (s == null || s.length() == 0) {
 655                 throw ioException(
 656                     "Configuration.Error.Line.line.system.property.value.expanded.to.empty.value",
 657                     linenum, value);
 658             }
 659             return s;
 660         }
 661 
 662         private IOException ioException(String resourceKey, Object... args) {
 663             MessageFormat form = new MessageFormat(
 664                 ResourcesMgr.getAuthResourceString(resourceKey));
 665             return new IOException(form.format(args));
 666         }
 667     }
 668 }


 609             if ("file".equalsIgnoreCase(url.getProtocol())) {
 610                 // Compatibility notes:
 611                 //
 612                 // Code changed from
 613                 //   String path = url.getFile().replace('/', File.separatorChar);
 614                 //   return new FileInputStream(path);
 615                 //
 616                 // The original implementation would search for "/tmp/a%20b"
 617                 // when url is "file:///tmp/a%20b". This is incorrect. The
 618                 // current codes fix this bug and searches for "/tmp/a b".
 619                 // For compatibility reasons, when the file "/tmp/a b" does
 620                 // not exist, the file named "/tmp/a%20b" will be tried.
 621                 //
 622                 // This also means that if both file exists, the behavior of
 623                 // this method is changed, and the current codes choose the
 624                 // correct one.
 625                 try {
 626                     return url.openStream();
 627                 } catch (Exception e) {
 628                     String file = url.getPath();
 629                     if (!url.getHost().isEmpty()) {  // For Windows UNC
 630                         file = "//" + url.getHost() + file;
 631                     }
 632                     if (debugConfig != null) {
 633                         debugConfig.println("cannot read " + url +
 634                                             ", try " + file);
 635                     }
 636                     return new FileInputStream(file);
 637                 }
 638             } else {
 639                 return url.openStream();
 640             }
 641         }
 642 
 643         private String expand(String value)
 644             throws PropertyExpander.ExpandException, IOException {
 645 
 646             if (value.isEmpty()) {
 647                 return value;
 648             }
 649 
 650             if (!expandProp) {
 651                 return value;
 652             }
 653             String s = PropertyExpander.expand(value);
 654             if (s == null || s.isEmpty()) {
 655                 throw ioException(
 656                     "Configuration.Error.Line.line.system.property.value.expanded.to.empty.value",
 657                     linenum, value);
 658             }
 659             return s;
 660         }
 661 
 662         private IOException ioException(String resourceKey, Object... args) {
 663             MessageFormat form = new MessageFormat(
 664                 ResourcesMgr.getAuthResourceString(resourceKey));
 665             return new IOException(form.format(args));
 666         }
 667     }
 668 }
< prev index next >