You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sc...@apache.org on 2016/06/23 00:37:53 UTC

svn commit: r1749802 - in /maven/shared/trunk/maven-shared-utils: ./ src/main/java/org/apache/maven/shared/utils/ src/main/java/org/apache/maven/shared/utils/io/ src/main/java/org/apache/maven/shared/utils/xml/ src/test/java/org/apache/maven/shared/uti...

Author: schulte
Date: Thu Jun 23 00:37:53 2016
New Revision: 1749802

URL: http://svn.apache.org/viewvc?rev=1749802&view=rev
Log:
[MSHARED-564] Exceptions thrown on closing resources should not be suppressed silently.


Modified:
    maven/shared/trunk/maven-shared-utils/pom.xml
    maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/Expand.java
    maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/PropertyUtils.java
    maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
    maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/IOUtil.java
    maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java
    maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java
    maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
    maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java

Modified: maven/shared/trunk/maven-shared-utils/pom.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/pom.xml?rev=1749802&r1=1749801&r2=1749802&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/pom.xml (original)
+++ maven/shared/trunk/maven-shared-utils/pom.xml Thu Jun 23 00:37:53 2016
@@ -28,7 +28,7 @@
   </parent>
 
   <artifactId>maven-shared-utils</artifactId>
-  <version>3.0.2-SNAPSHOT</version>
+  <version>3.1.0-SNAPSHOT</version>
 
   <name>Apache Maven Shared Utils</name>
   <description>Shared utils without any further dependencies</description>

Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/Expand.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/Expand.java?rev=1749802&r1=1749801&r2=1749802&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/Expand.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/Expand.java Thu Jun 23 00:37:53 2016
@@ -24,10 +24,13 @@ import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.Date;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
+
 import org.apache.maven.shared.utils.io.FileUtils;
+import org.apache.maven.shared.utils.io.IOUtil;
 
 /**
  * Expand will unpack the given zip archive.
@@ -123,31 +126,25 @@ class Expand
             destDir = new File( System.getProperty( "user.dir" ) );
         }
 
-        FileInputStream fileInputStream = new FileInputStream( srcFile );
+        ZipInputStream in = null;
         try
         {
-            ZipInputStream zipInputStream = new ZipInputStream( fileInputStream );
-
-            ZipEntry zipEntry;
+            in = new ZipInputStream( new FileInputStream( srcFile ) );
 
-            while ( ( zipEntry = zipInputStream.getNextEntry() ) != null )
+            for ( ZipEntry zipEntry = in.getNextEntry(); zipEntry != null; zipEntry = in.getNextEntry() )
             {
                 String zipEntryName = zipEntry.getName();
                 Date zipEntryDate = new Date( zipEntry.getTime() );
 
-                extractFile( source, destDir, zipInputStream, zipEntryName, zipEntryDate, zipEntry.isDirectory() );
+                extractFile( source, destDir, in, zipEntryName, zipEntryDate, zipEntry.isDirectory() );
             }
+
+            in.close();
+            in = null;
         }
         finally
         {
-            try
-            {
-                fileInputStream.close();
-            }
-            catch ( IOException ioe )
-            {
-                // no worries, all is ok ...
-            }
+            IOUtil.close( in );
         }
     }
 
@@ -191,25 +188,23 @@ class Expand
             else
             {
                 byte[] buffer = new byte[BUFFER_SIZE];
-                FileOutputStream fileOutputStream = new FileOutputStream( targetFile );
+                OutputStream out = null;
                 try
                 {
+                    out = new FileOutputStream( targetFile );
+
                     int len;
-                    while ( ( len = compressedInputStream.read( buffer ) ) > 0 )
+                    while ( ( len = compressedInputStream.read( buffer ) ) >= 0 )
                     {
-                        fileOutputStream.write( buffer, 0, len );
+                        out.write( buffer, 0, len );
                     }
+
+                    out.close();
+                    out = null;
                 }
                 finally
                 {
-                    try
-                    {
-                        fileOutputStream.close();
-                    }
-                    catch ( IOException ioe )
-                    {
-                        // no worries, all is ok ...
-                    }
+                    IOUtil.close( out );
                 }
                 targetFile.setLastModified( entryDate.getTime() );
             }

Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/PropertyUtils.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/PropertyUtils.java?rev=1749802&r1=1749801&r2=1749802&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/PropertyUtils.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/PropertyUtils.java Thu Jun 23 00:37:53 2016
@@ -23,6 +23,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.Properties;
 
 import javax.annotation.Nonnull;
@@ -31,7 +32,7 @@ import javax.annotation.Nullable;
 import org.apache.maven.shared.utils.io.IOUtil;
 
 /**
- * 
+ *
  */
 public class PropertyUtils
 {
@@ -46,9 +47,15 @@ public class PropertyUtils
 
     /**
      * @param url The URL which should be used to load the properties.
+     *
      * @return The loaded properties.
+     *
+     * @deprecated As of 3.1.0, please use method {@link #loadOptionalProperties(java.net.URL)}. This method should not
+     * be used as it suppresses exceptions when loading properties fails and returns {@code null} instead of an empty
+     * {@code Properties} instance when the given {@code URL} is {@code null}.
      */
-    public static java.util.Properties loadProperties( @Nonnull java.net.URL url )
+    @Deprecated
+    public static java.util.Properties loadProperties( @Nonnull URL url )
     {
         try
         {
@@ -63,8 +70,14 @@ public class PropertyUtils
 
     /**
      * @param file The file from which the properties will be loaded.
+     *
      * @return The loaded properties.
+     *
+     * @deprecated As of 3.1.0, please use method {@link #loadOptionalProperties(java.io.File)}. This method should not
+     * be used as it suppresses exceptions when loading properties fails and returns {@code null} instead of an empty
+     * {@code Properties} instance when the given {@code URL} is {@code null}.
      */
+    @Deprecated
     public static Properties loadProperties( @Nonnull File file )
     {
         try
@@ -80,8 +93,13 @@ public class PropertyUtils
 
     /**
      * @param is {@link InputStream}
+     *
      * @return The loaded properties.
+     *
+     * @deprecated As of 3.1.0, please use method {@link #loadOptionalProperties(java.io.InputStream)}. This method
+     * should not be used as it suppresses exceptions when loading properties fails.
      */
+    @Deprecated
     public static Properties loadProperties( @Nullable InputStream is )
     {
         try
@@ -112,4 +130,109 @@ public class PropertyUtils
         return null;
     }
 
+    /**
+     * Loads {@code Properties} from a given {@code URL}.
+     *
+     * @param url The {@code URL} of the properties resource to load or {@code null}.
+     *
+     * @return The loaded properties or an empty {@code Properties} instance if {@code url} is {@code null}.
+     *
+     * @throws IOException if loading properties fails.
+     *
+     * @since 3.1.0
+     */
+    @Nonnull public static Properties loadOptionalProperties( final @Nullable URL url )
+        throws IOException
+    {
+        InputStream in = null;
+        try
+        {
+            final Properties properties = new Properties();
+
+            if ( url != null )
+            {
+                in = url.openStream();
+                properties.load( in );
+                in.close();
+                in = null;
+            }
+
+            return properties;
+        }
+        finally
+        {
+            IOUtil.close( in );
+        }
+    }
+
+    /**
+     * Loads {@code Properties} from a given {@code File}.
+     *
+     * @param file The {@code File} of the properties resource to load or {@code null}.
+     *
+     * @return The loaded properties or an empty {@code Properties} instance if {@code file} is {@code null}.
+     *
+     * @throws IOException if loading properties fails.
+     *
+     * @since 3.1.0
+     */
+    @Nonnull public static Properties loadOptionalProperties( final @Nullable File file )
+        throws IOException
+    {
+        InputStream in = null;
+        try
+        {
+            final Properties properties = new Properties();
+
+            if ( file != null )
+            {
+                in = new FileInputStream( file );
+                properties.load( in );
+                in.close();
+                in = null;
+            }
+
+            return properties;
+        }
+        finally
+        {
+            IOUtil.close( in );
+        }
+    }
+
+    /**
+     * Loads {@code Properties} from a given {@code InputStream}.
+     *
+     * @param inputStream The {@code InputStream} of the properties resource to load or {@code null}.
+     *
+     * @return The loaded properties or an empty {@code Properties} instance if {@code inputStream} is {@code null}.
+     *
+     * @throws IOException if loading properties fails.
+     *
+     * @since 3.1.0
+     */
+    @Nonnull public static Properties loadOptionalProperties( final @Nullable InputStream inputStream )
+        throws IOException
+    {
+        InputStream in = null;
+        try
+        {
+            final Properties properties = new Properties();
+
+            if ( inputStream != null )
+            {
+                in = inputStream;
+                properties.load( in );
+                in.close();
+                in = null;
+            }
+
+            return properties;
+        }
+        finally
+        {
+            IOUtil.close( in );
+        }
+    }
+
 }

Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java?rev=1749802&r1=1749801&r2=1749802&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/FileUtils.java Thu Jun 23 00:37:53 2016
@@ -25,6 +25,7 @@ import org.apache.maven.shared.utils.Str
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.annotation.WillClose;
+
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
@@ -290,10 +291,12 @@ public class FileUtils
             }
             int count;
             char[] b = new char[512];
-            while ( ( count = reader.read( b ) ) > 0 )  // blocking read
+            while ( ( count = reader.read( b ) ) >= 0 )  // blocking read
             {
                 buf.append( b, 0, count );
             }
+            reader.close();
+            reader = null;
         }
         finally
         {
@@ -312,9 +315,9 @@ public class FileUtils
     @Nonnull public static String[] fileReadArray( @Nonnull File file )
         throws IOException
     {
-        List<String> files = loadFile( file );
+        List<String> lines = loadFile( file );
 
-        return files.toArray( new String[files.size()] );
+        return lines.toArray( new String[lines.size()] );
     }
 
     /**
@@ -354,6 +357,8 @@ public class FileUtils
             {
                 out.write( data.getBytes() );
             }
+            out.close();
+            out = null;
         }
         finally
         {
@@ -404,16 +409,17 @@ public class FileUtils
         Writer writer = null;
         try
         {
-            OutputStream out = new FileOutputStream( file );
             if ( encoding != null )
             {
-                writer = new OutputStreamWriter( out, encoding );
+                writer = new OutputStreamWriter( new FileOutputStream( file ), encoding );
             }
             else
             {
-                writer = new OutputStreamWriter( out );
+                writer = new OutputStreamWriter( new FileOutputStream( file ) );
             }
             writer.write( data );
+            writer.close();
+            writer = null;
         }
         finally
         {
@@ -449,14 +455,13 @@ public class FileUtils
         Writer writer = null;
         try
         {
-            OutputStream out = new FileOutputStream( file );
             if ( encoding != null )
             {
-                writer = new OutputStreamWriter( out, encoding );
+                writer = new OutputStreamWriter( new FileOutputStream( file ), encoding );
             }
             else
             {
-                writer = new OutputStreamWriter( out );
+                writer = new OutputStreamWriter( new FileOutputStream( file ) );
             }
 
             for ( int i = 0; data != null && i < data.length; i++ )
@@ -467,6 +472,9 @@ public class FileUtils
                     writer.write( "\n" );
                 }
             }
+
+            writer.close();
+            writer = null;
         }
         finally
         {
@@ -639,18 +647,23 @@ public class FileUtils
 
         InputStream input1 = null;
         InputStream input2 = null;
+        boolean equals = false;
         try
         {
             input1 = new FileInputStream( file1 );
             input2 = new FileInputStream( file2 );
-            return IOUtil.contentEquals( input1, input2 );
-
+            equals = IOUtil.contentEquals( input1, input2 );
+            input1.close();
+            input1 = null;
+            input2.close();
+            input2 = null;
         }
         finally
         {
             IOUtil.close( input1 );
             IOUtil.close( input2 );
         }
+        return equals;
     }
 
     /**
@@ -871,6 +884,14 @@ public class FileUtils
                 count = size - pos > FILE_COPY_BUFFER_SIZE ? FILE_COPY_BUFFER_SIZE : size - pos;
                 pos += output.transferFrom( input, pos, count );
             }
+            output.close();
+            output = null;
+            fos.close();
+            fos = null;
+            input.close();
+            input = null;
+            fis.close();
+            fis = null;
         }
         finally
         {
@@ -947,7 +968,8 @@ public class FileUtils
                                           @Nonnull final File destination )
         throws IOException
     {
-        FileOutputStream output = null;
+        InputStream in = source;
+        OutputStream out = null;
         try
         {
             //does destination directory exist ?
@@ -964,13 +986,17 @@ public class FileUtils
                 throw new IOException( message );
             }
 
-            output = new FileOutputStream( destination );
-            IOUtil.copy( source, output );
+            out = new FileOutputStream( destination );
+            IOUtil.copy( in, out );
+            out.close();
+            out = null;
+            in.close();
+            in = null;
         }
         finally
         {
-            IOUtil.close( source );
-            IOUtil.close( output );
+            IOUtil.close( out );
+            IOUtil.close( in );
         }
     }
 
@@ -1908,22 +1934,20 @@ public class FileUtils
                 }
                 else
                 {
-                    FileInputStream instream = new FileInputStream( from );
-
-                    FileOutputStream outstream = new FileOutputStream( to );
-
-                    fileReader = new BufferedReader( new InputStreamReader( instream, encoding ) );
-
-                    fileWriter = new OutputStreamWriter( outstream, encoding );
+                    fileReader = new BufferedReader( new InputStreamReader( new FileInputStream( from ), encoding ) );
+                    fileWriter = new OutputStreamWriter( new FileOutputStream( to ), encoding );
                 }
 
-                Reader reader = fileReader;
                 for ( FilterWrapper wrapper : wrappers )
                 {
-                    reader = wrapper.getReader( reader );
+                    fileReader = wrapper.getReader( fileReader );
                 }
 
-                IOUtil.copy( reader, fileWriter );
+                IOUtil.copy( fileReader, fileWriter );
+                fileWriter.close();
+                fileWriter = null;
+                fileReader.close();
+                fileReader = null;
             }
             finally
             {
@@ -1954,14 +1978,12 @@ public class FileUtils
 
         if ( file.exists() )
         {
-            FileReader fileReader = new FileReader( file );
+            BufferedReader reader = null;
             try
             {
-                BufferedReader reader = new BufferedReader( fileReader );
+                reader = new BufferedReader( new FileReader( file ) );
 
-                String line = reader.readLine();
-
-                while ( line != null )
+                for ( String line = reader.readLine(); line != null; line = reader.readLine() )
                 {
                     line = line.trim();
 
@@ -1969,14 +1991,14 @@ public class FileUtils
                     {
                         lines.add( line );
                     }
-                    line = reader.readLine();
                 }
 
                 reader.close();
+                reader = null;
             }
             finally
             {
-                fileReader.close();
+                IOUtil.close( reader );
             }
         }
 

Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/IOUtil.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/IOUtil.java?rev=1749802&r1=1749801&r2=1749802&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/IOUtil.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/io/IOUtil.java Thu Jun 23 00:37:53 2016
@@ -84,7 +84,7 @@ import java.nio.channels.Channel;
  * @author <a href="mailto:peter@apache.org">Peter Donald</a>
  * @author <a href="mailto:jefft@apache.org">Jeff Turner</a>
  * @version CVS $Revision$ $Date$
- * 
+ *
  */
 public final class IOUtil
 /*

Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java?rev=1749802&r1=1749801&r2=1749802&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/xml/Xpp3DomBuilder.java Thu Jun 23 00:37:53 2016
@@ -102,8 +102,14 @@ public class Xpp3DomBuilder
         try
         {
             DocHandler docHandler = parseSax( new InputSource( reader ), trim );
+            reader.close();
+            reader = null;
             return docHandler.result;
         }
+        catch ( final IOException e )
+        {
+            throw new XmlPullParserException( e );
+        }
         finally
         {
             IOUtil.close( reader );

Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java?rev=1749802&r1=1749801&r2=1749802&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/PropertyUtilsTest.java Thu Jun 23 00:37:53 2016
@@ -19,14 +19,11 @@ package org.apache.maven.shared.utils;
  * under the License.
  */
 
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -34,11 +31,18 @@ import java.lang.annotation.Target;
 import java.net.URL;
 import java.util.Properties;
 
-import static org.hamcrest.CoreMatchers.*;
+import org.apache.maven.shared.utils.io.IOUtil;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
 import static org.junit.Assert.assertThat;
 
 public class PropertyUtilsTest
 {
+
     @Retention( RetentionPolicy.RUNTIME )
     @Target( ElementType.METHOD )
     @interface NeedsTemporaryFolder
@@ -48,8 +52,8 @@ public class PropertyUtilsTest
     @Rule
     public TemporaryFolder tempFolder = new TemporaryFolder();
 
-
     @Test
+    @SuppressWarnings( "deprecation" )
     // @ReproducesPlexusBug( "Should return null on error like url and file do" )
     public void loadNullInputStream()
         throws Exception
@@ -58,6 +62,14 @@ public class PropertyUtilsTest
     }
 
     @Test
+    public void loadOptionalNullInputStream()
+        throws Exception
+    {
+        assertThat( PropertyUtils.loadOptionalProperties( (InputStream) null ), is( new Properties() ) );
+    }
+
+    @Test
+    @SuppressWarnings( "deprecation" )
     public void loadNullURL()
         throws Exception
     {
@@ -65,6 +77,14 @@ public class PropertyUtilsTest
     }
 
     @Test
+    public void loadOptionalNullURL()
+        throws Exception
+    {
+        assertThat( PropertyUtils.loadOptionalProperties( (URL) null ), is( new Properties() ) );
+    }
+
+    @Test
+    @SuppressWarnings( "deprecation" )
     public void loadNullFile()
         throws Exception
     {
@@ -72,61 +92,113 @@ public class PropertyUtilsTest
     }
 
     @Test
+    public void loadOptionalNullFile()
+        throws Exception
+    {
+        assertThat( PropertyUtils.loadOptionalProperties( (File) null ), is( new Properties() ) );
+    }
+
+    @Test
+    @SuppressWarnings( "deprecation" )
     public void loadEmptyInputStream()
         throws Exception
     {
-        assertThat( PropertyUtils.loadProperties( new ByteArrayInputStream( new byte[0] ) ), is( new Properties() ) );
+        assertThat( PropertyUtils.loadProperties( new ByteArrayInputStream( new byte[ 0 ] ) ),
+                    is( new Properties() ) );
+
+        assertThat( PropertyUtils.loadOptionalProperties( new ByteArrayInputStream( new byte[ 0 ] ) ),
+                    is( new Properties() ) );
+
     }
 
     @Test
     @NeedsTemporaryFolder
+    @SuppressWarnings( "deprecation" )
     public void loadEmptyFile()
         throws Exception
     {
         assertThat( PropertyUtils.loadProperties( tempFolder.newFile( "empty" ) ), is( new Properties() ) );
+        assertThat( PropertyUtils.loadOptionalProperties( tempFolder.newFile( "optional" ) ), is( new Properties() ) );
     }
 
     @Test
     @NeedsTemporaryFolder
+    @SuppressWarnings( "deprecation" )
     public void loadEmptyURL()
         throws Exception
     {
-        assertThat( PropertyUtils.loadProperties( tempFolder.newFile( "empty" ).toURI().toURL() ), is( new Properties() ) );
+        assertThat( PropertyUtils.loadProperties( tempFolder.newFile( "empty" ).toURI().toURL() ),
+                    is( new Properties() ) );
+
+        assertThat( PropertyUtils.loadOptionalProperties( tempFolder.newFile( "optional" ).toURI().toURL() ),
+                    is( new Properties() ) );
+
     }
 
     @Test
+    @SuppressWarnings( "deprecation" )
     public void loadValidInputStream()
         throws Exception
     {
         Properties value = new Properties();
         value.setProperty( "a", "b" );
+
         assertThat( PropertyUtils.loadProperties( new ByteArrayInputStream( "a=b".getBytes( "ISO-8859-1" ) ) ),
                     is( value ) );
+
+        assertThat( PropertyUtils.loadOptionalProperties( new ByteArrayInputStream( "a=b".getBytes( "ISO-8859-1" ) ) ),
+                    is( value ) );
+
     }
 
     @Test
     @NeedsTemporaryFolder
+    @SuppressWarnings( "deprecation" )
     public void loadValidFile()
         throws Exception
     {
-        File valid = tempFolder.newFile( "valid" );
-        Properties value = new Properties();
-        value.setProperty( "a", "b" );
-        value.store( new FileOutputStream( valid ), "a test" );
-        assertThat( PropertyUtils.loadProperties( valid ), is( value ) );
+        OutputStream out = null;
+        try
+        {
+            File valid = tempFolder.newFile( "valid" );
+            Properties value = new Properties();
+            value.setProperty( "a", "b" );
+            out = new FileOutputStream( valid );
+            value.store( out, "a test" );
+            out.close();
+            out = null;
+            assertThat( PropertyUtils.loadProperties( valid ), is( value ) );
+            assertThat( PropertyUtils.loadOptionalProperties( valid ), is( value ) );
+        }
+        finally
+        {
+            IOUtil.close( out );
+        }
     }
 
     @Test
     @NeedsTemporaryFolder
+    @SuppressWarnings( "deprecation" )
     public void loadValidURL()
         throws Exception
     {
-        File valid = tempFolder.newFile( "valid" );
-        Properties value = new Properties();
-        value.setProperty( "a", "b" );
-        value.store( new FileOutputStream( valid ), "a test" );
-        assertThat( PropertyUtils.loadProperties( valid.toURI().toURL() ), is( value ) );
+        OutputStream out = null;
+        try
+        {
+            File valid = tempFolder.newFile( "valid" );
+            Properties value = new Properties();
+            value.setProperty( "a", "b" );
+            out = new FileOutputStream( valid );
+            value.store( out, "a test" );
+            out.close();
+            out = null;
+            assertThat( PropertyUtils.loadProperties( valid.toURI().toURL() ), is( value ) );
+            assertThat( PropertyUtils.loadOptionalProperties( valid.toURI().toURL() ), is( value ) );
+        }
+        finally
+        {
+            IOUtil.close( out );
+        }
     }
 
-
 }

Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java?rev=1749802&r1=1749801&r2=1749802&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/io/FileUtilsTest.java Thu Jun 23 00:37:53 2016
@@ -122,14 +122,18 @@ public class FileUtilsTest
         {
             throw new IOException( "Cannot create file " + file + " as the parent directory does not exist" );
         }
-        BufferedOutputStream output = new BufferedOutputStream( new FileOutputStream( file ) );
+
+        OutputStream out = null;
         try
         {
-            FileTestHelper.generateTestData( output, size );
+            out = new BufferedOutputStream( new FileOutputStream( file ) );
+            FileTestHelper.generateTestData( out, size );
+            out.close();
+            out = null;
         }
         finally
         {
-            IOUtil.close( output );
+            IOUtil.close( out );
         }
     }
 

Modified: maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java?rev=1749802&r1=1749801&r2=1749802&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java (original)
+++ maven/shared/trunk/maven-shared-utils/src/test/java/org/apache/maven/shared/utils/testhelpers/FileTestHelper.java Thu Jun 23 00:37:53 2016
@@ -70,17 +70,21 @@ public final class FileTestHelper
         {
             throw new IOException( "Cannot create file " + file + " as the parent directory does not exist" );
         }
-        PrintWriter output = new PrintWriter( new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ) );
+
+        PrintWriter out = null;
         try
         {
+            out = new PrintWriter( new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ) );
             for ( String aData : data )
             {
-                output.println( aData );
+                out.println( aData );
             }
+            out.close();
+            out = null;
         }
         finally
         {
-            IOUtil.close( output );
+            IOUtil.close( out );
         }
     }