correctly close inputstream Signed-off-by: olivier lamy <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/maven-indexer/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-indexer/commit/a354f5c7 Tree: http://git-wip-us.apache.org/repos/asf/maven-indexer/tree/a354f5c7 Diff: http://git-wip-us.apache.org/repos/asf/maven-indexer/diff/a354f5c7 Branch: refs/heads/master Commit: a354f5c72a821e76e00486a407136630cf8d15b4 Parents: a49cfdc Author: olivier lamy <[email protected]> Authored: Mon Jul 24 11:54:21 2017 +1000 Committer: olivier lamy <[email protected]> Committed: Mon Jul 24 11:54:21 2017 +1000 ---------------------------------------------------------------------- .../org/apache/maven/index/locator/ArtifactLocator.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/a354f5c7/indexer-core/src/main/java/org/apache/maven/index/locator/ArtifactLocator.java ---------------------------------------------------------------------- diff --git a/indexer-core/src/main/java/org/apache/maven/index/locator/ArtifactLocator.java b/indexer-core/src/main/java/org/apache/maven/index/locator/ArtifactLocator.java index d27d2a6..f4feb34 100644 --- a/indexer-core/src/main/java/org/apache/maven/index/locator/ArtifactLocator.java +++ b/indexer-core/src/main/java/org/apache/maven/index/locator/ArtifactLocator.java @@ -22,6 +22,8 @@ package org.apache.maven.index.locator; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; import org.apache.maven.index.artifact.ArtifactPackagingMapper; import org.apache.maven.index.artifact.Gav; @@ -48,16 +50,19 @@ public class ArtifactLocator public File locate( File source, GavCalculator gavCalculator, Gav gav ) { // if we don't have this data, nothing we can do - if ( source == null || !source.exists() || gav == null || gav.getArtifactId() == null + if ( source == null // + || !source.exists() // + || gav == null // + || gav.getArtifactId() == null // || gav.getVersion() == null ) { return null; } - try + try (InputStream inputStream = Files.newInputStream( source.toPath() )) { // need to read the pom model to get packaging - final Model model = new MavenXpp3Reader().read( new FileInputStream( source ), false ); + final Model model = new MavenXpp3Reader().read( inputStream, false ); if ( model == null ) {
