United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6898310 (cs) Charset cache lookups should be synchronized
JDK-6898310 : (cs) Charset cache lookups should be synchronized

Details
Type:
Bug
Submit Date:
2009-11-05
Status:
Closed
Updated Date:
2013-04-16
Project Name:
JDK
Resolved Date:
2011-06-28
Component:
core-libs
OS:
generic
Sub-Component:
java.nio
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.2
Fixed Versions:
1.4.2_33 (b02)

Related Reports
Backport:
Backport:
Backport:
Backport:
Relates:
Relates:

Sub Tasks

Description
Charset cache access method, lookup() needs to be synchronized.
One lookup() had been already done as the fix for 4685305.

Considering to the purpose of the above resolution, 
one more lookup() should be synchronized as well.
Specifically speaking, the line#182 should be synchronized.

=== ./jdk/share/classes/sun/nio/cs/AbstractCharsetProvider.java (jdk7b75)===
....
?? 158      public final Charset charsetForName(String charsetName) {
?? 159          synchronized (this) {              <===== This is the fix for 4685305
?? 160              init();
?? 161              return lookup(canonicalize(charsetName));
?? 162          }
?? 163      }
?? 164
   165      public final Iterator<Charset> charsets() {
   166
   167          final ArrayList ks;
   168          synchronized (this) {
   169              init();
   170              ks = new ArrayList(classMap.keySet());
   171          }
   172
   173          return new Iterator<Charset>() {
   174                  Iterator i = ks.iterator();
   175
   176                  public boolean hasNext() {
   177                      return i.hasNext();
   178                  }
   179
   180                  public Charset next() {
   181                      String csn = (String)i.next();
   182                      return lookup(csn);      <====== Should this line be synchronized ?
   183                  }
   184
   185                  public void remove() {
   186                      throw new UnsupportedOperationException();
   187                  }
   188              };
   189      }
....
======================

                                    

Comments
EVALUATION

we can add the extra synchronised block as requested or perhaps even just synchronise the lookup method call.
                                     
2011-04-11



Hardware and Software, Engineered to Work Together