o Updated to 'plexus-utils-3.0.23'.
o Updated to stop suppressing exceptions incorrectly when closing resources.
Most of the time the 'IOUtils.closeQuietly' methods of 'commons-io' and
the 'IOUtil.close' method of 'plexus-utils' are used incorrectly. They
are meant to be used in 'finally' blocks to not suppress an exception
already thrown in the 'try' block. The documentation of the
'IOUtils.closeQuietly' methods explicitly contains usage examples.
As soon as 'commons-io' or 'plexus-utils' is targetted at Java 1.7, those
methods should get deprecated and people should be told to use the
try-with-resources statement instead.
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1742353 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index afdb42b..7aacae3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -230,7 +230,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
- <version>3.0.20</version>
+ <version>3.0.23</version>
</dependency>
<!-- test -->
diff --git a/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java b/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java
index dc3a1f0..f13d8d7 100644
--- a/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java
@@ -55,7 +55,6 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
@@ -738,14 +737,12 @@
clirrNewClasses = new LinkedList<String>();
clirrNewMethods = new LinkedHashMap<String, List<String>>();
- BufferedReader input = null;
- Reader reader = null;
+ BufferedReader reader = null;
try
{
- reader = ReaderFactory.newReader( clirrTextOutputFile, "UTF-8" );
- input = new BufferedReader( reader );
- String line;
- while ( ( line = input.readLine() ) != null )
+ reader = new BufferedReader( ReaderFactory.newReader( clirrTextOutputFile, "UTF-8" ) );
+
+ for ( String line = reader.readLine(); line != null; line = reader.readLine() )
{
String[] split = StringUtils.split( line, ":" );
if ( split.length != 4 )
@@ -818,11 +815,13 @@
}
// CHECKSTYLE_ON: MagicNumber
}
+
+ reader.close();
+ reader = null;
}
finally
{
IOUtils.closeQuietly( reader );
- IOUtils.closeQuietly( input );
}
if ( clirrNewClasses.isEmpty() && clirrNewMethods.isEmpty() )
{
@@ -986,9 +985,8 @@
{
reader = new BufferedReader( new StringReader( originalContent ) );
- String line;
int lineNumber = 0;
- while ( ( line = reader.readLine() ) != null )
+ for ( String line = reader.readLine(); line != null; line = reader.readLine() )
{
lineNumber++;
final String indent = autodetectIndentation( line );
@@ -1047,6 +1045,9 @@
stringWriter.write( line );
stringWriter.write( EOL );
}
+
+ reader.close();
+ reader = null;
}
finally
{
@@ -2941,6 +2942,8 @@
{
writer = WriterFactory.newWriter( javaFile, encoding );
writer.write( StringUtils.unifyLineSeparators( content ) );
+ writer.close();
+ writer = null;
}
finally
{
@@ -2970,7 +2973,8 @@
{
Properties properties = new Properties();
properties.load( resourceAsStream );
-
+ resourceAsStream.close();
+ resourceAsStream = null;
if ( StringUtils.isNotEmpty( properties.getProperty( "version" ) ) )
{
clirrVersion = properties.getProperty( "version" );
diff --git a/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java b/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java
index ecb30d9..ceb5f69 100644
--- a/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java
@@ -5226,14 +5226,17 @@
throws IOException
{
final String fixData;
- final InputStream in = this.getClass().getResourceAsStream( "frame-injection-fix.txt" );
- if ( in == null )
- {
- throw new FileNotFoundException( "Missing resource 'frame-injection-fix.txt' in classpath." );
- }
+ InputStream in = null;
try
{
+ in = this.getClass().getResourceAsStream( "frame-injection-fix.txt" );
+ if ( in == null )
+ {
+ throw new FileNotFoundException( "Missing resource 'frame-injection-fix.txt' in classpath." );
+ }
fixData = StringUtils.unifyLineSeparators( IOUtil.toString( in, "US-ASCII" ) ).trim();
+ in.close();
+ in = null;
}
finally
{
@@ -5412,7 +5415,8 @@
{
Properties properties = new Properties();
properties.load( resourceAsStream );
-
+ resourceAsStream.close();
+ resourceAsStream = null;
if ( StringUtils.isNotEmpty( properties.getProperty( "version" ) ) )
{
javadocPluginVersion = properties.getProperty( "version" );
@@ -5699,12 +5703,17 @@
link.setLocation( javaApiPackageListFile.getParentFile().getAbsolutePath() );
link.setUrl( javaApiLink );
- InputStream in = this.getClass().getResourceAsStream( "java-api-package-list-" + apiVersion );
+ InputStream in = null;
OutputStream out = null;
try
{
+ in = this.getClass().getResourceAsStream( "java-api-package-list-" + apiVersion );
out = new FileOutputStream( javaApiPackageListFile );
IOUtil.copy( in, out );
+ out.close();
+ out = null;
+ in.close();
+ in = null;
}
catch ( IOException ioe )
{
diff --git a/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java b/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java
index a4c36f3..2398fed 100644
--- a/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java
+++ b/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java
@@ -780,8 +780,10 @@
try
{
osw = new OutputStreamWriter( ost, charsetName );
+ osw.close();
+ osw = null;
}
- catch ( UnsupportedEncodingException exc )
+ catch ( IOException exc )
{
return false;
}
@@ -895,29 +897,35 @@
throw new IOException( "The url could not be null." );
}
- InputStream is = url.openStream();
- if ( is == null )
- {
- throw new IOException( "The resource " + url + " doesn't exists." );
- }
-
if ( !file.getParentFile().exists() )
{
file.getParentFile().mkdirs();
}
- OutputStream os = null;
+ InputStream in = null;
+ OutputStream out = null;
try
{
- os = new FileOutputStream( file );
+ in = url.openStream();
- IOUtil.copy( is, os );
+ if ( in == null )
+ {
+ throw new IOException( "The resource " + url + " doesn't exists." );
+ }
+
+ out = new FileOutputStream( file );
+
+ IOUtil.copy( in, out );
+
+ out.close();
+ out = null;
+ in.close();
+ in = null;
}
finally
{
- IOUtil.close( is );
-
- IOUtil.close( os );
+ IOUtil.close( in );
+ IOUtil.close( out );
}
}
@@ -1150,8 +1158,9 @@
try
{
jarStream = new JarInputStream( new FileInputStream( jarFile ) );
- JarEntry jarEntry = jarStream.getNextJarEntry();
- while ( jarEntry != null )
+
+ for ( JarEntry jarEntry = jarStream.getNextJarEntry(); jarEntry != null;
+ jarEntry = jarStream.getNextJarEntry() )
{
if ( jarEntry.getName().toLowerCase( Locale.ENGLISH ).endsWith( ".class" ) )
{
@@ -1161,8 +1170,10 @@
}
jarStream.closeEntry();
- jarEntry = jarStream.getNextJarEntry();
}
+
+ jarStream.close();
+ jarStream = null;
}
finally
{
@@ -1731,8 +1742,7 @@
if ( validateContent )
{
- String line;
- while ( ( line = reader.readLine() ) != null )
+ for ( String line = reader.readLine(); line != null; line = reader.readLine() )
{
if ( !isValidPackageName( line ) )
{
@@ -1741,6 +1751,9 @@
}
}
+ reader.close();
+ reader = null;
+
return true;
}
finally
diff --git a/src/main/java/org/apache/maven/plugin/javadoc/resolver/ResourceResolver.java b/src/main/java/org/apache/maven/plugin/javadoc/resolver/ResourceResolver.java
index 6cd7f7f..89d13b4 100644
--- a/src/main/java/org/apache/maven/plugin/javadoc/resolver/ResourceResolver.java
+++ b/src/main/java/org/apache/maven/plugin/javadoc/resolver/ResourceResolver.java
@@ -196,7 +196,8 @@
{
stream = new FileInputStream( optionsFile );
JavadocOptions options = new JavadocOptionsXpp3Reader().read( stream );
-
+ stream.close();
+ stream = null;
bundles.add( new JavadocBundle( options, new File( project.getBasedir(),
options.getJavadocResourcesDirectory() ) ) );
}
diff --git a/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java b/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java
index 1cee10d..a27e84f 100644
--- a/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java
+++ b/src/test/java/org/apache/maven/plugin/javadoc/FixJavadocMojoTest.java
@@ -721,7 +721,10 @@
try
{
fileReader = ReaderFactory.newReader( file, "UTF-8" );
- return IOUtil.toString( fileReader );
+ final String content = IOUtil.toString( fileReader );
+ fileReader.close();
+ fileReader = null;
+ return content;
}
finally
{
diff --git a/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java b/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java
index 035c15a..cd899fc 100644
--- a/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java
+++ b/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java
@@ -343,6 +343,8 @@
{
reader = ReaderFactory.newPlatformReader( options );
contentOptions = IOUtil.toString( reader );
+ reader.close();
+ reader = null;
}
finally
{