From dev-return-12992-apmail-directory-dev-archive=directory.apache.org@directory.apache.org Thu Aug 17 17:00:09 2006 Return-Path: Delivered-To: apmail-directory-dev-archive@www.apache.org Received: (qmail 7783 invoked from network); 17 Aug 2006 17:00:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 Aug 2006 17:00:08 -0000 Received: (qmail 1149 invoked by uid 500); 17 Aug 2006 17:00:00 -0000 Delivered-To: apmail-directory-dev-archive@directory.apache.org Received: (qmail 1091 invoked by uid 500); 17 Aug 2006 17:00:00 -0000 Mailing-List: contact dev-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Apache Directory Developers List" Delivered-To: mailing list dev@directory.apache.org Received: (qmail 1057 invoked by uid 99); 17 Aug 2006 16:59:59 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Aug 2006 09:59:59 -0700 X-ASF-Spam-Status: No, hits=1.9 required=10.0 tests=DNS_FROM_RFC_ABUSE,DNS_FROM_RFC_POST,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of aok123@bellsouth.net designates 205.152.59.69 as permitted sender) Received: from [205.152.59.69] (HELO imf21aec.mail.bellsouth.net) (205.152.59.69) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Aug 2006 09:59:57 -0700 Received: from ibm63aec.bellsouth.net ([65.80.200.112]) by imf21aec.mail.bellsouth.net with ESMTP id <20060817165936.QQIU15881.imf21aec.mail.bellsouth.net@ibm63aec.bellsouth.net> for ; Thu, 17 Aug 2006 12:59:36 -0400 Received: from [172.16.1.7] (really [65.80.200.112]) by ibm63aec.bellsouth.net with ESMTP id <20060817165936.DMZH8982.ibm63aec.bellsouth.net@[172.16.1.7]> for ; Thu, 17 Aug 2006 12:59:36 -0400 Message-ID: <44E4A0EF.6020604@bellsouth.net> Date: Thu, 17 Aug 2006 13:01:35 -0400 From: Alex Karasulu User-Agent: Thunderbird 1.5.0.5 (X11/20060728) MIME-Version: 1.0 To: Apache Directory Developers List Subject: Re: Bug parade References: <44E470C4.2040509@levigo.de> <44E48D28.2060407@levigo.de> In-Reply-To: <44E48D28.2060407@levigo.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Jörg Henne wrote: > Hi, > > 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 > Class[0]); > defaultCharset = ((Charset) method.invoke(null, new > Object[0])).name(); > } catch (Exception e) { > // fall back to olg method > defaultCharset = new OutputStreamWriter(new > ByteArrayOutputStream()) > .getEncoding(); > } > 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. +1 I like the use of reflection here btw. Sounds like the 1.5 dependency is Charset from java.nio.charset.Charset. Why not go all the way and dynamically load the class itself and call the method on it? Meaning why directly reference Charset at all? > private static String defaultCharset; > /** > * @return The default charset > */ > public static final String getDefaultCharsetName() > { > if (null == defaultCharset) > try { Class clazz = Class.forName( "java.nio.charset.Charset" ); > Method method = clazz.getMethod("defaultCharset", new > Class[0]); > defaultCharset = ((Charset) method.invoke(null, new > Object[0])).name(); > } catch (Exception e) { > // fall back to olg method > defaultCharset = new OutputStreamWriter(new > ByteArrayOutputStream()) > .getEncoding(); > } > return defaultCharset; > } This would lift the compile dep on 1.5. Regards, Alex