Skip to content

Commit

Permalink
Fix unclosed opened stream
Browse files Browse the repository at this point in the history
Method ArtifactStore#get was used for checking only if artifact exist
but return was not consumed and opened stream was never closed
  • Loading branch information
slawekjaranowski committed Jun 17, 2022
1 parent 8297bfd commit ce8e541
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ public ArtifactStoreFileSystem( ArtifactStore store )
this.store = store;
}

/**
* {@inheritDoc}
*/
@Override
public Entry[] listEntries( DirectoryEntry directory )
{
if ( getRoot().equals( directory ) )
Expand Down Expand Up @@ -164,7 +162,6 @@ public Entry[] listEntries( DirectoryEntry directory )
String groupId = path.replace( '/', '.' );

// get all the groupId's that start with this groupId
String groupIdPrefix = groupId + ".";
Set<String> groupIds = new TreeSet<>( store.getGroupIds( groupId ) );
for ( String name : groupIds )
{
Expand Down Expand Up @@ -223,9 +220,7 @@ public Entry[] listEntries( DirectoryEntry directory )
return result.toArray(new Entry[0]);
}

/**
* {@inheritDoc}
*/
@Override
protected Entry get( DirectoryEntry parent, String name )
{
String path = "/";
Expand Down Expand Up @@ -299,7 +294,8 @@ else if ( ARCHETYPE_CATALOG.matcher( path ).matches() )
matcher.group( 10 ) );
try
{
store.get( artifact );
// check if artifact exist
store.getSize( artifact );
return new ArtifactFileEntry( this, parent, artifact, store );
}
catch ( IOException | ArtifactNotFoundException e )
Expand All @@ -325,7 +321,8 @@ else if ( ARCHETYPE_CATALOG.matcher( path ).matches() )
matcher.group( 10 ), timestamp, buildNumber );
try
{
store.get( artifact );
// check if artifact exist
store.getSize( artifact );
return new ArtifactFileEntry( this, parent, artifact, store );
}
catch ( IOException | ArtifactNotFoundException e )
Expand Down Expand Up @@ -360,7 +357,8 @@ else if ( ARCHETYPE_CATALOG.matcher( path ).matches() )
Artifact artifact = new Artifact( groupId, artifactId, version, classifier, type );
try
{
store.get( artifact );
// check if artifact exist
store.getSize( artifact );
return new ArtifactFileEntry( this, parent, artifact, store );
}
catch ( ArtifactNotFoundException | IOException e )
Expand All @@ -376,9 +374,7 @@ else if ( ARCHETYPE_CATALOG.matcher( path ).matches() )
}
}

/**
* {@inheritDoc}
*/
@Override
public long getLastModified( DirectoryEntry entry )
throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public class ArtifactStoreFileSystemTest

@Test
public void testGroupMetadataRegex()
throws Exception
{
Matcher matcher = ArtifactStoreFileSystem.METADATA.matcher( "/commons/maven-metadata.xml" );
assertTrue( matcher.matches() );
Expand All @@ -56,7 +55,6 @@ public void testGroupMetadataRegex()

@Test
public void testArtifactRegex()
throws Exception
{
Matcher matcher = ArtifactStoreFileSystem.ARTIFACT.matcher( "/commons/maven-metadata.xml" );
assertFalse( matcher.matches() );
Expand Down Expand Up @@ -109,7 +107,6 @@ public void testArtifactRegex()

@Test
public void testSnapshotArtifactRegex()
throws Exception
{
Matcher matcher = ArtifactStoreFileSystem.SNAPSHOT_ARTIFACT.matcher( "/commons/maven-metadata.xml" );
assertFalse( matcher.matches() );
Expand Down Expand Up @@ -159,7 +156,7 @@ public void testSnapshotArtifactRegex()
public void testSiteXmlReleaseVersion() throws Exception
{
ArtifactStore store = mock( ArtifactStore.class );
when( store.get( isA( Artifact.class ) ) ).thenThrow( ArtifactNotFoundException.class );
when( store.getSize( isA( Artifact.class ) ) ).thenThrow( ArtifactNotFoundException.class );
ArtifactStoreFileSystem system = new ArtifactStoreFileSystem( store );
FileEntry entry = (FileEntry) system.get( "/localhost/mmockrm-5/1/mmockrm-5-1-site_en.xml" );
assertNull( entry );
Expand All @@ -169,7 +166,7 @@ public void testSiteXmlReleaseVersion() throws Exception
public void testSiteXmlSnapshotVersion() throws Exception
{
ArtifactStore store = mock( ArtifactStore.class );
when( store.get( isA( Artifact.class ) ) ).thenThrow( ArtifactNotFoundException.class );
when( store.getSize( isA( Artifact.class ) ) ).thenThrow( ArtifactNotFoundException.class );
ArtifactStoreFileSystem system = new ArtifactStoreFileSystem( store );
FileEntry entry = (FileEntry) system.get( "/localhost/mmockrm-5/1.0-SNAPSHOT/mmockrm-5-1.0-SNAPSHOT-site_en.xml" );
assertNull( entry );
Expand Down

0 comments on commit ce8e541

Please sign in to comment.