Skip to content

Commit 5b6c319

Browse files
authored
[MRESOLVER-278] Session close and onClose hooks fix (#207)
There are valid cases in Maven when interaction with resolver (that would "lazily" init SyncContext) happens way late, when session is already done readOnly. Fix: adding onCloseHandler should NOT be affected by readOnly state of session, as it merely means it's members like LRM, etc are "fixed", but session data etc are all still mutable. This change makes all Maven ITs pass with this resolver.
1 parent b365567 commit 5b6c319

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

maven-resolver-api/src/main/java/org/eclipse/aether/DefaultRepositorySystemSession.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -816,9 +816,9 @@ private void verifyStateForMutation()
816816
{
817817
throw new IllegalStateException( "repository system session is read-only" );
818818
}
819-
if ( isClosed() )
819+
if ( closed.get() )
820820
{
821-
throw new IllegalStateException( "repository system session is closed" );
821+
throw new IllegalStateException( "repository system session is already closed" );
822822
}
823823
}
824824

@@ -894,8 +894,11 @@ public Collection<FileTransformer> getTransformersForArtifact( Artifact artifact
894894
@Override
895895
public void addOnCloseHandler( Consumer<RepositorySystemSession> handler )
896896
{
897-
verifyStateForMutation();
898897
requireNonNull( handler, "handler cannot be null" );
898+
if ( closed.get() )
899+
{
900+
throw new IllegalStateException( "repository system session is already closed" );
901+
}
899902
onCloseHandlers.add( 0, handler );
900903
}
901904

0 commit comments

Comments
 (0)