Skip to content

SOLR-16903: Make java.io.File a forbidden API #3321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

mlbiscoc
Copy link
Contributor

https://issues.apache.org/jira/browse/SOLR-16903

Description

Add java.io.File as a default forbidden API

Solution

Remove all usages of File, either toFile() or old classes

Tests

Updated tests using File

Checklist

Please review the following and check all that apply:

  • I have reviewed the guidelines for How to Contribute and my code conforms to the standards described there to the best of my ability.
  • I have created a Jira issue and added the issue ID to my pull request title.
  • I have given Solr maintainers access to contribute to my PR branch. (optional but recommended, not available for branches on forks living under an organisation)
  • I have developed this patch against the main branch.
  • I have run ./gradlew check.
  • I have added tests for my changes.
  • I have added documentation for the Reference Guide

Copy link
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!
I see you also got in some needless getAbsolutePath removals as well.

tmpConfigDir.toFile().deleteOnExit();
PathUtils.deleteOnExit(tmpConfigDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createTempDir self cleans up per test. It's javadocs say so.

@@ -1565,7 +1565,7 @@ public void testDeleteErrors() throws Exception {
final SolrClient solrClient = getHttpSolrClient(baseUrl);
final Path configDir = getFile("solr").resolve("configsets/configset-2/conf");
final Path tmpConfigDir = createTempDir();
tmpConfigDir.toFile().deleteOnExit();
PathUtils.deleteOnExit(tmpConfigDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createTempDir self cleans up per test. It's javadocs say so.

@@ -205,7 +205,7 @@ private void setupBaseConfigSet(String baseConfigSetName, Map<String, String> ol
throws Exception {
final Path configDir = getFile("solr").resolve("configsets/configset-2/conf");
final Path tmpConfigDir = createTempDir();
tmpConfigDir.toFile().deleteOnExit();
PathUtils.deleteOnExit(tmpConfigDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createTempDir self cleans up per test. It's javadocs say so.

@@ -105,8 +106,7 @@ public static void beforeClass() throws Exception {
wrongPemFilePath = JWT_TEST_PATH().resolve("security").resolve("jwt_plugin_idp_wrongcert.pem");

Path tempDir = Files.createTempDirectory(JWTAuthPluginIntegrationTest.class.getSimpleName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we call createTempDir instead?

@@ -60,9 +60,8 @@ protected static void setupTest(
protected static void initFolders(boolean isPersistent) throws Exception {
tmpSolrHome = createTempDir();
tmpConfDir = tmpSolrHome.resolve(CONF_DIR);
tmpConfDir.toFile().deleteOnExit();
PathUtils.deleteOnExit(tmpConfDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createTempDir self cleans up per test. It's javadocs say so.

@@ -136,7 +136,7 @@ protected static void setupTestInit(String solrconfig, String schema, boolean is
throws Exception {
tmpSolrHome = createTempDir();
tmpConfDir = tmpSolrHome.resolve(CONF_DIR);
tmpConfDir.toFile().deleteOnExit();
PathUtils.deleteOnExit(tmpConfDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createTempDir self cleans up per test. It's javadocs say so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this suite, can we just use createTempDir?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@mlbiscoc
Copy link
Contributor Author

Moved to createTempDir. Also think moving to createTempDir fixed that error that bubbled up from the previous precommit run.

Copy link
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I think this closes out SOLR-16903. Looking in CHANGES.txt, there are 2 mentions. The first is:

* SOLR-16903: Update CLI tools and Solr Core to use java.nio.file.Path instead of java.io.File (Andrey Bozhko, Matthew Biscocho)

I propose updating this one to simply be "Replace all java.io.File usages to java.nio.file.Path (NIO)" listing you & @AndreyBozhko

I also see:

* SOLR-17548: Switch all public Java APIs from File to Path. (Matthew Biscocho via Eric Pugh)

which is implied by the total switch from File -> Path. At least move this to be adjacent but you could also simply combine to the same bullet, listing both JIRAs (this happens sometimes).

Thanks to you both!

@mlbiscoc
Copy link
Contributor Author

JWTAuthPluginIntegrationTest > classMethod FAILED
    java.nio.file.ProviderMismatchException: mismatch, expected: FilterPath, got: class sun.nio.fs.UnixPath

Looks like we might be running into that filterPath issue I ran into previously. Also looks like there is precommit issues I am not seeing locally.... I'll need to fix this before merging. Will update the CHANGES.txt combining the change log and list @AndreyBozhko

Path tempDir = Files.createTempDirectory(JWTAuthPluginIntegrationTest.class.getSimpleName());
tempDir.toFile().deleteOnExit();

Path tempDir = createTempDir(JWTAuthPluginIntegrationTest.class.getSimpleName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createTempDir already incorporates the test class name

Comment on lines -108 to 109
tempDir.toFile().deleteOnExit();

Path tempDir = FilterPath.unwrap(createTempDir());
Path modifiedP12Cert = tempDir.resolve(p12Cert.getFileName());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to unwrap to resolve the path

Comment on lines -159 to -160
* SOLR-17548: Switch all public Java APIs from File to Path. (Matthew Biscocho via Eric Pugh)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to just remove this because its implied from the change above anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants