Github user rwm commented on the issue:

    https://github.com/apache/jena/pull/133
  
    I would strongly vote for adding the AutoCloseable interface, at least for 
StmtIterator. The sole purpose of AutoCloseable is to allow developers to use 
the `try-with-resources` statement and it does not cause any side effects. When 
it was introduced to Java, the interface was added to all objects with a 
`close()` method.
    
    The javadoc for AutoCloseable says:
    
    > An object that may hold resources (such as file or socket handles) until 
it is closed. The close() method of an AutoCloseable object is called 
automatically when exiting a try-with-resources block for which the object has 
been declared in the resource specification header. This construction ensures 
prompt release, avoiding resource exhaustion exceptions and errors that may 
otherwise occur.
    >API Note:
    >    It is possible, and in fact common, for a base class to implement 
AutoCloseable even though not all of its subclasses or instances will hold 
releasable resources. For code that must operate in complete generality, or 
when it is known that the AutoCloseable instance requires resource release, it 
is recommended to use try-with-resources constructions. However, when using 
facilities such as Stream that support both I/O-based and non-I/O-based forms, 
try-with-resources blocks are in general unnecessary when using non-I/O-based 
forms.
    
    
    @afs do you have a list of the generated warnings and maybe could attach 
them in a file so we can review them?
    
    In my experience, the warnings are mostly useful hints about missing close 
statements. You can disable them via `@SuppressWarnings("resource")` or by 
compiling with `-source 7`.
    
    See the following example:
    ```
        private class C implements AutoCloseable{
                @Override
                public void close() {
                }
        }
        public void a(){
                C c = new C();
                // warning! never closed
                Objects.requireNonNull(c);
        }
        public void b(){
                C c = new C();
                Objects.requireNonNull(c);
                c.close();
                // no warning, the instance is closed
        }
        public C c(){
                C c = new C();
                Objects.requireNonNull(c);
                // no warning, the instance is returned
                return c;
        }
        public void d(){
                C c = new C();
                if( new Random().nextFloat() < 0.2 ){
                        // warning! not closed at this location
                        return;
                }
                c.close();
        }
    ```
    
    The AutoCloseable interface should be used on any class with a `close()` 
method, which may need to be called. Otherwise developers are forced to use 
Java 6 code with manual exception handling for resource.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to