< prev index next >

src/java.base/share/classes/java/nio/charset/Charset.java

Print this page
rev 17455 : 8184665: Skip name and alias checks for standard Charsets
Reviewed-by: sherman


 618     /* -- Instance fields and methods -- */
 619 
 620     private final String name;          // tickles a bug in oldjavac
 621     private final String[] aliases;     // tickles a bug in oldjavac
 622     private Set<String> aliasSet = null;
 623 
 624     /**
 625      * Initializes a new charset with the given canonical name and alias
 626      * set.
 627      *
 628      * @param  canonicalName
 629      *         The canonical name of this charset
 630      *
 631      * @param  aliases
 632      *         An array of this charset's aliases, or null if it has no aliases
 633      *
 634      * @throws IllegalCharsetNameException
 635      *         If the canonical name or any of the aliases are illegal
 636      */
 637     protected Charset(String canonicalName, String[] aliases) {
 638         checkName(canonicalName);
 639         String[] as = Objects.requireNonNullElse(aliases, zeroAliases);
 640         for (int i = 0; i < as.length; i++)







 641             checkName(as[i]);


 642         this.name = canonicalName;
 643         this.aliases = as;
 644     }
 645 
 646     /**
 647      * Returns this charset's canonical name.
 648      *
 649      * @return  The canonical name of this charset
 650      */
 651     public final String name() {
 652         return name;
 653     }
 654 
 655     /**
 656      * Returns a set containing this charset's aliases.
 657      *
 658      * @return  An immutable set of this charset's aliases
 659      */
 660     public final Set<String> aliases() {
 661         if (aliasSet != null)




 618     /* -- Instance fields and methods -- */
 619 
 620     private final String name;          // tickles a bug in oldjavac
 621     private final String[] aliases;     // tickles a bug in oldjavac
 622     private Set<String> aliasSet = null;
 623 
 624     /**
 625      * Initializes a new charset with the given canonical name and alias
 626      * set.
 627      *
 628      * @param  canonicalName
 629      *         The canonical name of this charset
 630      *
 631      * @param  aliases
 632      *         An array of this charset's aliases, or null if it has no aliases
 633      *
 634      * @throws IllegalCharsetNameException
 635      *         If the canonical name or any of the aliases are illegal
 636      */
 637     protected Charset(String canonicalName, String[] aliases) {

 638         String[] as = Objects.requireNonNullElse(aliases, zeroAliases);
 639 
 640         // Skip checks for the standard, built-in Charsets we always load
 641         // during initialization.
 642         if (canonicalName != StandardCharsets.ISO_8859_1
 643                 && canonicalName != StandardCharsets.US_ASCII
 644                 && canonicalName != StandardCharsets.UTF_8) {
 645             checkName(canonicalName);
 646             for (int i = 0; i < as.length; i++) {
 647                 checkName(as[i]);
 648             }
 649         }
 650         this.name = canonicalName;
 651         this.aliases = as;
 652     }
 653 
 654     /**
 655      * Returns this charset's canonical name.
 656      *
 657      * @return  The canonical name of this charset
 658      */
 659     public final String name() {
 660         return name;
 661     }
 662 
 663     /**
 664      * Returns a set containing this charset's aliases.
 665      *
 666      * @return  An immutable set of this charset's aliases
 667      */
 668     public final Set<String> aliases() {
 669         if (aliasSet != null)


< prev index next >