From ecedc12dfb8f1cbaacc27dd7284770c456dbd66d Mon Sep 17 00:00:00 2001 From: Vladimir I Date: Wed, 26 Nov 2025 11:32:53 +0100 Subject: [PATCH] Prevent FileNotFoundException when reading .lastUpdated tracking files Reading tracking metadata could fail with a java.io.FileNotFoundException during concurrent repository access or cleanup, causing update checks and dependency collection to break. This patch adds a dedicated FileNotFoundException catch block in DefaultTrackingFileManager.read(), allowing the resolver to safely ignore missing or invalid tracking files and return null instead of failing. --- .../impl/DefaultTrackingFileManager.java | 3 ++ .../impl/DefaultTrackingFileManagerTest.java | 9 ++++ .../impl/fs/DefaultTrackingTestFile.java | 46 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/fs/DefaultTrackingTestFile.java diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManager.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManager.java index 8f41f7d2f..b2009c8a3 100644 --- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManager.java +++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManager.java @@ -25,6 +25,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.io.UncheckedIOException; @@ -60,6 +61,8 @@ public Properties read(File file) { Properties props = new Properties(); props.load(stream); return props; + } catch (FileNotFoundException e) { + return null; } catch (IOException e) { LOGGER.warn("Failed to read tracking file '{}'", file, e); throw new UncheckedIOException(e); diff --git a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManagerTest.java b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManagerTest.java index 7209ed798..2c980a9d5 100644 --- a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManagerTest.java +++ b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManagerTest.java @@ -20,6 +20,7 @@ import java.io.File; import java.nio.charset.StandardCharsets; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -27,6 +28,7 @@ import java.util.Map; import java.util.Properties; +import org.eclipse.aether.internal.impl.fs.DefaultTrackingTestFile; import org.eclipse.aether.internal.test.util.TestFileUtils; import org.junit.Test; @@ -104,6 +106,13 @@ public void testUpdateNoFileLeak() throws Exception { } } + @Test + public void testFileNotFoundIsIgnoredWhenReadingTrackingFile() { + TrackingFileManager tfm = new DefaultTrackingFileManager(); + Properties properties = tfm.read(new DefaultTrackingTestFile("hello\u0000", Paths.get(""))); + assertNull(properties); + } + @Test public void testLockingOnCanonicalPath() throws Exception { final TrackingFileManager tfm = new DefaultTrackingFileManager(); diff --git a/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/fs/DefaultTrackingTestFile.java b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/fs/DefaultTrackingTestFile.java new file mode 100644 index 000000000..3430c34e8 --- /dev/null +++ b/maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/fs/DefaultTrackingTestFile.java @@ -0,0 +1,46 @@ +/* + * 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.eclipse.aether.internal.impl.fs; + +import java.io.File; +import java.nio.file.Path; + +/** + * The DefaultTrackingTestFile class extends the File class and provides additional functionality + * for working with files using a safe Path object. + * This class ensures file operations are referenced and handled using the encapsulated Path instance. + */ +public class DefaultTrackingTestFile extends File { + private final Path safePath; + + public DefaultTrackingTestFile(String pathname, Path safePath) { + super(pathname); + this.safePath = safePath; + } + + @Override + public Path toPath() { + return safePath; + } + + @Override + public String getCanonicalPath() { + return safePath.toString(); + } +}