Andrew Zhang wrote:
Hi, all

Things are a little bit complex when I tried to implement this workaround.

Consider availableCharsets() method from Charset.java, which loads provider
classes from configuration file.

Please see my comments inline.

final ClassLoader cl = getContextClassLoader();
 if (null != cl) { // what shall we do if context class loader is null?
  try {
   //  context classloader is used to get resources.
   Enumeration e = cl
     .getResources(PROVIDER_CONFIGURATION_FILE_NAME);
   // Examine each configuration file
   while (e.hasMoreElements()) {
// here, context classloader is used to load class.
// If system classloader is used as backup when context classloader fails to
load, it seems illogical, because it's context classloader who get
resources.
// It should be the same classloader who gets resources and loads
corresponding classes.
    loadConfiguredCharsets((URL) e.nextElement(), cl, charsets);
   }
  } catch (IOException ex) {
   // Unexpected ClassLoader exception, ignore
  }
 }

If we put another copy code after this section, using "system classloader" instead of "context classloader", it also seems illogical. What shall we do
if context classloader fails to load a provider charset class? Should it
throw an error as spec requires or pass silently?
Hmm... I think more serious problem here is that the classloader is used not only to load the CharsetProvider class, but also to load the configuration files, so if we choose to try context classloader then system classloader, they may load different config files! IMHO, the behavior will be contradict with both RI and spec. I suggest we give up the *third way* and choose one(RI or spec) to follow, from others' comments, Sun has been aware of this for long time, so they must have reason not to fix the codes, maybe just because this is a not trivial difference(it may be significant for server application which has multi classloaders and special charsets), so I suggest we follow RI.



To sum up, it's hard to follow RI, and comply with spec simultaneously. We
have to choose one of them. Spec or RI?

I don't think RI would change its behaviour in later release. In fact, the "bug" still exists in SUN 6.0 rc version. Personally, +1 for following RI.

Any comments or better suggestions?

Thanks!




--
Paulex Yang
China Software Development Lab
IBM



---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to