harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
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 GMT
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<AbstractPreferences> 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<Object> 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) {}
+    }
 }



Mime
View raw message