Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

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;
import java.util.List;
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;

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}