Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: files closed properly, in accordance with FIO04-J

...

Code Block
bgColor#FFcccc
public final class Client {
  public void doSomething(File file) {
    final Lock lock = new ReentrantLock();
    InputStream in = null;
    try {
      lock.lock();
      InputStream in = new FileInputStream(file);
      // Perform operations on the open file
      lock.unlock();
    } catch (FileNotFoundException fnfx) {
      // Handle the exception
 exception
    } finally {
      if (in != null) {
       try {
          in.close();
        } catch (IOException x) {
          // Handle exception
        }  
      }
    }
  }
}

Note that the lock is still held, even when the doSomething() method returns.

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="0dc255237fa67f22-42755e9b-44554631-9677ade0-103a2af0ea5538b8527a8614"><ac:plain-text-body><![CDATA[

[[MITRE 2009

AA. Bibliography#MITRE 09]]

[CWE-883

http://cwe.mitre.org/data/definitions/883.html] "Deadlock"

]]></ac:plain-text-body></ac:structured-macro>

...

<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="8fd24b63b9dd0f53-23cda7e6-44724f3c-add88bb3-53dc0c6031bd559ef46c97f3"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

Class ReentrantLock

]]></ac:plain-text-body></ac:structured-macro>

...