...
This noncompliant code example uses a ReentrantLock
to protect a java.util.Date
instance – recall that java.util.Date
is thread-_un_safe by design. The doSomethingSafely()
method must catch Throwable
to comply with rule ERR06 ERR01-J. Do not allow exceptions to expose sensitive information.
Code Block | ||
---|---|---|
| ||
final class DateHandler { private final Date date = new Date(); final Lock lock = new ReentrantLock(); public void doSomethingSafely(String str) { try { doSomething(str); } catch(Throwable t) { // Forward to handler } } public void doSomething(String str) { lock.lock(); String dateString = date.toString(); if (str.equals(dateString)) { // ... } lock.unlock(); } } |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="ee17f93863b48798-f0fcd9c1-40cb48f2-83cf9d1e-785fe2750cd6b26a6ab2f8fd"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. Bibliography#API 06]] | Class | ]]></ac:plain-text-body></ac:structured-macro> |
...