gnodet-bot commented on code in PR #13945: URL: https://github.com/apache/maven/pull/13945#discussion_r4526311953
########## api/maven-api-core/src/main/java/org/apache/maven/api/OperationService.java: ########## @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.api; + +import org.apache.maven.api.annotations.Experimental; +import org.apache.maven.api.annotations.ThreadSafe; +import org.apache.maven.api.cache.CacheMetadata; +import org.apache.maven.api.cache.CacheRetention; +import org.apache.maven.api.services.Request; +import org.apache.maven.api.services.RequestTrace; +import org.apache.maven.api.services.Result; + +/** + * Marker interface for services whose operations participate in the shared request pipeline. + * Implementations submit their requests to the session's request pipeline, which provides + * caching and the context needed to observe operation lifecycles. Requests and results + * describe the work, while request traces identify the operations that initiated it. + * + * <p>Participation does not require caching: operations with side effects must disable + * caching using {@link CacheMetadata} and {@link CacheRetention#DISABLED}. + * Lightweight utilities, factories and leaf operations that do not benefit from the + * pipeline extend {@link Service} directly.</p> Review Comment: The `@ThreadSafe` annotation is a contract, but the Javadoc doesn't state what it requires of implementations. Add a sentence: ```suggestion * Marker interface for services whose operations participate in the shared request pipeline. * Implementations submit their requests to the session's request pipeline, which provides * caching and the context needed to observe operation lifecycles. Requests and results * describe the work, while request traces identify the operations that initiated it. * * <p>Implementations must be safe for concurrent use by multiple threads.</p> * * <p>Participation does not require caching: operations with side effects must disable * caching using {@link CacheMetadata} and {@link CacheRetention#DISABLED}. * Lightweight utilities, factories and leaf operations that do not benefit from the * pipeline extend {@link Service} directly.</p> ``` ########## api/maven-api-core/src/main/java/org/apache/maven/api/services/DependencyCoordinatesFactory.java: ########## @@ -71,7 +125,18 @@ default DependencyCoordinates create(@Nonnull Session session, @Nonnull Artifact @Nonnull default DependencyCoordinates create( @Nonnull Session session, @Nonnull org.apache.maven.api.Dependency dependency) { - return create(DependencyCoordinatesFactoryRequest.build(session, dependency)); + requireNonNull(dependency, "dependency"); + return create( + session, + dependency.groupId(), + dependency.artifactId(), + dependency.version().toString(), + dependency.classifier(), + dependency.extension(), + dependency.type().id(), + dependency.scope().id(), + dependency.isOptional(), + List.of()); Review Comment: `api.Dependency.toCoordinates()` returns `DependencyCoordinates`, which carries `exclusions()`. Passing `List.of()` silently drops all exclusions declared on the dependency. The old code had the same bug; now that the primary API exposes `exclusions` explicitly, this is a one-line fix: ```suggestion dependency.isOptional(), dependency.toCoordinates().exclusions()); ``` ########## impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultVersionResolver.java: ########## @@ -52,12 +52,17 @@ public DefaultVersionResolver(RepositorySystem repositorySystem) { public VersionResolverResult resolve(VersionResolverRequest request) throws VersionResolverException { requireNonNull(request, "request"); InternalSession session = InternalSession.from(request.getSession()); - return session.request(request, this::doResolve); + RequestTraceHelper.ResolverTrace trace = RequestTraceHelper.enter(session, request); + try { + return session.request(request, this::doResolve); + } finally { + RequestTraceHelper.exit(trace); + } } protected VersionResolverResult doResolve(VersionResolverRequest request) throws VersionResolverException { InternalSession session = InternalSession.from(request.getSession()); - RequestTraceHelper.ResolverTrace trace = RequestTraceHelper.enter(session, request); + org.apache.maven.api.services.RequestTrace trace = RequestTraceHelper.getCurrentTrace(session); Review Comment: Same issue as `DefaultVersionRangeResolver.doResolve()`. `getCurrentTrace()` can return `null`; `trace.context()` at line 73 will NPE if this `protected` method is called by a subclass without first entering a trace scope via `resolve()`. Consider making it `private` or adding a null guard. ########## impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultArtifactResolver.java: ########## @@ -101,8 +106,8 @@ protected ArtifactResolverResult doResolve(ArtifactResolverRequest request) { req.setRepositories(repositories); req.setArtifact(session.toArtifact(coords)); req.setRequestContext(trace.context()); Review Comment: `getCurrentTrace()` may return `null`; this `protected` method then calls `trace.context()` unconditionally. Same pattern as `DefaultVersionRangeResolver`/`DefaultVersionResolver`. Normal pipeline path always sets a trace first, but a subclass calling `doResolve()` directly will NPE here. ########## impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultVersionRangeResolver.java: ########## @@ -58,13 +58,18 @@ public VersionRangeResolverResult resolve(VersionRangeResolverRequest request) throws VersionRangeResolverException { requireNonNull(request, "request"); InternalSession session = InternalSession.from(request.getSession()); - return session.request(request, this::doResolve); + RequestTraceHelper.ResolverTrace trace = RequestTraceHelper.enter(session, request); + try { + return session.request(request, this::doResolve); + } finally { + RequestTraceHelper.exit(trace); + } } public VersionRangeResolverResult doResolve(VersionRangeResolverRequest request) Review Comment: `doResolve()` is `public`. After this change it calls `getCurrentTrace(session)` which returns `null` if no trace is active, then dereferences `trace.context()` at line 83 — NPE if invoked directly without a prior `enter()`. All known callers go through `resolve()`, but the method is part of the public API surface. Consider making it `private` (no external callers exist), or add a null guard on `trace` before the `trace.context()` call. -- 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]
