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="2e53bd265d355aaa-37f3b697-4da7453d-b4a0a098-cad8029de5de37cb12a3b90f"><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="6ff92ab7163aa09b-a5081c92-49484a51-9566b473-f0264deb287721388b6b5808"><ac:plain-text-body><![CDATA[

[[API 2006

AA. Bibliography#API 06]]

Class ReentrantLock

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

...