95 lines
1.7 KiB
Plaintext
95 lines
1.7 KiB
Plaintext
include::../common/rationale.adoc[]
|
|
|
|
== Why is this an issue?
|
|
|
|
include::../common/description.adoc[]
|
|
|
|
=== What is the potential impact?
|
|
|
|
include::../common/impact.adoc[]
|
|
|
|
== How to fix it
|
|
|
|
=== Code examples
|
|
|
|
include::../common/fix/code-rationale.adoc[]
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,java,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
|
|
protected void Example() throws IOException {
|
|
File tempDir;
|
|
tempDir = File.createTempFile("", ".");
|
|
tempDir.delete();
|
|
tempDir.mkdir(); // Noncompliant
|
|
}
|
|
----
|
|
|
|
|
|
==== Compliant solution
|
|
|
|
[source,java,diff-id=1,diff-type=compliant]
|
|
----
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
|
|
protected void Example() throws IOException {
|
|
Path tempPath = Files.createTempDirectory("");
|
|
File tempDir = tempPath.toFile();
|
|
}
|
|
----
|
|
|
|
=== How does this work?
|
|
|
|
include::../common/fix/introduction.adoc[]
|
|
|
|
include::../common/fix/secure-api.adoc[]
|
|
|
|
Here, the example compliant code uses the safer `Files.createTempDirectory`
|
|
function to manage the creation of temporary directories.
|
|
|
|
include::../common/fix/manual-setup.adoc[]
|
|
|
|
//=== Pitfalls
|
|
|
|
//=== Going the extra mile
|
|
|
|
|
|
== Resources
|
|
|
|
include::../common/resources/documentation.adoc[]
|
|
|
|
//=== Articles & blog posts
|
|
//=== Conference presentations
|
|
|
|
include::../common/resources/standards.adoc[]
|
|
|
|
//=== Benchmarks
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Use "Files.createTempDirectory" to create this directory instead.
|
|
|
|
=== Highlighting
|
|
|
|
"mkdir" method call
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|