8029800: Flags.java uses String.toLowerCase without specifying Locale

Tue, 17 Dec 2013 10:55:59 +0100

author
jlahoda
date
Tue, 17 Dec 2013 10:55:59 +0100
changeset 2413
fe033d997ddf
parent 2412
bf8edbcae43a
child 2414
17ce329d7bd0

8029800: Flags.java uses String.toLowerCase without specifying Locale
Summary: Introducing StringUtils.toLowerCase/toUpperCase independent on the default locale, converting almost all usages of String.toLowerCase/toUpperCase to use the new methods.
Reviewed-by: jjg, bpatel

src/share/classes/com/sun/tools/classfile/Instruction.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlAttr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTag.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/MemberSummaryBuilder.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/SerializedFormBuilder.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/SimpleTaglet.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclint/Checker.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclint/Env.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclint/HtmlTag.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/doclint/Messages.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Flags.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/file/Locations.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/main/Option.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/parser/DocCommentParser.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/StringUtils.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javap/AttributeWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javap/TypeAnnotationWriter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/sjavac/server/CompilerThread.java file | annotate | diff | comparison | revisions
test/tools/javac/NoStringToLower.java file | annotate | diff | comparison | revisions
test/tools/javac/util/StringUtilsTest.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/classfile/Instruction.java	Wed Jun 04 20:01:13 2014 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/classfile/Instruction.java	Tue Dec 17 10:55:59 2013 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -25,6 +25,8 @@
    1.11  
    1.12  package com.sun.tools.classfile;
    1.13  
    1.14 +import java.util.Locale;
    1.15 +
    1.16  /**
    1.17   * See JVMS, chapter 6.
    1.18   *
    1.19 @@ -211,7 +213,7 @@
    1.20          if (opcode == null)
    1.21              return "bytecode " + getUnsignedByte(0);
    1.22          else
    1.23 -            return opcode.toString().toLowerCase();
    1.24 +            return opcode.toString().toLowerCase(Locale.US);
    1.25      }
    1.26  
    1.27      /** Get the length, in bytes, of this instruction, including the opcode
     2.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Wed Jun 04 20:01:13 2014 +0100
     2.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java	Tue Dec 17 10:55:59 2013 +0100
     2.3 @@ -37,6 +37,7 @@
     2.4  import com.sun.tools.doclint.DocLint;
     2.5  import com.sun.tools.javac.file.JavacFileManager;
     2.6  import com.sun.tools.javac.util.Context;
     2.7 +import com.sun.tools.javac.util.StringUtils;
     2.8  import com.sun.tools.javadoc.RootDocImpl;
     2.9  
    2.10  /**
    2.11 @@ -237,7 +238,7 @@
    2.12      public void setSpecificDocletOptions(String[][] options) {
    2.13          for (int oi = 0; oi < options.length; ++oi) {
    2.14              String[] os = options[oi];
    2.15 -            String opt = os[0].toLowerCase();
    2.16 +            String opt = StringUtils.toLowerCase(os[0]);
    2.17              if (opt.equals("-footer")) {
    2.18                  footer = os[1];
    2.19              } else if (opt.equals("-header")) {
    2.20 @@ -325,7 +326,7 @@
    2.21              return result;
    2.22          }
    2.23          // otherwise look for the options we have added
    2.24 -        option = option.toLowerCase();
    2.25 +        option = StringUtils.toLowerCase(option);
    2.26          if (option.equals("-nodeprecatedlist") ||
    2.27              option.equals("-noindex") ||
    2.28              option.equals("-notree") ||
    2.29 @@ -389,7 +390,7 @@
    2.30          // otherwise look at our options
    2.31          for (int oi = 0; oi < options.length; ++oi) {
    2.32              String[] os = options[oi];
    2.33 -            String opt = os[0].toLowerCase();
    2.34 +            String opt = StringUtils.toLowerCase(os[0]);
    2.35              if (opt.equals("-helpfile")) {
    2.36                  if (nohelp == true) {
    2.37                      reporter.printError(getText("doclet.Option_conflict",
     3.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Wed Jun 04 20:01:13 2014 +0100
     3.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Tue Dec 17 10:55:59 2013 +0100
     3.3 @@ -34,6 +34,7 @@
     3.4  import com.sun.tools.doclets.internal.toolkit.*;
     3.5  import com.sun.tools.doclets.internal.toolkit.taglets.*;
     3.6  import com.sun.tools.doclets.internal.toolkit.util.*;
     3.7 +import com.sun.tools.javac.util.StringUtils;
     3.8  
     3.9  /**
    3.10   * Class for the Html Format Code Generation specific to JavaDoc.
    3.11 @@ -138,17 +139,17 @@
    3.12          if (index < 0) {
    3.13              return htmlstr;
    3.14          }
    3.15 -        String lowerHtml = htmlstr.toLowerCase();
    3.16 +        String lowerHtml = StringUtils.toLowerCase(htmlstr);
    3.17 +        final String docroot = "{@docroot}";
    3.18          // Return index of first occurrence of {@docroot}
    3.19          // Note: {@docRoot} is not case sensitive when passed in w/command line option
    3.20 -        index = lowerHtml.indexOf("{@docroot}", index);
    3.21 +        index = lowerHtml.indexOf(docroot, index);
    3.22          if (index < 0) {
    3.23              return htmlstr;
    3.24          }
    3.25          StringBuilder buf = new StringBuilder();
    3.26          int previndex = 0;
    3.27          while (true) {
    3.28 -            final String docroot = "{@docroot}";
    3.29              // Search for lowercase version of {@docRoot}
    3.30              index = lowerHtml.indexOf(docroot, previndex);
    3.31              // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
    3.32 @@ -1689,13 +1690,13 @@
    3.33          }
    3.34  
    3.35          //Redirect all relative links.
    3.36 -        int end, begin = text.toLowerCase().indexOf("<a");
    3.37 +        int end, begin = StringUtils.toLowerCase(text).indexOf("<a");
    3.38          if(begin >= 0){
    3.39              StringBuilder textBuff = new StringBuilder(text);
    3.40  
    3.41              while(begin >=0){
    3.42                  if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
    3.43 -                    begin = textBuff.toString().toLowerCase().indexOf("<a", begin + 1);
    3.44 +                    begin = StringUtils.toLowerCase(textBuff.toString()).indexOf("<a", begin + 1);
    3.45                      continue;
    3.46                  }
    3.47  
    3.48 @@ -1722,15 +1723,16 @@
    3.49                      }
    3.50                  }
    3.51                  String relativeLink = textBuff.substring(begin, end);
    3.52 -                if (!(relativeLink.toLowerCase().startsWith("mailto:") ||
    3.53 -                        relativeLink.toLowerCase().startsWith("http:") ||
    3.54 -                        relativeLink.toLowerCase().startsWith("https:") ||
    3.55 -                        relativeLink.toLowerCase().startsWith("file:"))) {
    3.56 +                String relativeLinkLowerCase = StringUtils.toLowerCase(relativeLink);
    3.57 +                if (!(relativeLinkLowerCase.startsWith("mailto:") ||
    3.58 +                        relativeLinkLowerCase.startsWith("http:") ||
    3.59 +                        relativeLinkLowerCase.startsWith("https:") ||
    3.60 +                        relativeLinkLowerCase.startsWith("file:"))) {
    3.61                      relativeLink = "{@"+(new DocRootTaglet()).getName() + "}/"
    3.62                          + redirectPathFromRoot.resolve(relativeLink).getPath();
    3.63                      textBuff.replace(begin, end, relativeLink);
    3.64                  }
    3.65 -                begin = textBuff.toString().toLowerCase().indexOf("<a", begin + 1);
    3.66 +                begin = StringUtils.toLowerCase(textBuff.toString()).indexOf("<a", begin + 1);
    3.67              }
    3.68              return textBuff.toString();
    3.69          }
    3.70 @@ -1771,7 +1773,7 @@
    3.71                      break main;
    3.72                  ch = text.charAt(currPos);
    3.73              }
    3.74 -            if (ch == '>' && blockTags.contains(text.substring(tagPos, currPos).toLowerCase())) {
    3.75 +            if (ch == '>' && blockTags.contains(StringUtils.toLowerCase(text.substring(tagPos, currPos)))) {
    3.76                  result.append(text, startPos, lessThanPos);
    3.77                  startPos = currPos + 1;
    3.78              }
     4.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java	Wed Jun 04 20:01:13 2014 +0100
     4.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java	Tue Dec 17 10:55:59 2013 +0100
     4.3 @@ -31,6 +31,7 @@
     4.4  import com.sun.tools.doclets.formats.html.markup.*;
     4.5  import com.sun.tools.doclets.internal.toolkit.*;
     4.6  import com.sun.tools.doclets.internal.toolkit.util.*;
     4.7 +import com.sun.tools.javac.util.StringUtils;
     4.8  
     4.9  /**
    4.10   * Writes method documentation in HTML format.
    4.11 @@ -338,7 +339,7 @@
    4.12              return "";
    4.13          }
    4.14  
    4.15 -        String lc = tag.toLowerCase();
    4.16 +        String lc = StringUtils.toLowerCase(tag);
    4.17          int begin = lc.indexOf("<code>");
    4.18          int end = lc.indexOf("</code>");
    4.19          if(begin == -1 || end == -1 || end <= begin){
     5.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlAttr.java	Wed Jun 04 20:01:13 2014 +0100
     5.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlAttr.java	Tue Dec 17 10:55:59 2013 +0100
     5.3 @@ -25,6 +25,8 @@
     5.4  
     5.5  package com.sun.tools.doclets.formats.html.markup;
     5.6  
     5.7 +import com.sun.tools.javac.util.StringUtils;
     5.8 +
     5.9  /**
    5.10   * Enum representing HTML tag attributes.
    5.11   *
    5.12 @@ -64,7 +66,7 @@
    5.13      private final String value;
    5.14  
    5.15      HtmlAttr() {
    5.16 -        this.value = name().toLowerCase();
    5.17 +        this.value = StringUtils.toLowerCase(name());
    5.18      }
    5.19  
    5.20      HtmlAttr(String name) {
     6.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTag.java	Wed Jun 04 20:01:13 2014 +0100
     6.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTag.java	Tue Dec 17 10:55:59 2013 +0100
     6.3 @@ -25,7 +25,7 @@
     6.4  
     6.5  package com.sun.tools.doclets.formats.html.markup;
     6.6  
     6.7 -import java.util.Locale;
     6.8 +import com.sun.tools.javac.util.StringUtils;
     6.9  
    6.10  /**
    6.11   * Enum representing HTML tags.
    6.12 @@ -117,7 +117,7 @@
    6.13      HtmlTag(BlockType blockType, EndTag endTag ) {
    6.14          this.blockType = blockType;
    6.15          this.endTag = endTag;
    6.16 -        this.value = name().toLowerCase(Locale.US);
    6.17 +        this.value = StringUtils.toLowerCase(name());
    6.18      }
    6.19  
    6.20      /**
     7.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Wed Jun 04 20:01:13 2014 +0100
     7.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java	Tue Dec 17 10:55:59 2013 +0100
     7.3 @@ -29,6 +29,7 @@
     7.4  import java.util.*;
     7.5  import java.util.regex.Matcher;
     7.6  import java.util.regex.Pattern;
     7.7 +import javax.tools.JavaFileManager;
     7.8  
     7.9  import com.sun.javadoc.*;
    7.10  import com.sun.tools.javac.sym.Profiles;
    7.11 @@ -36,7 +37,7 @@
    7.12  import com.sun.tools.doclets.internal.toolkit.builders.BuilderFactory;
    7.13  import com.sun.tools.doclets.internal.toolkit.taglets.*;
    7.14  import com.sun.tools.doclets.internal.toolkit.util.*;
    7.15 -import javax.tools.JavaFileManager;
    7.16 +import com.sun.tools.javac.util.StringUtils;
    7.17  
    7.18  /**
    7.19   * Configure the output based on the options. Doclets should sub-class
    7.20 @@ -337,7 +338,7 @@
    7.21       * Negative value means error occurred.
    7.22       */
    7.23      public int optionLength(String option) {
    7.24 -        option = option.toLowerCase();
    7.25 +        option = StringUtils.toLowerCase(option);
    7.26          if (option.equals("-author") ||
    7.27              option.equals("-docfilessubdirs") ||
    7.28              option.equals("-javafx") ||
    7.29 @@ -454,7 +455,7 @@
    7.30          // the output directory has already been created: so do that first.
    7.31          for (int oi = 0; oi < options.length; ++oi) {
    7.32              String[] os = options[oi];
    7.33 -            String opt = os[0].toLowerCase();
    7.34 +            String opt = StringUtils.toLowerCase(os[0]);
    7.35              if (opt.equals("-d")) {
    7.36                  destDirName = addTrailingFileSep(os[1]);
    7.37                  docFileDestDirName = destDirName;
    7.38 @@ -465,7 +466,7 @@
    7.39  
    7.40          for (int oi = 0; oi < options.length; ++oi) {
    7.41              String[] os = options[oi];
    7.42 -            String opt = os[0].toLowerCase();
    7.43 +            String opt = StringUtils.toLowerCase(os[0]);
    7.44              if (opt.equals("-docfilessubdirs")) {
    7.45                  copydocfilesubdirs = true;
    7.46              } else if (opt.equals("-docencoding")) {
    7.47 @@ -708,7 +709,7 @@
    7.48          String encoding = "";
    7.49          for (int oi = 0; oi < options.length; oi++) {
    7.50              String[] os = options[oi];
    7.51 -            String opt = os[0].toLowerCase();
    7.52 +            String opt = StringUtils.toLowerCase(os[0]);
    7.53              if (opt.equals("-docencoding")) {
    7.54                  docencodingfound = true;
    7.55                  if (!checkOutputFileEncoding(os[1], reporter)) {
     8.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/MemberSummaryBuilder.java	Wed Jun 04 20:01:13 2014 +0100
     8.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/MemberSummaryBuilder.java	Tue Dec 17 10:55:59 2013 +0100
     8.3 @@ -384,13 +384,13 @@
     8.4                  commentTextBuilder.append(
     8.5                          MessageFormat.format(
     8.6                                  configuration.getText("doclet.PropertySetterWithName"),
     8.7 -                                Util.propertyNameFromMethodName(member.name())));
     8.8 +                                Util.propertyNameFromMethodName(configuration, member.name())));
     8.9              }
    8.10              if (isGetter) {
    8.11                  commentTextBuilder.append(
    8.12                          MessageFormat.format(
    8.13                                  configuration.getText("doclet.PropertyGetterWithName"),
    8.14 -                                Util.propertyNameFromMethodName(member.name())));
    8.15 +                                Util.propertyNameFromMethodName(configuration, member.name())));
    8.16              }
    8.17              if (propertyDoc.commentText() != null
    8.18                          && !propertyDoc.commentText().isEmpty()) {
     9.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/SerializedFormBuilder.java	Wed Jun 04 20:01:13 2014 +0100
     9.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/SerializedFormBuilder.java	Tue Dec 17 10:55:59 2013 +0100
     9.3 @@ -31,6 +31,7 @@
     9.4  import com.sun.javadoc.*;
     9.5  import com.sun.tools.doclets.internal.toolkit.*;
     9.6  import com.sun.tools.doclets.internal.toolkit.util.*;
     9.7 +import com.sun.tools.javac.util.StringUtils;
     9.8  
     9.9  /**
    9.10   * Builds the serialized form.
    9.11 @@ -567,7 +568,7 @@
    9.12          }
    9.13          Tag[] serial = doc.tags("serial");
    9.14          if (serial.length > 0) {
    9.15 -            String serialtext = serial[0].text().toLowerCase();
    9.16 +            String serialtext = StringUtils.toLowerCase(serial[0].text());
    9.17              if (serialtext.indexOf("exclude") >= 0) {
    9.18                  return false;
    9.19              } else if (serialtext.indexOf("include") >= 0) {
    10.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/SimpleTaglet.java	Wed Jun 04 20:01:13 2014 +0100
    10.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/SimpleTaglet.java	Tue Dec 17 10:55:59 2013 +0100
    10.3 @@ -28,6 +28,7 @@
    10.4  import com.sun.javadoc.*;
    10.5  import com.sun.tools.doclets.internal.toolkit.Content;
    10.6  import com.sun.tools.doclets.internal.toolkit.util.DocFinder;
    10.7 +import com.sun.tools.javac.util.StringUtils;
    10.8  
    10.9  /**
   10.10   * A simple single argument custom tag.
   10.11 @@ -110,7 +111,7 @@
   10.12      public SimpleTaglet(String tagName, String header, String locations) {
   10.13          this.tagName = tagName;
   10.14          this.header = header;
   10.15 -        locations = locations.toLowerCase();
   10.16 +        locations = StringUtils.toLowerCase(locations);
   10.17          if (locations.indexOf(ALL) != -1 && locations.indexOf(EXCLUDED) == -1) {
   10.18              this.locations = PACKAGE + TYPE + FIELD + METHOD + CONSTRUCTOR + OVERVIEW;
   10.19          } else {
    11.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java	Wed Jun 04 20:01:13 2014 +0100
    11.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java	Tue Dec 17 10:55:59 2013 +0100
    11.3 @@ -35,6 +35,7 @@
    11.4  
    11.5  import com.sun.javadoc.*;
    11.6  import com.sun.tools.doclets.internal.toolkit.util.*;
    11.7 +import com.sun.tools.javac.util.StringUtils;
    11.8  
    11.9  /**
   11.10   * Manages the<code>Taglet</code>s used by doclets.
   11.11 @@ -304,7 +305,7 @@
   11.12              return;
   11.13          }
   11.14          Taglet tag = customTags.get(tagName);
   11.15 -        locations = locations.toLowerCase();
   11.16 +        locations = StringUtils.toLowerCase(locations);
   11.17          if (tag == null || header != null) {
   11.18              customTags.remove(tagName);
   11.19              customTags.put(tagName, new SimpleTaglet(tagName, header, locations));
   11.20 @@ -375,7 +376,7 @@
   11.21                  name = name.substring(1, name.length());
   11.22              }
   11.23              if (! (standardTags.contains(name) || customTags.containsKey(name))) {
   11.24 -                if (standardTagsLowercase.contains(name.toLowerCase())) {
   11.25 +                if (standardTagsLowercase.contains(StringUtils.toLowerCase(name))) {
   11.26                      message.warning(tags[i].position(), "doclet.UnknownTagLowercase", tags[i].name());
   11.27                      continue;
   11.28                  } else {
   11.29 @@ -708,7 +709,7 @@
   11.30      private void initStandardTagsLowercase() {
   11.31          Iterator<String> it = standardTags.iterator();
   11.32          while (it.hasNext()) {
   11.33 -            standardTagsLowercase.add(it.next().toLowerCase());
   11.34 +            standardTagsLowercase.add(StringUtils.toLowerCase(it.next()));
   11.35          }
   11.36      }
   11.37  
    12.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java	Wed Jun 04 20:01:13 2014 +0100
    12.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java	Tue Dec 17 10:55:59 2013 +0100
    12.3 @@ -28,11 +28,12 @@
    12.4  import java.io.*;
    12.5  import java.lang.annotation.ElementType;
    12.6  import java.util.*;
    12.7 +import javax.tools.StandardLocation;
    12.8  
    12.9  import com.sun.javadoc.*;
   12.10  import com.sun.javadoc.AnnotationDesc.ElementValuePair;
   12.11  import com.sun.tools.doclets.internal.toolkit.*;
   12.12 -import javax.tools.StandardLocation;
   12.13 +import com.sun.tools.javac.util.StringUtils;
   12.14  
   12.15  /**
   12.16   * Utilities Class for Doclets.
   12.17 @@ -253,8 +254,8 @@
   12.18       */
   12.19      private static class TypeComparator implements Comparator<Type> {
   12.20          public int compare(Type type1, Type type2) {
   12.21 -            return type1.qualifiedTypeName().toLowerCase().compareTo(
   12.22 -                type2.qualifiedTypeName().toLowerCase());
   12.23 +            return type1.qualifiedTypeName().compareToIgnoreCase(
   12.24 +                type2.qualifiedTypeName());
   12.25          }
   12.26      }
   12.27  
   12.28 @@ -589,7 +590,7 @@
   12.29              typeName = "doclet.Enum";
   12.30          }
   12.31          return config.getText(
   12.32 -            lowerCaseOnly ? typeName.toLowerCase() : typeName);
   12.33 +            lowerCaseOnly ? StringUtils.toLowerCase(typeName) : typeName);
   12.34      }
   12.35  
   12.36      /**
   12.37 @@ -724,7 +725,7 @@
   12.38       * @param name name of the getter or setter method.
   12.39       * @return the name of the property of the given setter of getter.
   12.40       */
   12.41 -    public static String propertyNameFromMethodName(String name) {
   12.42 +    public static String propertyNameFromMethodName(Configuration configuration, String name) {
   12.43          String propertyName = null;
   12.44          if (name.startsWith("get") || name.startsWith("set")) {
   12.45              propertyName = name.substring(3);
   12.46 @@ -734,7 +735,7 @@
   12.47          if ((propertyName == null) || propertyName.isEmpty()){
   12.48              return "";
   12.49          }
   12.50 -        return propertyName.substring(0, 1).toLowerCase()
   12.51 +        return propertyName.substring(0, 1).toLowerCase(configuration.getLocale())
   12.52                  + propertyName.substring(1);
   12.53      }
   12.54  
    13.1 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java	Wed Jun 04 20:01:13 2014 +0100
    13.2 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java	Tue Dec 17 10:55:59 2013 +0100
    13.3 @@ -702,7 +702,7 @@
    13.4          private boolean isPropertyGetterOrSetter(MethodDoc[] members,
    13.5                                                   MethodDoc methodDoc) {
    13.6              boolean found = false;
    13.7 -            String propertyName = Util.propertyNameFromMethodName(methodDoc.name());
    13.8 +            String propertyName = Util.propertyNameFromMethodName(configuration, methodDoc.name());
    13.9              if (!propertyName.isEmpty()) {
   13.10                  String propertyMethodName = propertyName + "Property";
   13.11                  for (MethodDoc member: members) {
    14.1 --- a/src/share/classes/com/sun/tools/doclint/Checker.java	Wed Jun 04 20:01:13 2014 +0100
    14.2 +++ b/src/share/classes/com/sun/tools/doclint/Checker.java	Tue Dec 17 10:55:59 2013 +0100
    14.3 @@ -80,6 +80,7 @@
    14.4  import com.sun.source.util.TreePath;
    14.5  import com.sun.tools.doclint.HtmlTag.AttrKind;
    14.6  import com.sun.tools.javac.tree.DocPretty;
    14.7 +import com.sun.tools.javac.util.StringUtils;
    14.8  import static com.sun.tools.doclint.Messages.Group.*;
    14.9  
   14.10  
   14.11 @@ -243,7 +244,7 @@
   14.12          markEnclosingTag(Flag.HAS_TEXT);
   14.13          String name = tree.getName().toString();
   14.14          if (name.startsWith("#")) {
   14.15 -            int v = name.toLowerCase().startsWith("#x")
   14.16 +            int v = StringUtils.toLowerCase(name).startsWith("#x")
   14.17                      ? Integer.parseInt(name.substring(2), 16)
   14.18                      : Integer.parseInt(name.substring(1), 10);
   14.19              if (!Entity.isValid(v)) {
    15.1 --- a/src/share/classes/com/sun/tools/doclint/Env.java	Wed Jun 04 20:01:13 2014 +0100
    15.2 +++ b/src/share/classes/com/sun/tools/doclint/Env.java	Tue Dec 17 10:55:59 2013 +0100
    15.3 @@ -44,6 +44,7 @@
    15.4  import com.sun.source.util.TreePath;
    15.5  import com.sun.tools.javac.model.JavacTypes;
    15.6  import com.sun.tools.javac.tree.JCTree;
    15.7 +import com.sun.tools.javac.util.StringUtils;
    15.8  
    15.9  /**
   15.10   * Utility container for current execution environment,
   15.11 @@ -66,7 +67,7 @@
   15.12  
   15.13          static boolean accepts(String opt) {
   15.14              for (AccessKind g: values())
   15.15 -                if (opt.equals(g.name().toLowerCase())) return true;
   15.16 +                if (opt.equals(StringUtils.toLowerCase(g.name()))) return true;
   15.17              return false;
   15.18          }
   15.19  
    16.1 --- a/src/share/classes/com/sun/tools/doclint/HtmlTag.java	Wed Jun 04 20:01:13 2014 +0100
    16.2 +++ b/src/share/classes/com/sun/tools/doclint/HtmlTag.java	Tue Dec 17 10:55:59 2013 +0100
    16.3 @@ -36,6 +36,7 @@
    16.4  import javax.lang.model.element.Name;
    16.5  
    16.6  import static com.sun.tools.doclint.HtmlTag.Attr.*;
    16.7 +import com.sun.tools.javac.util.StringUtils;
    16.8  
    16.9  /**
   16.10   * Enum representing HTML tags.
   16.11 @@ -352,7 +353,7 @@
   16.12          WIDTH;
   16.13  
   16.14          public String getText() {
   16.15 -            return toLowerCase(name());
   16.16 +            return StringUtils.toLowerCase(name());
   16.17          }
   16.18  
   16.19          static final Map<String,Attr> index = new HashMap<String,Attr>();
   16.20 @@ -431,11 +432,11 @@
   16.21      }
   16.22  
   16.23      public String getText() {
   16.24 -        return toLowerCase(name());
   16.25 +        return StringUtils.toLowerCase(name());
   16.26      }
   16.27  
   16.28      public Attr getAttr(Name attrName) {
   16.29 -        return Attr.index.get(toLowerCase(attrName.toString()));
   16.30 +        return Attr.index.get(StringUtils.toLowerCase(attrName.toString()));
   16.31      }
   16.32  
   16.33      public AttrKind getAttrKind(Name attrName) {
   16.34 @@ -457,10 +458,7 @@
   16.35      }
   16.36  
   16.37      static HtmlTag get(Name tagName) {
   16.38 -        return index.get(toLowerCase(tagName.toString()));
   16.39 +        return index.get(StringUtils.toLowerCase(tagName.toString()));
   16.40      }
   16.41  
   16.42 -    private static String toLowerCase(String s) {
   16.43 -        return s.toLowerCase(Locale.US);
   16.44 -    }
   16.45  }
    17.1 --- a/src/share/classes/com/sun/tools/doclint/Messages.java	Wed Jun 04 20:01:13 2014 +0100
    17.2 +++ b/src/share/classes/com/sun/tools/doclint/Messages.java	Tue Dec 17 10:55:59 2013 +0100
    17.3 @@ -1,5 +1,5 @@
    17.4  /*
    17.5 - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
    17.6 + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
    17.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    17.8   *
    17.9   * This code is free software; you can redistribute it and/or modify it
   17.10 @@ -42,6 +42,7 @@
   17.11  import com.sun.source.doctree.DocTree;
   17.12  import com.sun.source.tree.Tree;
   17.13  import com.sun.tools.doclint.Env.AccessKind;
   17.14 +import com.sun.tools.javac.util.StringUtils;
   17.15  
   17.16  /**
   17.17   * Message reporting for DocLint.
   17.18 @@ -67,7 +68,7 @@
   17.19          SYNTAX,
   17.20          REFERENCE;
   17.21  
   17.22 -        String optName() { return name().toLowerCase(); }
   17.23 +        String optName() { return StringUtils.toLowerCase(name()); }
   17.24          String notOptName() { return "-" + optName(); }
   17.25  
   17.26          static boolean accepts(String opt) {
   17.27 @@ -158,7 +159,7 @@
   17.28  
   17.29          static boolean isValidOptions(String opts) {
   17.30              for (String opt: opts.split(",")) {
   17.31 -                if (!isValidOption(opt.trim().toLowerCase()))
   17.32 +                if (!isValidOption(StringUtils.toLowerCase(opt.trim())))
   17.33                      return false;
   17.34              }
   17.35              return true;
   17.36 @@ -203,7 +204,7 @@
   17.37                  setOption(ALL, Env.AccessKind.PRIVATE);
   17.38              else {
   17.39                  for (String opt: opts.split(","))
   17.40 -                    setOption(opt.trim().toLowerCase());
   17.41 +                    setOption(StringUtils.toLowerCase(opt.trim()));
   17.42              }
   17.43          }
   17.44  
   17.45 @@ -215,7 +216,7 @@
   17.46  
   17.47              int sep = arg.indexOf("/");
   17.48              if (sep > 0) {
   17.49 -                Env.AccessKind ak = Env.AccessKind.valueOf(arg.substring(sep + 1).toUpperCase());
   17.50 +                Env.AccessKind ak = Env.AccessKind.valueOf(StringUtils.toUpperCase(arg.substring(sep + 1)));
   17.51                  setOption(arg.substring(0, sep), ak);
   17.52              } else {
   17.53                  setOption(arg, null);
   17.54 @@ -290,7 +291,7 @@
   17.55              out.println("By diagnostic kind...");
   17.56              Table dkindTable = new Table();
   17.57              for (Diagnostic.Kind k : Diagnostic.Kind.values()) {
   17.58 -                dkindTable.put(k.toString().toLowerCase(), dkindCounts[k.ordinal()]);
   17.59 +                dkindTable.put(StringUtils.toLowerCase(k.toString()), dkindCounts[k.ordinal()]);
   17.60              }
   17.61              dkindTable.print(out);
   17.62              out.println();
    18.1 --- a/src/share/classes/com/sun/tools/javac/code/Flags.java	Wed Jun 04 20:01:13 2014 +0100
    18.2 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java	Tue Dec 17 10:55:59 2013 +0100
    18.3 @@ -33,6 +33,7 @@
    18.4  import javax.lang.model.element.Modifier;
    18.5  
    18.6  import com.sun.tools.javac.util.Assert;
    18.7 +import com.sun.tools.javac.util.StringUtils;
    18.8  
    18.9  /** Access flags and other modifiers for Java classes and members.
   18.10   *
   18.11 @@ -388,7 +389,7 @@
   18.12  
   18.13          Flag(long flag) {
   18.14              this.value = flag;
   18.15 -            this.lowercaseName = name().toLowerCase();
   18.16 +            this.lowercaseName = StringUtils.toLowerCase(name());
   18.17          }
   18.18  
   18.19          @Override
    19.1 --- a/src/share/classes/com/sun/tools/javac/file/Locations.java	Wed Jun 04 20:01:13 2014 +0100
    19.2 +++ b/src/share/classes/com/sun/tools/javac/file/Locations.java	Tue Dec 17 10:55:59 2013 +0100
    19.3 @@ -1,5 +1,5 @@
    19.4  /*
    19.5 - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
    19.6 + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
    19.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    19.8   *
    19.9   * This code is free software; you can redistribute it and/or modify it
   19.10 @@ -51,6 +51,7 @@
   19.11  import com.sun.tools.javac.util.ListBuffer;
   19.12  import com.sun.tools.javac.util.Log;
   19.13  import com.sun.tools.javac.util.Options;
   19.14 +import com.sun.tools.javac.util.StringUtils;
   19.15  
   19.16  import javax.tools.JavaFileManager;
   19.17  import javax.tools.StandardJavaFileManager;
   19.18 @@ -717,7 +718,7 @@
   19.19  
   19.20      /** Is this the name of an archive file? */
   19.21      private boolean isArchive(File file) {
   19.22 -        String n = file.getName().toLowerCase();
   19.23 +        String n = StringUtils.toLowerCase(file.getName());
   19.24          return fsInfo.isFile(file)
   19.25              && (n.endsWith(".jar") || n.endsWith(".zip"));
   19.26      }
    20.1 --- a/src/share/classes/com/sun/tools/javac/main/Option.java	Wed Jun 04 20:01:13 2014 +0100
    20.2 +++ b/src/share/classes/com/sun/tools/javac/main/Option.java	Tue Dec 17 10:55:59 2013 +0100
    20.3 @@ -47,6 +47,7 @@
    20.4  import com.sun.tools.javac.util.Log.PrefixKind;
    20.5  import com.sun.tools.javac.util.Log.WriterKind;
    20.6  import com.sun.tools.javac.util.Options;
    20.7 +import com.sun.tools.javac.util.StringUtils;
    20.8  import static com.sun.tools.javac.main.Option.ChoiceKind.*;
    20.9  import static com.sun.tools.javac.main.Option.OptionGroup.*;
   20.10  import static com.sun.tools.javac.main.Option.OptionKind.*;
   20.11 @@ -713,7 +714,7 @@
   20.12              String v = options.get(XPKGINFO);
   20.13              return (v == null
   20.14                      ? PkgInfo.LEGACY
   20.15 -                    : PkgInfo.valueOf(v.toUpperCase()));
   20.16 +                    : PkgInfo.valueOf(StringUtils.toUpperCase(v)));
   20.17          }
   20.18      }
   20.19  
    21.1 --- a/src/share/classes/com/sun/tools/javac/parser/DocCommentParser.java	Wed Jun 04 20:01:13 2014 +0100
    21.2 +++ b/src/share/classes/com/sun/tools/javac/parser/DocCommentParser.java	Tue Dec 17 10:55:59 2013 +0100
    21.3 @@ -57,6 +57,7 @@
    21.4  import com.sun.tools.javac.util.Names;
    21.5  import com.sun.tools.javac.util.Options;
    21.6  import com.sun.tools.javac.util.Position;
    21.7 +import com.sun.tools.javac.util.StringUtils;
    21.8  import static com.sun.tools.javac.util.LayoutCharacters.*;
    21.9  
   21.10  /**
   21.11 @@ -993,7 +994,7 @@
   21.12                      "h1", "h2", "h3", "h4", "h5", "h6", "p", "pre"));
   21.13  
   21.14      protected boolean isSentenceBreak(Name n) {
   21.15 -        return htmlBlockTags.contains(n.toString().toLowerCase());
   21.16 +        return htmlBlockTags.contains(StringUtils.toLowerCase(n.toString()));
   21.17      }
   21.18  
   21.19      protected boolean isSentenceBreak(DCTree t) {
    22.1 --- a/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java	Wed Jun 04 20:01:13 2014 +0100
    22.2 +++ b/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java	Tue Dec 17 10:55:59 2013 +0100
    22.3 @@ -1,5 +1,5 @@
    22.4  /*
    22.5 - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
    22.6 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
    22.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    22.8   *
    22.9   * This code is free software; you can redistribute it and/or modify it
   22.10 @@ -36,6 +36,7 @@
   22.11  import java.io.PrintWriter;
   22.12  import java.io.Writer;
   22.13  import java.util.*;
   22.14 +import com.sun.tools.javac.util.StringUtils;
   22.15  
   22.16  /**
   22.17   * A processor which prints out elements.  Used to implement the
   22.18 @@ -202,7 +203,7 @@
   22.19                      writer.print("@interface");
   22.20                      break;
   22.21                  default:
   22.22 -                    writer.print(kind.toString().toLowerCase());
   22.23 +                    writer.print(StringUtils.toLowerCase(kind.toString()));
   22.24                  }
   22.25                  writer.print(" ");
   22.26                  writer.print(e.getSimpleName());
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/share/classes/com/sun/tools/javac/util/StringUtils.java	Tue Dec 17 10:55:59 2013 +0100
    23.3 @@ -0,0 +1,53 @@
    23.4 +/*
    23.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    23.7 + *
    23.8 + * This code is free software; you can redistribute it and/or modify it
    23.9 + * under the terms of the GNU General Public License version 2 only, as
   23.10 + * published by the Free Software Foundation.  Oracle designates this
   23.11 + * particular file as subject to the "Classpath" exception as provided
   23.12 + * by Oracle in the LICENSE file that accompanied this code.
   23.13 + *
   23.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   23.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   23.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   23.17 + * version 2 for more details (a copy is included in the LICENSE file that
   23.18 + * accompanied this code).
   23.19 + *
   23.20 + * You should have received a copy of the GNU General Public License version
   23.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   23.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   23.23 + *
   23.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   23.25 + * or visit www.oracle.com if you need additional information or have any
   23.26 + * questions.
   23.27 + */
   23.28 +
   23.29 +package com.sun.tools.javac.util;
   23.30 +
   23.31 +import java.util.Locale;
   23.32 +
   23.33 +/** A collection of utilities for String manipulation.
   23.34 + *
   23.35 + *  <p><b>This is NOT part of any supported API.
   23.36 + *  If you write code that depends on this, you do so at your own risk.
   23.37 + *  This code and its internal interfaces are subject to change or
   23.38 + *  deletion without notice.</b>
   23.39 + */
   23.40 +public class StringUtils {
   23.41 +
   23.42 +    /**Converts the given String to lower case using the {@link Locale#US US Locale}. The result
   23.43 +     * is independent of the default Locale in the current JVM instance.
   23.44 +     */
   23.45 +    public static String toLowerCase(String source) {
   23.46 +        return source.toLowerCase(Locale.US);
   23.47 +    }
   23.48 +
   23.49 +    /**Converts the given String to upper case using the {@link Locale#US US Locale}. The result
   23.50 +     * is independent of the default Locale in the current JVM instance.
   23.51 +     */
   23.52 +    public static String toUpperCase(String source) {
   23.53 +        return source.toUpperCase(Locale.US);
   23.54 +    }
   23.55 +
   23.56 +}
    24.1 --- a/src/share/classes/com/sun/tools/javap/AttributeWriter.java	Wed Jun 04 20:01:13 2014 +0100
    24.2 +++ b/src/share/classes/com/sun/tools/javap/AttributeWriter.java	Tue Dec 17 10:55:59 2013 +0100
    24.3 @@ -62,6 +62,7 @@
    24.4  import com.sun.tools.classfile.Synthetic_attribute;
    24.5  
    24.6  import static com.sun.tools.classfile.AccessFlags.*;
    24.7 +import com.sun.tools.javac.util.StringUtils;
    24.8  
    24.9  /*
   24.10   *  A writer for writing Attributes as text.
   24.11 @@ -690,14 +691,14 @@
   24.12      }
   24.13  
   24.14      static String toHex(int i) {
   24.15 -        return Integer.toString(i, 16).toUpperCase();
   24.16 +        return StringUtils.toUpperCase(Integer.toString(i, 16));
   24.17      }
   24.18  
   24.19      static String toHex(int i, int w) {
   24.20 -        String s = Integer.toHexString(i).toUpperCase();
   24.21 +        String s = StringUtils.toUpperCase(Integer.toHexString(i));
   24.22          while (s.length() < w)
   24.23              s = "0" + s;
   24.24 -        return s.toUpperCase();
   24.25 +        return StringUtils.toUpperCase(s);
   24.26      }
   24.27  
   24.28      private AnnotationWriter annotationWriter;
    25.1 --- a/src/share/classes/com/sun/tools/javap/TypeAnnotationWriter.java	Wed Jun 04 20:01:13 2014 +0100
    25.2 +++ b/src/share/classes/com/sun/tools/javap/TypeAnnotationWriter.java	Tue Dec 17 10:55:59 2013 +0100
    25.3 @@ -37,6 +37,7 @@
    25.4  import java.util.HashMap;
    25.5  import java.util.List;
    25.6  import java.util.Map;
    25.7 +import com.sun.tools.javac.util.StringUtils;
    25.8  
    25.9  /**
   25.10   * Annotate instructions with details about type annotations.
   25.11 @@ -115,7 +116,7 @@
   25.12                  print("@");
   25.13                  annotationWriter.write(n.anno, false, true);
   25.14                  print(", ");
   25.15 -                println(n.kind.toString().toLowerCase());
   25.16 +                println(StringUtils.toLowerCase(n.kind.toString()));
   25.17              }
   25.18          }
   25.19      }
    26.1 --- a/src/share/classes/com/sun/tools/sjavac/server/CompilerThread.java	Wed Jun 04 20:01:13 2014 +0100
    26.2 +++ b/src/share/classes/com/sun/tools/sjavac/server/CompilerThread.java	Tue Dec 17 10:55:59 2013 +0100
    26.3 @@ -49,6 +49,7 @@
    26.4  import com.sun.tools.javac.util.Context;
    26.5  import com.sun.tools.javac.util.Log;
    26.6  import com.sun.tools.javac.util.BaseFileManager;
    26.7 +import com.sun.tools.javac.util.StringUtils;
    26.8  import com.sun.tools.sjavac.comp.Dependencies;
    26.9  import com.sun.tools.sjavac.comp.JavaCompilerWithDeps;
   26.10  import com.sun.tools.sjavac.comp.SmartFileManager;
   26.11 @@ -256,7 +257,7 @@
   26.12              // Load visible sources
   26.13              Set<URI> visibleSources = new HashSet<URI>();
   26.14              boolean fix_drive_letter_case =
   26.15 -                System.getProperty("os.name").toLowerCase().startsWith("windows");
   26.16 +                StringUtils.toLowerCase(System.getProperty("os.name")).startsWith("windows");
   26.17              for (;;) {
   26.18                  String l = in.readLine();
   26.19                  if (l == null)
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/test/tools/javac/NoStringToLower.java	Tue Dec 17 10:55:59 2013 +0100
    27.3 @@ -0,0 +1,128 @@
    27.4 +/*
    27.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    27.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    27.7 + *
    27.8 + * This code is free software; you can redistribute it and/or modify it
    27.9 + * under the terms of the GNU General Public License version 2 only, as
   27.10 + * published by the Free Software Foundation.
   27.11 + *
   27.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   27.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   27.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   27.15 + * version 2 for more details (a copy is included in the LICENSE file that
   27.16 + * accompanied this code).
   27.17 + *
   27.18 + * You should have received a copy of the GNU General Public License version
   27.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   27.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   27.21 + *
   27.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   27.23 + * or visit www.oracle.com if you need additional information or have any
   27.24 + * questions.
   27.25 + */
   27.26 +
   27.27 +/*
   27.28 + * @test
   27.29 + * @bug 8029800
   27.30 + * @summary String.toLowerCase()/toUpperCase is generally dangerous, check it is not used in langtools
   27.31 + */
   27.32 +
   27.33 +import java.io.*;
   27.34 +import java.util.*;
   27.35 +import javax.tools.*;
   27.36 +import com.sun.tools.classfile.*;
   27.37 +import com.sun.tools.classfile.ConstantPool.CONSTANT_Methodref_info;
   27.38 +
   27.39 +public class NoStringToLower {
   27.40 +    public static void main(String... args) throws Exception {
   27.41 +        NoStringToLower c = new NoStringToLower();
   27.42 +        if (c.run(args))
   27.43 +            return;
   27.44 +
   27.45 +        if (is_jtreg())
   27.46 +            throw new Exception(c.errors + " errors occurred");
   27.47 +        else
   27.48 +            System.exit(1);
   27.49 +    }
   27.50 +
   27.51 +    static boolean is_jtreg() {
   27.52 +        return (System.getProperty("test.src") != null);
   27.53 +    }
   27.54 +
   27.55 +    /**
   27.56 +     * Main entry point.
   27.57 +     */
   27.58 +    boolean run(String... args) throws Exception {
   27.59 +        JavaCompiler c = ToolProvider.getSystemJavaCompiler();
   27.60 +        JavaFileManager fm = c.getStandardFileManager(null, null, null);
   27.61 +        JavaFileManager.Location javacLoc = findJavacLocation(fm);
   27.62 +        String[] pkgs = {
   27.63 +            "javax.annotation.processing",
   27.64 +            "javax.lang.model",
   27.65 +            "javax.tools",
   27.66 +            "com.sun.source",
   27.67 +            "com.sun.tools"
   27.68 +        };
   27.69 +        for (String pkg: pkgs) {
   27.70 +            for (JavaFileObject fo: fm.list(javacLoc,
   27.71 +                    pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) {
   27.72 +                scan(fo);
   27.73 +            }
   27.74 +        }
   27.75 +
   27.76 +        return (errors == 0);
   27.77 +    }
   27.78 +
   27.79 +    // depending on how the test is run, javac may be on bootclasspath or classpath
   27.80 +    JavaFileManager.Location findJavacLocation(JavaFileManager fm) {
   27.81 +        JavaFileManager.Location[] locns =
   27.82 +            { StandardLocation.PLATFORM_CLASS_PATH, StandardLocation.CLASS_PATH };
   27.83 +        try {
   27.84 +            for (JavaFileManager.Location l: locns) {
   27.85 +                JavaFileObject fo = fm.getJavaFileForInput(l,
   27.86 +                    "com.sun.tools.javac.Main", JavaFileObject.Kind.CLASS);
   27.87 +                if (fo != null)
   27.88 +                    return l;
   27.89 +            }
   27.90 +        } catch (IOException e) {
   27.91 +            throw new Error(e);
   27.92 +        }
   27.93 +        throw new IllegalStateException("Cannot find javac");
   27.94 +    }
   27.95 +
   27.96 +    /**
   27.97 +     * Verify there are no references to String.toLowerCase() in a class file.
   27.98 +     */
   27.99 +    void scan(JavaFileObject fo) throws IOException {
  27.100 +        InputStream in = fo.openInputStream();
  27.101 +        try {
  27.102 +            ClassFile cf = ClassFile.read(in);
  27.103 +            for (ConstantPool.CPInfo cpinfo: cf.constant_pool.entries()) {
  27.104 +                if (cpinfo.getTag() == ConstantPool.CONSTANT_Methodref) {
  27.105 +                    CONSTANT_Methodref_info ref = (CONSTANT_Methodref_info) cpinfo;
  27.106 +                    String methodDesc = ref.getClassInfo().getName() + "." + ref.getNameAndTypeInfo().getName() + ":" + ref.getNameAndTypeInfo().getType();
  27.107 +
  27.108 +                    if ("java/lang/String.toLowerCase:()Ljava/lang/String;".equals(methodDesc)) {
  27.109 +                        error("found reference to String.toLowerCase() in: " + fo.getName());
  27.110 +                    }
  27.111 +                    if ("java/lang/String.toUpperCase:()Ljava/lang/String;".equals(methodDesc)) {
  27.112 +                        error("found reference to String.toLowerCase() in: " + fo.getName());
  27.113 +                    }
  27.114 +                }
  27.115 +            }
  27.116 +        } catch (ConstantPoolException ignore) {
  27.117 +        } finally {
  27.118 +            in.close();
  27.119 +        }
  27.120 +    }
  27.121 +
  27.122 +    /**
  27.123 +     * Report an error.
  27.124 +     */
  27.125 +    void error(String msg) {
  27.126 +        System.err.println("Error: " + msg);
  27.127 +        errors++;
  27.128 +    }
  27.129 +
  27.130 +    int errors;
  27.131 +}
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/test/tools/javac/util/StringUtilsTest.java	Tue Dec 17 10:55:59 2013 +0100
    28.3 @@ -0,0 +1,66 @@
    28.4 +/*
    28.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
    28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    28.7 + *
    28.8 + * This code is free software; you can redistribute it and/or modify it
    28.9 + * under the terms of the GNU General Public License version 2 only, as
   28.10 + * published by the Free Software Foundation.
   28.11 + *
   28.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   28.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   28.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   28.15 + * version 2 for more details (a copy is included in the LICENSE file that
   28.16 + * accompanied this code).
   28.17 + *
   28.18 + * You should have received a copy of the GNU General Public License version
   28.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   28.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   28.21 + *
   28.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   28.23 + * or visit www.oracle.com if you need additional information or have any
   28.24 + * questions.
   28.25 + */
   28.26 +
   28.27 +/**
   28.28 + * @test
   28.29 + * @bug 8029800
   28.30 + * @summary Unit test StringUtils
   28.31 + * @run main StringUtilsTest
   28.32 + */
   28.33 +
   28.34 +import java.util.Locale;
   28.35 +import java.util.Objects;
   28.36 +import com.sun.tools.javac.util.StringUtils;
   28.37 +
   28.38 +public class StringUtilsTest {
   28.39 +    public static void main(String... args) throws Exception {
   28.40 +        new StringUtilsTest().run();
   28.41 +    }
   28.42 +
   28.43 +    void run() throws Exception {
   28.44 +        Locale.setDefault(new Locale("tr", "TR"));
   28.45 +
   28.46 +        //verify the properties of the default locale:
   28.47 +        assertEquals("\u0131", "I".toLowerCase());
   28.48 +        assertEquals("\u0130", "i".toUpperCase());
   28.49 +
   28.50 +        //verify the StringUtils does what it should
   28.51 +        assertEquals("i", StringUtils.toLowerCase("I"));
   28.52 +        assertEquals("I", StringUtils.toUpperCase("i"));
   28.53 +
   28.54 +        //verify we can use index from indexOf of toLowerCase String in the original:
   28.55 +        assertEquals(2, StringUtils.toLowerCase("\u0130\u0130lookFor").indexOf("lookfor"));
   28.56 +    }
   28.57 +
   28.58 +    void assertEquals(String expected, String actual) {
   28.59 +        if (!Objects.equals(expected, actual)) {
   28.60 +            throw new IllegalStateException("expected=" + expected + "; actual=" + actual);
   28.61 +        }
   28.62 +    }
   28.63 +
   28.64 +    void assertEquals(int expected, int actual) {
   28.65 +        if (expected != actual) {
   28.66 +            throw new IllegalStateException("expected=" + expected + "; actual=" + actual);
   28.67 +        }
   28.68 +    }
   28.69 +}

mercurial