Skip to content

Commit 358d5b4

Browse files
author
Vladimir I
committed
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.
1 parent 028404f commit 358d5b4

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.ByteArrayOutputStream;
2626
import java.io.File;
2727
import java.io.FileInputStream;
28+
import java.io.FileNotFoundException;
2829
import java.io.IOException;
2930
import java.io.RandomAccessFile;
3031
import java.io.UncheckedIOException;
@@ -60,6 +61,8 @@ public Properties read(File file) {
6061
Properties props = new Properties();
6162
props.load(stream);
6263
return props;
64+
} catch (FileNotFoundException e) {
65+
return null;
6366
} catch (IOException e) {
6467
LOGGER.warn("Failed to read tracking file '{}'", file, e);
6568
throw new UncheckedIOException(e);

maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultTrackingFileManagerTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020

2121
import java.io.File;
2222
import java.nio.charset.StandardCharsets;
23+
import java.nio.file.Paths;
2324
import java.util.ArrayList;
2425
import java.util.Collections;
2526
import java.util.HashMap;
2627
import java.util.List;
2728
import java.util.Map;
2829
import java.util.Properties;
2930

31+
import org.eclipse.aether.internal.impl.fs.DefaultTrackingTestFile;
3032
import org.eclipse.aether.internal.test.util.TestFileUtils;
3133
import org.junit.Test;
3234

@@ -104,6 +106,13 @@ public void testUpdateNoFileLeak() throws Exception {
104106
}
105107
}
106108

109+
@Test
110+
public void testFNFIgnoredOnMillingTrackingLock() throws Exception {
111+
TrackingFileManager tfm = new DefaultTrackingFileManager();
112+
Properties properties = tfm.read(new DefaultTrackingTestFile("hello\u0000", Paths.get("")));
113+
assertNull(properties);
114+
}
115+
107116
@Test
108117
public void testLockingOnCanonicalPath() throws Exception {
109118
final TrackingFileManager tfm = new DefaultTrackingFileManager();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.eclipse.aether.internal.impl.fs;
20+
21+
import java.io.File;
22+
import java.nio.file.Path;
23+
24+
/**
25+
* The DefaultTrackingTestFile class extends the File class and provides additional functionality
26+
* for working with files using a safe Path object.
27+
* This class ensures file operations are referenced and handled using the encapsulated Path instance.
28+
*/
29+
public class DefaultTrackingTestFile extends File {
30+
private final Path safePath;
31+
32+
public DefaultTrackingTestFile(String pathname, Path safePath) {
33+
super(pathname);
34+
this.safePath = safePath;
35+
}
36+
37+
@Override
38+
public Path toPath() {
39+
return safePath;
40+
}
41+
42+
@Override
43+
public String getCanonicalPath() {
44+
return safePath.toString();
45+
}
46+
}

0 commit comments

Comments
 (0)