michael-o commented on a change in pull request #589:
URL: https://github.com/apache/maven/pull/589#discussion_r817615789
##########
File path: maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
##########
@@ -553,9 +553,8 @@ else if ( cliRequest.commandLine.hasOption(
CLIManager.BATCH_MODE )
logFile = resolveFile( logFile, cliRequest.workingDirectory );
// redirect stdout and stderr to file
- try
+ try ( PrintStream ps = new PrintStream( new FileOutputStream(
logFile ) ) )
Review comment:
I I think you are right. This could leave to side effects. Folks, other
opinions?
##########
File path:
maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManager.java
##########
@@ -350,60 +350,29 @@ private Properties read( File touchfile )
synchronized ( touchfile.getAbsolutePath().intern() )
{
- FileInputStream in = null;
- FileLock lock = null;
-
try
{
Properties props = new Properties();
- in = new FileInputStream( touchfile );
- lock = in.getChannel().lock( 0, Long.MAX_VALUE, true );
-
- getLogger().debug( "Reading resolution-state from: " +
touchfile );
- props.load( in );
-
- lock.release();
- lock = null;
+ try ( FileInputStream in = new FileInputStream( touchfile ) )
+ {
+ try ( FileLock lock = in.getChannel().lock( 0,
Long.MAX_VALUE, true ) )
+ {
+ getLogger().debug( "Reading resolution-state from: " +
touchfile );
+ props.load( in );
- in.close();
- in = null;
+ lock.release();
+ return props;
+ }
+ }
- return props;
}
catch ( IOException e )
{
getLogger().debug( "Failed to read resolution tracking file "
+ touchfile, e );
return null;
}
- finally
- {
- if ( lock != null )
- {
- try
- {
- lock.release();
- }
- catch ( IOException e )
- {
- getLogger().debug( "Error releasing shared lock for
resolution tracking file: " + touchfile,
- e );
- }
- }
-
- if ( in != null )
- {
- try
- {
- in.close();
- }
- catch ( IOException e )
- {
- getLogger().debug( "Error closing FileChannel for
resolution tracking file: " + touchfile, e );
- }
- }
- }
}
}
Review comment:
I think we don't case about `maven-compat` anymore so I wouldn't really
touch unless necessary. @gnodet @cstamas WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]