Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5DDA2200BF7 for ; Mon, 9 Jan 2017 23:41:36 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 5C628160B3E; Mon, 9 Jan 2017 22:41:36 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7E3CE160B2F for ; Mon, 9 Jan 2017 23:41:35 +0100 (CET) Received: (qmail 58036 invoked by uid 500); 9 Jan 2017 22:41:34 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 58025 invoked by uid 99); 9 Jan 2017 22:41:34 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Jan 2017 22:41:34 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8E97BDFA22; Mon, 9 Jan 2017 22:41:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: schulte@apache.org To: commits@maven.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: maven git commit: [MNG-5629] ClosedChannelException from DefaultUpdateCheckManager.read Date: Mon, 9 Jan 2017 22:41:34 +0000 (UTC) archived-at: Mon, 09 Jan 2017 22:41:36 -0000 Repository: maven Updated Branches: refs/heads/MNG-5629 [created] ca1179ce6 [MNG-5629] ClosedChannelException from DefaultUpdateCheckManager.read o Updated to stop producing 'ClosedChannelException's when reading tracking files. o Updated to use 'Long.MAX_VALUE' as the size of any locked regions to prevent writing beyond locked regions. o Updated to support shrinking of tracking files. Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/ca1179ce Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/ca1179ce Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/ca1179ce Branch: refs/heads/MNG-5629 Commit: ca1179ce6ab6ed78fe755e2b97f7e0c01ea91361 Parents: e51fc87 Author: Christian Schulte Authored: Fri Dec 11 21:42:09 2015 +0100 Committer: Christian Schulte Committed: Mon Jan 9 16:07:28 2017 +0100 ---------------------------------------------------------------------- .../legacy/DefaultUpdateCheckManager.java | 61 ++++++++------------ 1 file changed, 24 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/ca1179ce/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManager.java ---------------------------------------------------------------------- diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManager.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManager.java index dfc463b..4839d68 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManager.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/DefaultUpdateCheckManager.java @@ -28,15 +28,12 @@ import org.apache.maven.repository.Proxy; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.util.IOUtil; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.RandomAccessFile; -import java.nio.ByteBuffer; +import java.nio.channels.Channels; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.util.Date; @@ -242,18 +239,12 @@ public class DefaultUpdateCheckManager Properties props = new Properties(); channel = new RandomAccessFile( touchfile, "rw" ).getChannel(); - lock = channel.lock( 0, channel.size(), false ); + lock = channel.lock(); if ( touchfile.canRead() ) { getLogger().debug( "Reading resolution-state from: " + touchfile ); - ByteBuffer buffer = ByteBuffer.allocate( (int) channel.size() ); - - channel.read( buffer ); - buffer.flip(); - - ByteArrayInputStream stream = new ByteArrayInputStream( buffer.array() ); - props.load( stream ); + props.load( Channels.newInputStream( channel ) ); } props.setProperty( key, Long.toString( System.currentTimeMillis() ) ); @@ -267,18 +258,15 @@ public class DefaultUpdateCheckManager props.remove( key + ERROR_KEY_SUFFIX ); } - ByteArrayOutputStream stream = new ByteArrayOutputStream(); - getLogger().debug( "Writing resolution-state to: " + touchfile ); - props.store( stream, "Last modified on: " + new Date() ); + channel.truncate( 0 ); + props.store( Channels.newOutputStream( channel ), "Last modified on: " + new Date() ); - byte[] data = stream.toByteArray(); - ByteBuffer buffer = ByteBuffer.allocate( data.length ); - buffer.put( data ); - buffer.flip(); + lock.release(); + lock = null; - channel.position( 0 ); - channel.write( buffer ); + channel.close(); + channel = null; } catch ( IOException e ) { @@ -359,27 +347,26 @@ public class DefaultUpdateCheckManager synchronized ( touchfile.getAbsolutePath().intern() ) { + FileInputStream in = null; FileLock lock = null; - FileChannel channel = null; + try { Properties props = new Properties(); - FileInputStream stream = new FileInputStream( touchfile ); - try - { - channel = stream.getChannel(); - lock = channel.lock( 0, channel.size(), true ); + in = new FileInputStream( touchfile ); + lock = in.getChannel().lock( 0, Long.MAX_VALUE, true ); - getLogger().debug( "Reading resolution-state from: " + touchfile ); - props.load( stream ); + getLogger().debug( "Reading resolution-state from: " + touchfile ); + props.load( in ); - return props; - } - finally - { - IOUtil.close( stream ); - } + lock.release(); + lock = null; + + in.close(); + in = null; + + return props; } catch ( IOException e ) { @@ -402,11 +389,11 @@ public class DefaultUpdateCheckManager } } - if ( channel != null ) + if ( in != null ) { try { - channel.close(); + in.close(); } catch ( IOException e ) {