title: How is in Java the idempotence of the close() method of the Closeable interface ensured?
body: <p>The <code>Closeable</code> interface was introduced in Java 5 whereas the <code>AutoCloseable</code> interface came in Java 7 together with the <code>try-with-resources</code> statement. <code>Closeable</code> extends (since Java 7) the <code>Autocloseable</code>interface.</p>
  
  <p>In the book <strong>OCA/OCP Java SE 7 - Programmer I &amp; II Study Guide</strong> it says on page 399:</p>
  
  <blockquote>
    <p>What happends if we call the <code>close()</code> multiple time? It depends. For classes that implement <code>AutoCloseable</code>, the implementation is required to be idempotent. Which means you can call <code>close()</code> all day and nothing will happen the second time and beyond. [...] For classes that implement <code>Closeable</code>, there is no such guarantee.</p>
  </blockquote>
  
  <p>So according to this text, implementations of <code>AutoCloseable</code> need to be idempotent, and those of <code>Closeable</code> not. Now when I have a look at the documentation of the <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/AutoCloseable.html" rel="noreferrer"><code>AutoCloseable</code> interface at docs.oracle.com</a>, it says:</p>
  
  <blockquote>
    <p>Note that unlike the <code>close</code> method of <code>Closeable</code>, this close method is not required to be idempotent. In other words, calling this <code>close</code> method more than once may have some visible side effect, unlike <code>Closeable.close</code> which is required to have no effect if called more than once.</p>
  </blockquote>
  
  <p>Now this is the opposite of what is written in the book. I have two questions:</p>
  
  <p>(1) What is correct? The doc at docs.oracle.com or the book? Which of the two interfaces requires idempotence?</p>
  
  <p>(2) No matter which one needs to be idempotent - am I right that Java has actually no way at all to ensure that it is idempotent? If so, the "requirement" of the <code>close</code> method to be idempotent is something that the programmer <strong>should</strong> do, but I can never be sure that someone who used the interface actually did do it, right? In this case the idempotence is merely a suggestion of oracle, correct?</p>