incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r929079 - /incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
Date Tue, 30 Mar 2010 11:06:15 GMT
Author: simonetripodi
Date: Tue Mar 30 11:06:14 2010
New Revision: 929079

URL: http://svn.apache.org/viewvc?rev=929079&view=rev
Log:
input streams always closed quietly

Modified:
    incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java

Modified: incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java?rev=929079&r1=929078&r2=929079&view=diff
==============================================================================
--- incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
(original)
+++ incubator/bval/trunk/bval-jsr303/src/main/java/org/apache/bval/jsr303/xml/ValidationParser.java
Tue Mar 30 11:06:14 2010
@@ -39,6 +39,8 @@ import javax.xml.bind.Unmarshaller;
 import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
+
+import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -74,8 +76,9 @@ public class ValidationParser {
     }
 
     private ValidationConfigType parseXmlConfig() {
+        InputStream inputStream = null;
         try {
-            InputStream inputStream = getInputStream(validationXmlFile);
+            inputStream = getInputStream(validationXmlFile);
             if (inputStream == null) {
                 if (log.isDebugEnabled()) log.debug("No " + validationXmlFile +
                       " found. Using annotation based configuration only.");
@@ -96,6 +99,8 @@ public class ValidationParser {
             throw new ValidationException("Unable to parse " + validationXmlFile, e);
         } catch (IOException e) {
             throw new ValidationException("Unable to parse " + validationXmlFile, e);
+        } finally {
+            closeQuietly(inputStream);
         }
     }
 
@@ -208,7 +213,7 @@ public class ValidationParser {
                 log.debug(
                       "Trying to open input stream for " + mappingFileName.getValue());
             }
-            InputStream in;
+            InputStream in = null;
             try {
                 in = getInputStream(mappingFileName.getValue());
                 if (in == null) {
@@ -219,8 +224,20 @@ public class ValidationParser {
             } catch (IOException e) {
                 throw new ValidationException("Unable to open input stream for mapping file
" +
                       mappingFileName.getValue(), e);
+            } finally {
+                closeQuietly(in);
             }
             target.addMapping(in);
         }
     }
+
+    private static void closeQuietly(Closeable closeable) {
+        if (closeable != null) {
+            try {
+                closeable.close();
+            } catch (IOException e) {
+                // do nothing
+            }
+        }
+    }
 }



Mime
View raw message