Skip to content
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

Introduce FilesCreateTempFileToFile Refaster rule #1162

Merged
merged 4 commits into from
Aug 7, 2024

Conversation

Stephan202
Copy link
Member

@Stephan202 Stephan202 commented Apr 30, 2024

Suggested commit message:

Introduce `FilesCreateTempFileToFile` Refaster rule (#1162)

Inspired by apache/maven-install-plugin#47, found through #1159.

@Stephan202 Stephan202 added this to the 0.17.0 milestone Apr 30, 2024
@Stephan202 Stephan202 force-pushed the sschroevers/create-temp-file-rules branch from 879ba3a to 25204a9 Compare April 30, 2024 04:28
@Stephan202 Stephan202 changed the title Introduce temporary file creation Refaster rules Introduce FilesCreateTempFileToFile Refaster rule Apr 30, 2024
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

2 similar comments
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarCloud


@AfterTemplate
File after(String prefix, String suffix) throws IOException {
return Files.createTempFile(prefix, suffix).toFile();
Copy link
Member Author

@Stephan202 Stephan202 Apr 30, 2024

Choose a reason for hiding this comment

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

SonarCloud now compains about this line, while the documentation literally says:

File f = Files.createTempFile("prefix", "suffix").toFile();  // Compliant

I suppose this is something to be reported upstream (either it's incorrect, or unclear).

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, I had a look, and for POSIX file systems at least this is safe: (a), (b). I tested this on my Linux laptop: the suggested code produces a file with -rw------- permissions, while the other two variants create a file with -rw-rw-r-- permissions.

The question is then what happens on Windows, but regardless this change is an improvement. I've added a comment to this effect, and suggest that this PR is good to go.

Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah left a comment

Choose a reason for hiding this comment

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

Clean 🚀

@Stephan202 Stephan202 modified the milestones: 0.17.0, 0.18.0 Jul 20, 2024
@Stephan202 Stephan202 force-pushed the sschroevers/create-temp-file-rules branch from 03ec072 to 8f08ea5 Compare August 4, 2024 10:58
Copy link

github-actions bot commented Aug 4, 2024

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link

github-actions bot commented Aug 4, 2024

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie force-pushed the sschroevers/create-temp-file-rules branch from ac67277 to 4c34d51 Compare August 7, 2024 13:20
Copy link

sonarqubecloud bot commented Aug 7, 2024

Copy link

github-actions bot commented Aug 7, 2024

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie merged commit a433a90 into master Aug 7, 2024
15 checks passed
@rickie rickie deleted the sschroevers/create-temp-file-rules branch August 7, 2024 13:41
@timtebeek
Copy link
Contributor

Inspired by apache/maven-install-plugin#47, found through #1159.

Fun to see that link here; Leitschuh has been using Moderne to roll that out broadly indeed. I did notice that we support both a 2 and 3 arg variant, whereas this only support the two arg option without additional directory argument. Could be worth adding that 3 arg variant here too, such that we can drop our recipe and just use this one. ;)

@Stephan202
Copy link
Member Author

Good one! I think I can open a PR for that shortly.

@Stephan202
Copy link
Member Author

Filed #1282 :)

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

Successfully merging this pull request may close these issues.

4 participants