2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-09-16 17:42:50 +03:00
include::../jvm-description.adoc[]
2020-12-21 15:38:52 +01:00
2021-02-02 15:02:10 +01:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2020-12-21 15:38:52 +01:00
2022-02-04 17:28:24 +01:00
[source,java]
2020-12-21 15:38:52 +01:00
----
public void doSomething(File file, Lock lock) {
file.delete(); // Noncompliant
// ...
lock.tryLock(); // Noncompliant
}
----
2023-05-03 11:06:20 +02:00
=== Compliant solution
2020-12-21 15:38:52 +01:00
2022-02-04 17:28:24 +01:00
[source,java]
2020-12-21 15:38:52 +01:00
----
public void doSomething(File file, Lock lock) {
if (!lock.tryLock()) {
// lock failed; take appropriate action
}
if (!file.delete()) {
// file delete failed; take appropriate action
}
}
----
2023-05-03 11:06:20 +02:00
== Resources
2020-12-21 15:38:52 +01:00
* https://wiki.sei.cmu.edu/confluence/x/xzdGBQ[CERT, EXP00-J.] - Do not ignore values returned by methods
* https://wiki.sei.cmu.edu/confluence/x/TTZGBQ[CERT, FIO02-J.] - Detect and handle file-related errors
2024-01-15 17:15:56 +01:00
* CWE - https://cwe.mitre.org/data/definitions/754[CWE-754 - Improper Check for Unusual Exceptional Conditions]
2021-06-02 20:44:38 +02:00
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== on 1 Dec 2014, 10:13:50 Freddy Mallet wrote:
Hi @Ann, I let you specify this one and would only track call to File.delete() for the time being. Thanks
=== on 11 May 2016, 18:22:00 Michael Gumowski wrote:
Updated to add case of ``++Lock.tryLock()++``.
=== on 18 Aug 2016, 14:37:57 Ann Campbell wrote:
``++File.mkdirs++`` excluded because Javadoc says: "true if and only if the directory was created, along with all necessary parent directories; false otherwise." Meaning that it will return ``++true++`` if it had to create the dir and ``++false++`` if the dir already existed. Either way, I have my dir.
include::../comments-and-links.adoc[]
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]