Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 8535 invoked from network); 2 Jan 2009 04:44:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Jan 2009 04:44:59 -0000 Received: (qmail 12655 invoked by uid 500); 2 Jan 2009 04:44:59 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 12640 invoked by uid 500); 2 Jan 2009 04:44:59 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 12631 invoked by uid 99); 2 Jan 2009 04:44:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Jan 2009 20:44:59 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Jan 2009 04:44:58 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8D61A238895D; Thu, 1 Jan 2009 20:44:38 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r730667 - in /harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs: AbstractPreferences.java FilePreferencesImpl.java XMLParser.java Date: Fri, 02 Jan 2009 04:44:38 -0000 To: commits@harmony.apache.org From: ndbeyer@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090102044438.8D61A238895D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ndbeyer Date: Thu Jan 1 20:44:38 2009 New Revision: 730667 URL: http://svn.apache.org/viewvc?rev=730667&view=rev Log: clean up some code based on FindBugs warnings Modified: harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java Modified: harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java?rev=730667&r1=730666&r2=730667&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java (original) +++ harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/AbstractPreferences.java Thu Jan 1 20:44:38 2009 @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; +import java.util.Collection; import java.util.EventListener; import java.util.EventObject; import java.util.HashMap; @@ -347,7 +348,7 @@ for (int i = 0; i < names.length; i++) { result.add(names[i]); } - return result.toArray(new String[0]); + return result.toArray(new String[result.size()]); } } @@ -733,10 +734,11 @@ cachedNode.put(childrenNames[i], child); } } - AbstractPreferences[] children = cachedNode - .values().toArray(new AbstractPreferences[0]); - for (int i = 0; i < children.length; i++) { - children[i].removeNodeImpl(); + + final Collection values = cachedNode.values(); + final AbstractPreferences[] children = values.toArray(new AbstractPreferences[values.size()]); + for (AbstractPreferences child : children) { + child.removeNodeImpl(); } removeNodeSpi(); isRemoved = true; Modified: harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java?rev=730667&r1=730666&r2=730667&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java (original) +++ harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/FilePreferencesImpl.java Thu Jan 1 20:44:38 2009 @@ -199,7 +199,8 @@ @Override protected String[] keysSpi() throws BackingStoreException { - return prefs.keySet().toArray(new String[0]); + final Set ks = prefs.keySet(); + return ks.toArray(new String[ks.size()]); } @Override Modified: harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java?rev=730667&r1=730666&r2=730667&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java (original) +++ harmony/enhanced/classlib/trunk/modules/prefs/src/main/java/java/util/prefs/XMLParser.java Thu Jan 1 20:44:38 2009 @@ -26,6 +26,7 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.StringReader; +import java.io.Writer; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.security.AccessController; @@ -433,14 +434,6 @@ return loadFilePrefsImpl(file); } }); - - // try { - // //FIXME: lines below can be deleted, because it is not required to - // persistent at the very beginning - // flushFilePrefs(file, result); - // } catch (IOException e) { - // e.printStackTrace(); - // } } static Properties loadFilePrefsImpl(final File file) { @@ -451,7 +444,6 @@ InputStream in = null; FileLock lock = null; try { - FileInputStream istream = new FileInputStream(file); in = new BufferedInputStream(istream); FileChannel channel = istream.getChannel(); @@ -467,17 +459,14 @@ result.setProperty(key, value); } return result; - } catch (Exception e) { - e.printStackTrace(); + } catch (IOException e) { + } catch (SAXException e) { + } catch (TransformerException e) { + // transform shouldn't fail for xpath call + throw new AssertionError(e); } finally { - try { - lock.release(); - } catch (Exception e) {//ignore - } - try { - in.close(); - } catch (Exception e) {//ignore - } + releaseQuietly(lock); + closeQuietly(in); } } else { file.delete(); @@ -525,16 +514,35 @@ } out.flush(); } finally { - try { - lock.release(); - } catch (Exception e) {//ignore - } - try { - if (null != out) { - out.close(); - } - } catch (Exception e) {//ignore - } + releaseQuietly(lock); + closeQuietly(out); } } + + private static void releaseQuietly(FileLock lock) { + if (lock == null) { + return; + } + try { + lock.release(); + } catch (IOException e) {} + } + + private static void closeQuietly(Writer out) { + if (out == null) { + return; + } + try { + out.close(); + } catch (IOException e) {} + } + + private static void closeQuietly(InputStream in) { + if (in == null) { + return; + } + try { + in.close(); + } catch (IOException e) {} + } }