Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6853689

Charset.lookup2() method should be synchronized on internal cache.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 6
    • core-libs

      FULL PRODUCT VERSION :
      all

      ADDITIONAL OS VERSION INFORMATION :
      not important

      A DESCRIPTION OF THE PROBLEM :
      If method lookup2() would be interrupted by another thread while swapping cache1 against cache2 method lookup potentially could return the wrong charset.



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Charset {
          ...
          private static Charset lookup2(String charsetName) {
              Object[] a;
              Charset cs;
              if ((a = cache2) != null && charsetName.equals(a[0])) { // TODO: synchronize !!!
                  cache2 = cache1;
                  cache1 = a;
                  cs = (Charset)a[1];
              }
              else if ((cs = standardProvider.charsetForName(charsetName)) != null ||
                      (cs = lookupExtendedCharset(charsetName)) != null ||
                      (cs = lookupViaProviders(charsetName)) != null)
                  cache(charsetName, cs);
              else
                  // Only need to check the name if we didn't find a charset for it
                  checkName(charsetName);
              return cs;
          }
          ...
      }
      ---------- END SOURCE ----------

            sherman Xueming Shen
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: