[ 
https://issues.apache.org/jira/browse/IGNITE-18049?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17636653#comment-17636653
 ] 

Roman Puchkovskiy commented on IGNITE-18049:
--------------------------------------------

Thanks!

> Cursor#close() should not declare any exceptions in throws clause
> -----------------------------------------------------------------
>
>                 Key: IGNITE-18049
>                 URL: https://issues.apache.org/jira/browse/IGNITE-18049
>             Project: Ignite
>          Issue Type: Improvement
>            Reporter: Roman Puchkovskiy
>            Assignee: Roman Puchkovskiy
>            Priority: Major
>              Labels: ignite-3, tech-debt
>             Fix For: 3.0.0-beta2
>
>          Time Spent: 1h
>  Remaining Estimate: 0h
>
> When an {{AutoCloseable}} subinterface/implementation declares {{throws 
> Exception}} in its {{close()}} method, it makes it very inconvenient to work 
> with such a type using try-with-resources because the using code must use 
> something like {{catch (Exception e)}} which makes it difficult to process 
> exceptions that might arise in the {{try}} block.
> The suggestion is to make {{Cursor#close()}} not declare any checked 
> exceptions. Most of the current implementations of {{Cursor}} already obey to 
> this restriction, and a few that don't can be easily reworked to obey.
> The only problem is adapters (when we adapt an {{Iterator}} producing a 
> {{{}Cursor{}}}). Here, we must be prepared to get an {{Iterator}} that is a 
> resource itself (is an {{{}AutoCloseable{}}}) and hence needs to be closed 
> when the cursor is closed. But {{AutoCloseable#close()}} might throw a 
> checked exception. It is unacceptable to swallow it, and it is not too good 
> to just automatically wrap it in an unchecked exception.
>  # The best thing is that developers (who know their resources) write their 
> own custom {{Cursor}} implementations handling the closure.
>  # We also need a way to adapt 'safe close' iterators (obtained from 
> in-memory collections, for example). We should add a method like 
> {{Cursor#fromPurIterator(Iterator)}} that will check (at the moment of 
> invocation that the provided iterator is NOT an AutoCloseable and will throw 
> if it is)
>  # We can also provide a generic way to adapt a closeable iterator with a 
> method like {{<IT extends Iterator<T> & AutoCloseable> 
> Cursor#fromCloseableIterator(IT iterator)}} adding a Javadoc urging the user 
> to use this method only when absolutely necessary
>  # We probably should not add an omnivorous method that could adapt both pure 
> and closeable iterators for now to prevent abuses.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to