openrewrite / openrewrite/rewrite
Issue discovered on `src/test/resources/dataflow-functional-tests/ArchiveAnalyzer.java` with `Use Files#createTempDirectory`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 570
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
Problem
The recipe org.openrewrite.java.security.UseFilesCreateTempDirectory made a change that deletes a bunch of code that may or may not be needed.
Expected behavior
I expected the recipe to only make the required set of changes. The result I got changes the underlying behavior.
Example diff
From: src/test/resources/dataflow-functional-tests/ArchiveAnalyzer.java
import javax.annotation.concurrent.ThreadSafe;
import java.io.*;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
public void prepareFileTypeAnalyzer(Engine engine) throws InitializationException {
try {
final File baseDir = getSettings().getTempDirectory();
- tempFileLocation = File.createTempFile("check", "tmp", baseDir);
- if (!tempFileLocation.delete()) {
- setEnabled(false);
- final String msg = String.format("Unable to delete temporary file '%s'.", tempFileLocation.getAbsolutePath());
- throw new InitializationException(msg);
- }
- if (!tempFileLocation.mkdirs()) {
- setEnabled(false);
- final String msg = String.format("Unable to create directory '%s'.", tempFileLocation.getAbsolutePath());
- throw new InitializationException(msg);
- }
+ tempFileLocation = Files.createTempDirectory(baseDir.toPath(), "check" + "tmp").toFile();
} catch (IOException ex) {
setEnabled(false);
throw new InitializationException("Unable to create a temporary file", ex);
Recipes in example diff:
org.openrewrite.java.security.UseFilesCreateTempDirectory
References:
- View original result
- Recipe ID:
org.openrewrite.java.security.UseFilesCreateTempDirectory - Recipe Name:
UseFiles#createTempDirectory`` - Repository:
openrewrite/rewrite-analysis/main - Created at Thu Aug 22 2024 09:49:22 GMT-0300 (Horário Padrão da Argentina)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the transformation produced by org.openrewrite.java.security.UseFilesCreateTempDirectory for src/test/resources/dataflow-functional-tests/ArchiveAnalyzer.java, using the linked original result as the comparison. Reproduce the example and inspect why the recipe replaces the deletion, enablement, and directory-creation checks. Done means the recipe makes only the required temporary-directory change without altering the surrounding behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100