directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jörg Henne <>
Subject Re: Bug parade
Date Thu, 17 Aug 2006 15:37:12 GMT

Emmanuel Lecharny schrieb:
> Hi,
> I don't think that the line 48 in StringTools is related to 1.5. It's 
> just a way to get the charSet, considering that it will work for 1.4, 
> but will return a different result.
> Can you confirm this assertion, Jörg?

as I see it, Charset.defaultCharset() is available only since 1.5 (see 
its @since annotation). Having this constant initializer there, causes 
at least a compile-time dependency on 1.5. I haven't tried, but I don't 
see why it would not also cause a run-time dependency.

My recommendatil would be this:   

   private static String defaultCharset;
     * @return The default charset
    public static final String getDefaultCharsetName()
      if (null == defaultCharset)
        try {
          Method method = Charset.class.getMethod("defaultCharset", new 
          defaultCharset = ((Charset) method.invoke(null, new 
        } catch (Exception e) {
          // fall back to olg method
          defaultCharset = new OutputStreamWriter(new 
      return defaultCharset;

Doing away with the reflection is also possible: simply catching 
NoSuchMethodError should allow a graceful fallback to the old method, 
too. However, this comes at the price of a compile-time dependency on 1.5.

Joerg Henne

View raw message