8043186: javac test langtools/tools/javac/util/StringUtilsTest.java fails

Thu, 29 May 2014 10:48:00 +0200

author
jlahoda
date
Thu, 29 May 2014 10:48:00 +0200
changeset 2415
7ceaee0e497b
parent 2414
17ce329d7bd0
child 2416
63ef1e0410d1

8043186: javac test langtools/tools/javac/util/StringUtilsTest.java fails
Summary: The result of String.toLowerCase.indexOf does not always point at the start of the given string in the non-lowercased text.
Reviewed-by: jjg, bpatel

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/javac/util/StringUtils.java file | annotate | diff | comparison | revisions
test/com/sun/javadoc/testRelativeLinks/TestRelativeLinks.java file | annotate | diff | comparison | revisions
test/com/sun/javadoc/testRelativeLinks/pkg/C.java file | annotate | diff | comparison | revisions
test/com/sun/javadoc/testTopOption/TestTopOption.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/doclets/formats/html/HtmlDocletWriter.java	Thu Dec 19 11:38:45 2013 -0500
     1.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java	Thu May 29 10:48:00 2014 +0200
     1.3 @@ -28,6 +28,8 @@
     1.4  import java.io.*;
     1.5  import java.text.SimpleDateFormat;
     1.6  import java.util.*;
     1.7 +import java.util.regex.Matcher;
     1.8 +import java.util.regex.Pattern;
     1.9  
    1.10  import com.sun.javadoc.*;
    1.11  import com.sun.tools.doclets.formats.html.markup.*;
    1.12 @@ -139,42 +141,37 @@
    1.13          if (index < 0) {
    1.14              return htmlstr;
    1.15          }
    1.16 -        String lowerHtml = StringUtils.toLowerCase(htmlstr);
    1.17 -        final String docroot = "{@docroot}";
    1.18 -        // Return index of first occurrence of {@docroot}
    1.19 -        // Note: {@docRoot} is not case sensitive when passed in w/command line option
    1.20 -        index = lowerHtml.indexOf(docroot, index);
    1.21 -        if (index < 0) {
    1.22 +        Matcher docrootMatcher = docrootPattern.matcher(htmlstr);
    1.23 +        if (!docrootMatcher.find()) {
    1.24              return htmlstr;
    1.25          }
    1.26          StringBuilder buf = new StringBuilder();
    1.27 -        int previndex = 0;
    1.28 -        while (true) {
    1.29 -            // Search for lowercase version of {@docRoot}
    1.30 -            index = lowerHtml.indexOf(docroot, previndex);
    1.31 -            // If next {@docRoot} tag not found, append rest of htmlstr and exit loop
    1.32 -            if (index < 0) {
    1.33 -                buf.append(htmlstr.substring(previndex));
    1.34 -                break;
    1.35 -            }
    1.36 -            // If next {@docroot} tag found, append htmlstr up to start of tag
    1.37 -            buf.append(htmlstr.substring(previndex, index));
    1.38 -            previndex = index + docroot.length();
    1.39 -            if (configuration.docrootparent.length() > 0 && htmlstr.startsWith("/..", previndex)) {
    1.40 +        int prevEnd = 0;
    1.41 +        do {
    1.42 +            int match = docrootMatcher.start();
    1.43 +            // append htmlstr up to start of next {@docroot}
    1.44 +            buf.append(htmlstr.substring(prevEnd, match));
    1.45 +            prevEnd = docrootMatcher.end();
    1.46 +            if (configuration.docrootparent.length() > 0 && htmlstr.startsWith("/..", prevEnd)) {
    1.47                  // Insert the absolute link if {@docRoot} is followed by "/..".
    1.48                  buf.append(configuration.docrootparent);
    1.49 -                previndex += 3;
    1.50 +                prevEnd += 3;
    1.51              } else {
    1.52                  // Insert relative path where {@docRoot} was located
    1.53                  buf.append(pathToRoot.isEmpty() ? "." : pathToRoot.getPath());
    1.54              }
    1.55              // Append slash if next character is not a slash
    1.56 -            if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') {
    1.57 +            if (prevEnd < htmlstr.length() && htmlstr.charAt(prevEnd) != '/') {
    1.58                  buf.append('/');
    1.59              }
    1.60 -        }
    1.61 +        } while (docrootMatcher.find());
    1.62 +        buf.append(htmlstr.substring(prevEnd));
    1.63          return buf.toString();
    1.64      }
    1.65 +    //where:
    1.66 +        // Note: {@docRoot} is not case sensitive when passed in w/command line option:
    1.67 +        private static final Pattern docrootPattern =
    1.68 +                Pattern.compile(Pattern.quote("{@docroot}"), Pattern.CASE_INSENSITIVE);
    1.69  
    1.70      /**
    1.71       * Get the script to show or hide the All classes link.
    1.72 @@ -1690,13 +1687,13 @@
    1.73          }
    1.74  
    1.75          //Redirect all relative links.
    1.76 -        int end, begin = StringUtils.toLowerCase(text).indexOf("<a");
    1.77 +        int end, begin = StringUtils.indexOfIgnoreCase(text, "<a");
    1.78          if(begin >= 0){
    1.79              StringBuilder textBuff = new StringBuilder(text);
    1.80  
    1.81              while(begin >=0){
    1.82                  if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) {
    1.83 -                    begin = StringUtils.toLowerCase(textBuff.toString()).indexOf("<a", begin + 1);
    1.84 +                    begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
    1.85                      continue;
    1.86                  }
    1.87  
    1.88 @@ -1732,7 +1729,7 @@
    1.89                          + redirectPathFromRoot.resolve(relativeLink).getPath();
    1.90                      textBuff.replace(begin, end, relativeLink);
    1.91                  }
    1.92 -                begin = StringUtils.toLowerCase(textBuff.toString()).indexOf("<a", begin + 1);
    1.93 +                begin = StringUtils.indexOfIgnoreCase(textBuff.toString(), "<a", begin + 1);
    1.94              }
    1.95              return textBuff.toString();
    1.96          }
     2.1 --- a/src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java	Thu Dec 19 11:38:45 2013 -0500
     2.2 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java	Thu May 29 10:48:00 2014 +0200
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     2.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     2.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.8   *
     2.9   * This code is free software; you can redistribute it and/or modify it
    2.10 @@ -332,24 +332,6 @@
    2.11      }
    2.12  
    2.13      /**
    2.14 -     * Parse the &lt;Code&gt; tag and return the text.
    2.15 -     */
    2.16 -    protected String parseCodeTag(String tag){
    2.17 -        if(tag == null){
    2.18 -            return "";
    2.19 -        }
    2.20 -
    2.21 -        String lc = StringUtils.toLowerCase(tag);
    2.22 -        int begin = lc.indexOf("<code>");
    2.23 -        int end = lc.indexOf("</code>");
    2.24 -        if(begin == -1 || end == -1 || end <= begin){
    2.25 -            return tag;
    2.26 -        } else {
    2.27 -            return tag.substring(begin + 6, end);
    2.28 -        }
    2.29 -    }
    2.30 -
    2.31 -    /**
    2.32       * {@inheritDoc}
    2.33       */
    2.34      protected static void addImplementsInfo(HtmlDocletWriter writer,
     3.1 --- a/src/share/classes/com/sun/tools/javac/util/StringUtils.java	Thu Dec 19 11:38:45 2013 -0500
     3.2 +++ b/src/share/classes/com/sun/tools/javac/util/StringUtils.java	Thu May 29 10:48:00 2014 +0200
     3.3 @@ -1,5 +1,5 @@
     3.4  /*
     3.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     3.6 + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
     3.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8   *
     3.9   * This code is free software; you can redistribute it and/or modify it
    3.10 @@ -26,6 +26,8 @@
    3.11  package com.sun.tools.javac.util;
    3.12  
    3.13  import java.util.Locale;
    3.14 +import java.util.regex.Matcher;
    3.15 +import java.util.regex.Pattern;
    3.16  
    3.17  /** A collection of utilities for String manipulation.
    3.18   *
    3.19 @@ -50,4 +52,19 @@
    3.20          return source.toUpperCase(Locale.US);
    3.21      }
    3.22  
    3.23 +    /**Case insensitive version of {@link String#indexOf(java.lang.String)}. Equivalent to
    3.24 +     * {@code text.indexOf(str)}, except the matching is case insensitive.
    3.25 +     */
    3.26 +    public static int indexOfIgnoreCase(String text, String str) {
    3.27 +        return indexOfIgnoreCase(text, str, 0);
    3.28 +    }
    3.29 +
    3.30 +    /**Case insensitive version of {@link String#indexOf(java.lang.String, int)}. Equivalent to
    3.31 +     * {@code text.indexOf(str, startIndex)}, except the matching is case insensitive.
    3.32 +     */
    3.33 +    public static int indexOfIgnoreCase(String text, String str, int startIndex) {
    3.34 +        Matcher m = Pattern.compile(Pattern.quote(str), Pattern.CASE_INSENSITIVE).matcher(text);
    3.35 +        return m.find(startIndex) ? m.start() : -1;
    3.36 +    }
    3.37 +
    3.38  }
     4.1 --- a/test/com/sun/javadoc/testRelativeLinks/TestRelativeLinks.java	Thu Dec 19 11:38:45 2013 -0500
     4.2 +++ b/test/com/sun/javadoc/testRelativeLinks/TestRelativeLinks.java	Thu May 29 10:48:00 2014 +0200
     4.3 @@ -23,7 +23,7 @@
     4.4  
     4.5  /*
     4.6   * @test
     4.7 - * @bug      4460354 8014636
     4.8 + * @bug      4460354 8014636 8043186
     4.9   * @summary  Test to make sure that relative paths are redirected in the
    4.10   *           output so that they are not broken.
    4.11   * @author   jamieh
     5.1 --- a/test/com/sun/javadoc/testRelativeLinks/pkg/C.java	Thu Dec 19 11:38:45 2013 -0500
     5.2 +++ b/test/com/sun/javadoc/testRelativeLinks/pkg/C.java	Thu May 29 10:48:00 2014 +0200
     5.3 @@ -1,5 +1,5 @@
     5.4  /*
     5.5 - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
     5.6 + * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
     5.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.8   *
     5.9   * This code is free software; you can redistribute it and/or modify it
    5.10 @@ -30,7 +30,7 @@
    5.11  public class C {
    5.12  
    5.13      /**
    5.14 -     * Here is a relative link in a field:
    5.15 +     * Here is a relative link in a field:\u0130
    5.16       * <a href="relative-field-link.html">relative field link</a>.
    5.17       */
    5.18      public C field = null;
     6.1 --- a/test/com/sun/javadoc/testTopOption/TestTopOption.java	Thu Dec 19 11:38:45 2013 -0500
     6.2 +++ b/test/com/sun/javadoc/testTopOption/TestTopOption.java	Thu May 29 10:48:00 2014 +0200
     6.3 @@ -23,7 +23,7 @@
     6.4  
     6.5  /*
     6.6   * @test
     6.7 - * @bug      6227616
     6.8 + * @bug      6227616 8043186
     6.9   * @summary  Test the new -top option.
    6.10   * @author   jamieh
    6.11   * @library  ../lib/
    6.12 @@ -39,7 +39,7 @@
    6.13  
    6.14      //Javadoc arguments.
    6.15      private static final String[] ARGS = new String[] {
    6.16 -        "-overview", "SRC_DIR + FS + overview.html", "-use", "-top", "TOP TEXT", "-d", BUG_ID, "-sourcepath",
    6.17 +        "-overview", SRC_DIR + FS + "overview.html", "-use", "-top", "\u0130{@docroot}TOP TEXT", "-d", BUG_ID, "-sourcepath",
    6.18          SRC_DIR, "pkg"
    6.19      };
    6.20  
     7.1 --- a/test/tools/javac/util/StringUtilsTest.java	Thu Dec 19 11:38:45 2013 -0500
     7.2 +++ b/test/tools/javac/util/StringUtilsTest.java	Thu May 29 10:48:00 2014 +0200
     7.3 @@ -1,5 +1,5 @@
     7.4  /*
     7.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     7.6 + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
     7.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.8   *
     7.9   * This code is free software; you can redistribute it and/or modify it
    7.10 @@ -23,7 +23,7 @@
    7.11  
    7.12  /**
    7.13   * @test
    7.14 - * @bug 8029800
    7.15 + * @bug 8029800 8043186
    7.16   * @summary Unit test StringUtils
    7.17   * @run main StringUtilsTest
    7.18   */
    7.19 @@ -44,12 +44,14 @@
    7.20          assertEquals("\u0131", "I".toLowerCase());
    7.21          assertEquals("\u0130", "i".toUpperCase());
    7.22  
    7.23 -        //verify the StringUtils does what it should
    7.24 +        //verify the StringUtils.toLowerCase/toUpperCase do what they should:
    7.25          assertEquals("i", StringUtils.toLowerCase("I"));
    7.26          assertEquals("I", StringUtils.toUpperCase("i"));
    7.27  
    7.28 -        //verify we can use index from indexOf of toLowerCase String in the original:
    7.29 -        assertEquals(2, StringUtils.toLowerCase("\u0130\u0130lookFor").indexOf("lookfor"));
    7.30 +        //verify StringUtils.caseInsensitiveIndexOf works:
    7.31 +        assertEquals(2, StringUtils.indexOfIgnoreCase("  lookFor", "lookfor"));
    7.32 +        assertEquals(11, StringUtils.indexOfIgnoreCase("  lookFor  LOOKfor", "lookfor", 11));
    7.33 +        assertEquals(2, StringUtils.indexOfIgnoreCase("\u0130\u0130lookFor", "lookfor"));
    7.34      }
    7.35  
    7.36      void assertEquals(String expected, String actual) {

mercurial