gnodet-bot commented on code in PR #12694:
URL: https://github.com/apache/maven/pull/12694#discussion_r4058099580


##########
impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/AbstractUpgradeStrategy.java:
##########
@@ -424,55 +318,29 @@ protected Path findCommonRoot(Set<Path> pomPaths) {
         return commonRoot;
     }
 
-    /**
-     * Returns the effective model for the given POM path.
-     *
-     * <p>Consults {@link #effectiveModelCache} first (populated by the {@code 
BUILD_PROJECT}
-     * reactor pass in {@link #prebuildReactorModels}). If the path is not in 
the cache
-     * (e.g. an external parent that was not part of the reactor), falls back 
to a
-     * {@code BUILD_EFFECTIVE} call on {@link #sharedModelBuilderSession}, 
which still
-     * benefits from the {@code mappedSources} populated during the reactor 
build.</p>
-     *
-     * @param context the upgrade context (used for debug logging)
-     * @param pomPath the path to the POM file
-     * @return the effective model, never {@code null}
-     */
-    protected Model buildEffectiveModel(UpgradeContext context, Path pomPath) {
-        Path key = pomPath.toAbsolutePath().normalize();
-
-        // Fast path: reactor pre-build already has this model.
-        Map<Path, Model> cache = effectiveModelCache;
-        if (cache != null) {
-            Model cached = cache.get(key);
-            if (cached != null) {
-                context.debug("Effective model cache hit: " + pomPath);
-                return cached;
-            }
+    protected void cleanupTempDirectory(Path tempDir) {
+        try {
+            Files.walk(tempDir)

Review Comment:
   **[medium] `Files.walk()` stream not closed — filesystem handle leak**
   
   `Files.walk()` returns a `Stream<Path>` that holds an open directory handle 
until closed. The current code never closes it: if `forEach` throws (e.g. 
`SecurityException` from `File::delete`) the stream stays open until GC. In the 
previous code deleted by this PR, `AbstractUpgradeStrategyTest` used `try (var 
walk = Files.walk(...))` correctly — that pattern should be followed here.
   
   ```suggestion
       protected void cleanupTempDirectory(Path tempDir) {
           try (var walk = Files.walk(tempDir)) {
               walk.sorted(Comparator.reverseOrder())
                       .map(Path::toFile)
                       .forEach(File::delete);
           } catch (Exception e) {
               // Best effort cleanup
           }
       }
   ```



##########
impl/maven-core/src/test/java/org/apache/maven/project/MavenProjectGetArtifactsTest.java:
##########
@@ -1,87 +0,0 @@
-/*
- * 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.project;
-
-import java.util.ArrayList;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.locks.LockSupport;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-
-class MavenProjectGetArtifactsTest {
-
-    @Test
-    void concurrentGetArtifactsDoesNotExposeAHalfBuiltSet() throws Exception {
-        MavenProject project = new MavenProject();
-        Set<Artifact> resolved = new LinkedHashSet<>();
-        for (int i = 0; i < 200; i++) {
-            resolved.add(new DefaultArtifact("g", "a" + i, "1", "compile", 
"jar", "", null));
-        }
-        project.setResolvedArtifacts(resolved);
-        project.setArtifactFilter(artifact -> {
-            LockSupport.parkNanos(TimeUnit.MICROSECONDS.toNanos(50));
-            return true;
-        });
-
-        int readers = 4;
-        ExecutorService pool = Executors.newFixedThreadPool(readers);
-        CountDownLatch start = new CountDownLatch(1);
-        List<Future<?>> futures = new ArrayList<>();
-        try {
-            for (int i = 0; i < readers; i++) {
-                futures.add(pool.submit(() -> {
-                    start.await();
-                    Set<Artifact> artifacts = project.getArtifacts();
-                    assertEquals(resolved.size(), artifacts.size());
-                    AtomicInteger seen = new AtomicInteger();
-                    artifacts.forEach(artifact -> seen.incrementAndGet());
-                    assertEquals(resolved.size(), seen.get());
-                    return null;
-                }));
-            }
-            start.countDown();
-            for (Future<?> future : futures) {
-                try {
-                    future.get(30, TimeUnit.SECONDS);
-                } catch (ExecutionException e) {
-                    throw e.getCause() instanceof Exception ? (Exception) 
e.getCause() : e;
-                }
-            }
-        } finally {
-            pool.shutdownNow();
-        }
-
-        assertFalse(project.getArtifacts().isEmpty());
-        assertEquals(resolved.size(), project.getArtifacts().size());
-    }
-}

Review Comment:
   **[medium] Concurrency regression test deleted without replacement**
   
   This file is deleted by the PR, but the concurrency fix it covers 
(`MavenProject.getArtifacts()` — restore `result` local variable so `artifacts` 
is only assigned after the loop completes) is still present in the production 
code. Deleting the test removes the guard against this regression being 
reintroduced silently. The test should either be retained as-is (it's a clean, 
self-contained stress test) or ported into a different test class, but not 
simply deleted.
   
   Note that `MavenProject.artifacts` is still non-`volatile` and 
`getArtifacts()` is still unsynchronized — the `result` local variable prevents 
observers from seeing a half-populated set *during construction*, but two 
threads that both see `artifacts == null` will still both enter the if-block 
and both compute the set. Whether that's acceptable depends on the broader 
threading model of `MavenProject`, but the test at minimum ensures the final 
state is consistent.



-- 
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]

Reply via email to