Apache Solr open-source search software
SOLR-16903: Make java.io.File a forbidden API (#3321)
Matthew Biscochob91905a653ea
diff --git a/gradle/validation/forbidden-apis/defaults.all.txt b/gradle/validation/forbidden-apis/defaults.all.txtindex a8be2d60091..f5ca3ae746f 100644--- a/gradle/validation/forbidden-apis/defaults.all.txt+++ b/gradle/validation/forbidden-apis/defaults.all.txt@@ -99,4 +99,7 @@ java.util.Locale#<init>(**)java.nio.file.Paths#get(**)@defaultMessage You probably meant to call String.startsWith-java.nio.file.Path#startsWith(java.lang.String)\ No newline at end of file+java.nio.file.Path#startsWith(java.lang.String)++@defaultMessage Use NIO Path instead of File+java.io.File\ No newline at end of filediff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 48c1e2e2fcf..1f8ed585ce5 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -166,12 +166,10 @@ Other Changes* SOLR-17321: Minimum Java version for Apache Solr is now 21, and for SolrJ, it is 17. (Sanjay Dutt, David Smiley)-* SOLR-16903: Update CLI tools and Solr Core to use java.nio.file.Path instead of java.io.File (Andrey Bozhko, Matthew Biscocho)+* SOLR-16903: Replace all java.io.File usages to java.nio.file.Path (NIO) (Andrey Bozhko, Matthew Biscocho)* SOLR-17568: SolrCloud no longer reroutes/proxies a core request to another node if not found locally. (David Smiley)-* SOLR-17548: Switch all public Java APIs from File to Path. (Matthew Biscocho via Eric Pugh)-* SOLR-17675: Remove DirContext param from DirectoryFactory.create method. (Bruno Roustant, David Smiley)* SOLR-16903: Switch CoreContainer#getSolrHome to return Path instead of String (Andrey Bozhko)diff --git a/solr/core/src/java/org/apache/solr/core/CoreContainer.java b/solr/core/src/java/org/apache/solr/core/CoreContainer.javaindex 10d00987e6f..35881ec9121 100644--- a/solr/core/src/java/org/apache/solr/core/CoreContainer.java+++ b/solr/core/src/java/org/apache/solr/core/CoreContainer.java@@ -35,6 +35,7 @@ import io.opentelemetry.api.trace.Tracer;import jakarta.inject.Singleton;import java.io.IOException;import java.lang.invoke.MethodHandles;+import java.nio.file.Files;import java.nio.file.Path;import java.text.SimpleDateFormat;import java.util.Arrays;@@ -1002,13 +1003,32 @@ public class CoreContainer {Path dataHome =cfg.getSolrDataHome() != null ? cfg.getSolrDataHome() : cfg.getCoreRootDirectory();solrMetricsContext.gauge(- () -> dataHome.toFile().getTotalSpace(),+ () -> {+ try {+ return Files.getFileStore(dataHome).getTotalSpace();+ } catch (IOException e) {+ throw new SolrException(+ ErrorCode.SERVER_ERROR,+ "Error retrieving total space for data home directory" + dataHome,+ e);+ }+ },true,"totalSpace",SolrInfoBean.Category.CONTAINER.toString(),"fs");+solrMetricsContext.gauge(- () -> dataHome.toFile().getUsableSpace(),+ () -> {+ try {+ return Files.getFileStore(dataHome).getUsableSpace();+ } catch (IOException e) {+ throw new SolrException(+ ErrorCode.SERVER_ERROR,+ "Error retrieving usable space for data home directory" + dataHome,+ e);+ }+ },true,"usableSpace",SolrInfoBean.Category.CONTAINER.toString(),@@ -1016,14 +1036,34 @@ public class CoreContainer {solrMetricsContext.gauge(dataHome::toString, true, "path", SolrInfoBean.Category.CONTAINER.toString(), "fs");solrMetricsContext.gauge(- () -> cfg.getCoreRootDirectory().toFile().getTotalSpace(),+ () -> {+ try {+ return Files.getFileStore(cfg.getCoreRootDirectory()).getTotalSpace();+ } catch (IOException e) {+ throw new SolrException(+ SolrException.ErrorCode.SERVER_ERROR,+ "Error retrieving total space for core root directory: "+ + cfg.getCoreRootDirectory(),+ e);+ }+ },true,"totalSpace",SolrInfoBean.Category.CONTAINER.toString(),"fs","coreRoot");solrMetricsContext.gauge(- () -> cfg.getCoreRootDirectory().toFile().getUsableSpace(),+ () -> {+ try {+ return Files.getFileStore(cfg.getCoreRootDirectory()).getUsableSpace();+ } catch (IOException e) {+ throw new SolrException(+ SolrException.ErrorCode.SERVER_ERROR,+ "Error retrieving usable space for core root directory: "+ + cfg.getCoreRootDirectory(),+ e);+ }+ },true,"usableSpace",SolrInfoBean.Category.CONTAINER.toString(),diff --git a/solr/core/src/java/org/apache/solr/filestore/DistribFileStore.java b/solr/core/src/java/org/apache/solr/filestore/DistribFileStore.javaindex 0e654491832..99b5b90e14c 100644--- a/solr/core/src/java/org/apache/solr/filestore/DistribFileStore.java+++ b/solr/core/src/java/org/apache/solr/filestore/DistribFileStore.java@@ -285,7 +285,12 @@ public class DistribFileStore implements FileStore {@Overridepublic Date getTimeStamp() {- return new Date(realPath().toFile().lastModified());+ try {+ return new Date(Files.getLastModifiedTime(realPath()).toMillis());+ } catch (IOException e) {+ throw new SolrException(+ SERVER_ERROR, "Failed to retrieve the last modified time for: " + realPath(), e);+ }}@Override@@ -295,7 +300,12 @@ public class DistribFileStore implements FileStore {@Overridepublic long size() {- return realPath().toFile().length();+ try {+ return Files.size(realPath());+ } catch (IOException e) {+ throw new SolrException(+ SERVER_ERROR, "Failed to retrieve the file size for: " + realPath(), e);+ }}@Overridediff --git a/solr/core/src/java/org/apache/solr/packagemanager/DefaultPackageRepository.java b/solr/core/src/java/org/apache/solr/packagemanager/DefaultPackageRepository.javaindex a7900124e70..8fbbfbbd347 100644--- a/solr/core/src/java/org/apache/solr/packagemanager/DefaultPackageRepository.java+++ b/solr/core/src/java/org/apache/solr/packagemanager/DefaultPackageRepository.java@@ -31,6 +31,7 @@ import java.util.function.Function;import java.util.stream.Collectors;import org.apache.commons.io.FileUtils;import org.apache.commons.io.FilenameUtils;+import org.apache.commons.io.file.PathUtils;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;import org.slf4j.Logger;@@ -80,7 +81,7 @@ public class DefaultPackageRepository extends PackageRepository {@Overridepublic Path download(String artifactName) throws SolrException, IOException {Path tmpDirectory = Files.createTempDirectory("solr-packages");- tmpDirectory.toFile().deleteOnExit();+ PathUtils.deleteOnExit(tmpDirectory);URL url = getRepoUri().resolve(artifactName).toURL();String fileName = FilenameUtils.getName(url.getPath());Path destination = tmpDirectory.resolve(fileName);diff --git a/solr/core/src/java/org/apache/solr/update/UpdateLog.java b/solr/core/src/java/org/apache/solr/update/UpdateLog.javaindex 9993e1bb642..c26eb7f77d7 100644--- a/solr/core/src/java/org/apache/solr/update/UpdateLog.java+++ b/solr/core/src/java/org/apache/solr/update/UpdateLog.java@@ -55,6 +55,7 @@ import java.util.concurrent.atomic.AtomicBoolean;import java.util.concurrent.atomic.AtomicInteger;import java.util.concurrent.atomic.AtomicReference;import java.util.stream.Stream;+import org.apache.commons.io.file.PathUtils;import org.apache.lucene.store.Directory;import org.apache.lucene.util.BytesRef;import org.apache.solr.common.SolrDocumentBase;@@ -2439,7 +2440,7 @@ public class UpdateLog implements PluginInfoInitialized, SolrMetricProducer {if (!success) {try {- file.toFile().deleteOnExit();+ PathUtils.deleteOnExit(file);} catch (Exception e) {log.error("Error deleting file on exit: {}", file, e);}diff --git a/solr/core/src/test/org/apache/solr/cli/SolrCLIZkToolsTest.java b/solr/core/src/test/org/apache/solr/cli/SolrCLIZkToolsTest.javaindex 35e2e019dbc..c7101a0f493 100644--- a/solr/core/src/test/org/apache/solr/cli/SolrCLIZkToolsTest.java+++ b/solr/core/src/test/org/apache/solr/cli/SolrCLIZkToolsTest.java@@ -146,7 +146,8 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {verifyZkLocalPathsMatch(tmp.resolve("conf"), "/configs/downconfig2");// And insure the empty file is a text filePath destEmpty = tmp2.resolve("conf").resolve("stopwords").resolve("emptyfile");- assertTrue("Empty files should NOT be copied down as directories", destEmpty.toFile().isFile());+ assertTrue(+ "Empty files should NOT be copied down as directories", Files.isRegularFile(destEmpty));}@Test@@ -326,7 +327,7 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {// Next, copy cp7 down and verify that zknode.data exists for cp7Path zData = tmp.resolve("conf/stopwords/zknode.data");- assertTrue("znode.data should have been copied down", zData.toFile().exists());+ assertTrue("znode.data should have been copied down", Files.exists(zData));// Finally, copy up to cp8 and verify that the data is up there.args = new String[] {"cp", "--recursive", "--zk-host", zkAddr, "file:" + tmp, "zk:/cp9"};@@ -385,7 +386,8 @@ public class SolrCLIZkToolsTest extends SolrCloudTestCase {assertEquals("Copy should have succeeded.", 0, res);Path locEmpty = tmp2.resolve("stopwords/emptyfile");- assertTrue("Empty files should NOT be copied down as directories", locEmpty.toFile().isFile());+ assertTrue(+ "Empty files should NOT be copied down as directories", Files.isRegularFile(locEmpty));}@Testdiff --git a/solr/core/src/test/org/apache/solr/cli/SolrProcessManagerTest.java b/solr/core/src/test/org/apache/solr/cli/SolrProcessManagerTest.javaindex c0bb17f59c7..6ca700d2f15 100644--- a/solr/core/src/test/org/apache/solr/cli/SolrProcessManagerTest.java+++ b/solr/core/src/test/org/apache/solr/cli/SolrProcessManagerTest.java@@ -56,8 +56,7 @@ public class SolrProcessManagerTest extends SolrTestCase {long processHttpsValue = isWindows ? processHttps.getKey() : processHttps.getValue().pid();SolrProcessManager.enableTestingMode = true;System.setProperty("jetty.port", Integer.toString(processHttp.getKey()));- Path pidDir = Files.createTempDirectory("solr-pid-dir").toAbsolutePath();- pidDir.toFile().deleteOnExit();+ Path pidDir = createTempDir("solr-pid-dir");System.setProperty("solr.pid.dir", pidDir.toString());Files.writeString(pidDir.resolve("solr-" + processHttpValue + PID_SUFFIX), Long.toString(processHttpValue));diff --git a/solr/core/src/test/org/apache/solr/cloud/ShardRoutingCustomTest.java b/solr/core/src/test/org/apache/solr/cloud/ShardRoutingCustomTest.javaindex 53fe7a7b07a..004d7cc06e8 100644--- a/solr/core/src/test/org/apache/solr/cloud/ShardRoutingCustomTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/ShardRoutingCustomTest.java@@ -61,8 +61,7 @@ public class ShardRoutingCustomTest extends AbstractFullDistribZkTestBase {Files.createDirectories(jettyDir);setupJettySolrHome(jettyDir);JettySolrRunner j =- createJetty(- jettyDir, createTempDir().toFile().getAbsolutePath(), "shardA", "solrconfig.xml", null);+ createJetty(jettyDir, createTempDir().toString(), "shardA", "solrconfig.xml", null);j.start();assertEquals(0,diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.javaindex 7be45b2daac..40e56159dcf 100644--- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java+++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPI.java@@ -207,7 +207,6 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {throws Exception {final Path configDir = getFile("solr").resolve("configsets/configset-2/conf");final Path tmpConfigDir = createTempDir();- tmpConfigDir.toFile().deleteOnExit();PathUtils.copyDirectory(configDir, tmpConfigDir);if (oldProps != null) {Files.writeString(@@ -1568,7 +1567,6 @@ public class TestConfigSetsAPI extends SolrCloudTestCase {final SolrClient solrClient = getHttpSolrClient(baseUrl);final Path configDir = getFile("solr").resolve("configsets/configset-2/conf");final Path tmpConfigDir = createTempDir();- tmpConfigDir.toFile().deleteOnExit();// Ensure ConfigSet is immutablePathUtils.copyDirectory(configDir, tmpConfigDir);Files.writeString(diff --git a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.javaindex bc644f1a362..f271850fd62 100644--- a/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java+++ b/solr/core/src/test/org/apache/solr/cloud/TestConfigSetsAPIZkFailure.java@@ -143,7 +143,6 @@ public class TestConfigSetsAPIZkFailure extends SolrTestCaseJ4 {throws Exception {final Path configDir = getFile("solr").resolve("configsets/configset-2/conf");final Path tmpConfigDir = createTempDir();- tmpConfigDir.toFile().deleteOnExit();PathUtils.copyDirectory(configDir, tmpConfigDir);if (oldProps != null) {Files.writeString(diff --git a/solr/core/src/test/org/apache/solr/core/CachingDirectoryFactoryTest.java b/solr/core/src/test/org/apache/solr/core/CachingDirectoryFactoryTest.javaindex c7ba1e9f299..e600738993b 100644--- a/solr/core/src/test/org/apache/solr/core/CachingDirectoryFactoryTest.java+++ b/solr/core/src/test/org/apache/solr/core/CachingDirectoryFactoryTest.java@@ -96,7 +96,7 @@ public class CachingDirectoryFactoryTest extends SolrTestCaseJ4 {df.release(a);assertTrue("The path " + pathA + " should exist because it has subdirs that prevent removal",- pathA.toFile().exists()); // we know there are subdirs that should prevent removal+ Files.exists(pathA)); // we know there are subdirs that should prevent removalCollections.shuffle(Arrays.asList(subdirs), r);for (Map.Entry<String, Directory> e : subdirs) {boolean after = removeAfter.getAsBoolean();@@ -126,7 +126,7 @@ public class CachingDirectoryFactoryTest extends SolrTestCaseJ4 {} else {assertTrue("There are subdirs to wait on, so the parent directory should still exist",- pathA.toFile().exists()); // parent must still be present+ Files.exists(pathA)); // parent must still be presentfor (Map.Entry<String, Directory> e : subdirs) {Path path = Path.of(e.getKey());boolean exists = Files.exists(path);diff --git a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.javaindex ecff729bf78..29535e39d5d 100644--- a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java+++ b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCloudSnapshots.java@@ -183,7 +183,7 @@ public class TestSolrCloudSnapshots extends SolrCloudTestCase {BackupRestoreUtils.verifyDocs(0, solrClient, collectionName);}- String backupLocation = createTempDir().toFile().getAbsolutePath();+ String backupLocation = createTempDir().toString();String backupName = "mytestbackup";String restoreCollectionName = collectionName + "_restored";diff --git a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.javaindex 935f1d0bda0..0feb4af0ace 100644--- a/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java+++ b/solr/core/src/test/org/apache/solr/core/snapshots/TestSolrCoreSnapshots.java@@ -92,7 +92,7 @@ public class TestSolrCoreSnapshots extends SolrCloudTestCase {CollectionAdminRequest.createCollection(collectionName, "conf1", 1, 1);create.process(solrClient);- String location = createTempDir().toFile().getAbsolutePath();+ String location = createTempDir().toString();int nDocs = BackupRestoreUtils.indexDocs(cluster.getSolrClient(), collectionName, docsSeed);DocCollection collectionState = solrClient.getClusterState().getCollection(collectionName);diff --git a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.javaindex 4117af54a19..5eb89f66990 100644--- a/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java+++ b/solr/core/src/test/org/apache/solr/handler/TestRestoreCore.java@@ -117,7 +117,7 @@ public class TestRestoreCore extends SolrJettyTestBase {// Use the default backup location or an externally provided location.if (random().nextBoolean()) {- location = createTempDir().toFile().getAbsolutePath();+ location = createTempDir().toString();leaderJetty.getCoreContainer().getAllowPaths()@@ -182,8 +182,7 @@ public class TestRestoreCore extends SolrJettyTestBase {public void testBackupFailsMissingAllowPaths() throws Exception {final String params =- "&location="- + URLEncoder.encode(createTempDir().toFile().getAbsolutePath(), StandardCharsets.UTF_8);+ "&location=" + URLEncoder.encode(createTempDir().toString(), StandardCharsets.UTF_8);Throwable t =expectThrows(IOException.class,@@ -199,7 +198,7 @@ public class TestRestoreCore extends SolrJettyTestBase {public void testFailedRestore() throws Exception {int nDocs = BackupRestoreUtils.indexDocs(leaderClient, "collection1", docsSeed);- String location = createTempDir().toFile().getAbsolutePath();+ String location = createTempDir().toString();leaderJetty.getCoreContainer().getAllowPaths().add(Path.of(location));String snapshotName = TestUtil.randomSimpleString(random(), 1, 5);String params =diff --git a/solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.java b/solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.javaindex d9872f4b19d..438251f8c3d 100644--- a/solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.java+++ b/solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.java@@ -236,7 +236,7 @@ public class V2ApiIntegrationTest extends SolrCloudTestCase {assertEquals("/collections/collection1/get",Utils.getObjectByPath(result, true, "/spec[0]/url/paths[0]"));- String tempDir = createTempDir().toFile().getPath();+ String tempDir = createTempDir().toString();Map<String, Object> backupParams = new HashMap<>();backupParams.put("location", tempDir);clusterdiff --git a/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginIntegrationTest.java b/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginIntegrationTest.javaindex c0a2b418d26..c2644665e5f 100644--- a/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginIntegrationTest.java+++ b/solr/modules/jwt-auth/src/test/org/apache/solr/security/jwt/JWTAuthPluginIntegrationTest.java@@ -55,6 +55,7 @@ import org.apache.http.client.methods.HttpPost;import org.apache.http.entity.ByteArrayEntity;import org.apache.http.entity.ContentType;import org.apache.http.impl.client.CloseableHttpClient;+import org.apache.lucene.tests.mockfile.FilterPath;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.client.solrj.impl.HttpClientUtil;import org.apache.solr.cloud.MiniSolrCloudCluster;@@ -104,9 +105,7 @@ public class JWTAuthPluginIntegrationTest extends SolrCloudAuthTestCase {pemFilePath = JWT_TEST_PATH().resolve("security").resolve("jwt_plugin_idp_cert.pem");wrongPemFilePath = JWT_TEST_PATH().resolve("security").resolve("jwt_plugin_idp_wrongcert.pem");- Path tempDir = Files.createTempDirectory(JWTAuthPluginIntegrationTest.class.getSimpleName());- tempDir.toFile().deleteOnExit();-+ Path tempDir = FilterPath.unwrap(createTempDir());Path modifiedP12Cert = tempDir.resolve(p12Cert.getFileName());new KeystoreGenerator().generateKeystore(diff --git a/solr/modules/llm/src/test/org/apache/solr/llm/TestLlmBase.java b/solr/modules/llm/src/test/org/apache/solr/llm/TestLlmBase.javaindex 84da95ca3ad..bd79b2dcbc3 100644--- a/solr/modules/llm/src/test/org/apache/solr/llm/TestLlmBase.java+++ b/solr/modules/llm/src/test/org/apache/solr/llm/TestLlmBase.java@@ -60,9 +60,7 @@ public class TestLlmBase extends RestTestBase {protected static void initFolders(boolean isPersistent) throws Exception {tmpSolrHome = createTempDir();tmpConfDir = tmpSolrHome.resolve(CONF_DIR);- tmpConfDir.toFile().deleteOnExit();PathUtils.copyDirectory(TEST_PATH(), tmpSolrHome.toAbsolutePath());-final Path modelStore = tmpConfDir.resolve(MODEL_FILE_NAME);if (isPersistent) {diff --git a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestRerankBase.java b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestRerankBase.javaindex 4570df1e7a8..4ef87e35892 100644--- a/solr/modules/ltr/src/test/org/apache/solr/ltr/TestRerankBase.java+++ b/solr/modules/ltr/src/test/org/apache/solr/ltr/TestRerankBase.java@@ -136,7 +136,6 @@ public class TestRerankBase extends RestTestBase {throws Exception {tmpSolrHome = createTempDir();tmpConfDir = tmpSolrHome.resolve(CONF_DIR);- tmpConfDir.toFile().deleteOnExit();PathUtils.copyDirectory(TEST_PATH(), tmpSolrHome);final Path fstore = tmpConfDir.resolve(FEATURE_FILE_NAME);diff --git a/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3BackupRepositoryTest.java b/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3BackupRepositoryTest.javaindex 44ce79e6844..18e30d19438 100644--- a/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3BackupRepositoryTest.java+++ b/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3BackupRepositoryTest.java@@ -39,10 +39,9 @@ import org.apache.lucene.store.OutputStreamIndexOutput;import org.apache.solr.cloud.api.collections.AbstractBackupRepositoryTest;import org.apache.solr.common.util.NamedList;import org.apache.solr.core.backup.repository.BackupRepository;+import org.junit.Before;import org.junit.ClassRule;-import org.junit.Rule;import org.junit.Test;-import org.junit.rules.TemporaryFolder;import software.amazon.awssdk.core.sync.RequestBody;import software.amazon.awssdk.regions.Region;import software.amazon.awssdk.services.s3.S3Client;@@ -51,13 +50,20 @@ public class S3BackupRepositoryTest extends AbstractBackupRepositoryTest {private static final String BUCKET_NAME = S3BackupRepositoryTest.class.getSimpleName();- @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();+ public Path temporaryFolder;@SuppressWarnings("removal")@ClassRulepublic static final S3MockRule S3_MOCK_RULE =S3MockRule.builder().withInitialBuckets(BUCKET_NAME).withSecureConnection(false).build();+ @Before+ @Override+ public void setUp() throws Exception {+ super.setUp();+ temporaryFolder = createTempDir("junit");+ }+/*** Sent by {@link org.apache.solr.handler.ReplicationHandler}, ensure we don't choke on the bare* URI.@@ -176,7 +182,7 @@ public class S3BackupRepositoryTest extends AbstractBackupRepositoryTest {try (S3BackupRepository repo = getRepository()) {// A file on the local disk- Path tmp = temporaryFolder.newFolder().toPath();+ Path tmp = Files.createTempDirectory(temporaryFolder, "junit");try (OutputStream os = PathUtils.newOutputStream(tmp.resolve("from-file"), false);IndexOutput indexOutput = new OutputStreamIndexOutput("", "", os, content.length())) {byte[] bytes = content.getBytes(StandardCharsets.UTF_8);@@ -206,7 +212,7 @@ public class S3BackupRepositoryTest extends AbstractBackupRepositoryTest {try (S3BackupRepository repo = getRepository()) {// Local folder for destination- Path tmp = temporaryFolder.newFolder().toPath();+ Path tmp = Files.createTempDirectory(temporaryFolder, "junit");// Directly create a file on S3pushObject("from-file", content);@@ -336,7 +342,7 @@ public class S3BackupRepositoryTest extends AbstractBackupRepositoryTest {private Path pullObject(String path) throws IOException {try (S3Client s3 = S3_MOCK_RULE.createS3ClientV2()) {- Path file = temporaryFolder.newFile().toPath();+ Path file = Files.createTempFile(temporaryFolder, "junit", null);InputStream input = s3.getObject(b -> b.bucket(BUCKET_NAME).key(path));Files.copy(input, file, StandardCopyOption.REPLACE_EXISTING);return file;diff --git a/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3IndexInputTest.java b/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3IndexInputTest.javaindex 56d8c64cc06..d58ba8a4e64 100644--- a/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3IndexInputTest.java+++ b/solr/modules/s3-repository/src/test/org/apache/solr/s3/S3IndexInputTest.java@@ -25,14 +25,20 @@ import java.nio.charset.StandardCharsets;import java.nio.file.Files;import java.nio.file.Path;import org.apache.solr.SolrTestCaseJ4;-import org.junit.Rule;+import org.junit.Before;import org.junit.Test;-import org.junit.rules.TemporaryFolder;/** Test for reading files from S3 'the Solr way'. */public class S3IndexInputTest extends SolrTestCaseJ4 {- @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();+ public Path temporaryFolder;++ @Before+ @Override+ public void setUp() throws Exception {+ super.setUp();+ temporaryFolder = createTempDir("junit");+ }/** Simulates fetching a file from S3 in more than one read operation. */@Test@@ -62,7 +68,8 @@ public class S3IndexInputTest extends SolrTestCaseJ4 {private void doTestPartialRead(boolean directBuffer, String content, int slice)throws IOException {- Path tmp = temporaryFolder.newFolder().toPath();+ Path tmp = Files.createTempDirectory(temporaryFolder, "junit");+Path file = tmp.resolve("content");Files.writeString(file, content, StandardCharsets.UTF_8);