try (SearchCursor searchResults = search( …);) {
.....
}
:)))
On Thu, 14 Jul 2022 at 02:11, Shawn McKinney <[email protected]> wrote:
>
> Hello,
>
> Recently noticed the fortress code is not closing the search cursor. Take the
> GroupDAO.find[1] example (listed below).
>
> Same pattern across the codebase despite clear warnings in the doc:
>
> "Don’t forget to close the cursor, otherwise the associated data remains in
> memory forever (causing a memory leak)! Best practice is to use
> try-with-resources statement.” [2]
>
> Obviously, we don’t want to be leaking. What’s the recommendation here,
> should I change the code?
>
>
> GroupDAO.find
>
> ```java
> List<Group> find( Group group ) throws FinderException
> {
> ...
> SearchCursor searchResults;
> try
> {
> ...
> searchResults = search( …);
>
> while ( searchResults.next() )
> {
> groupList.add( unloadLdapEntry( searchResults.getEntry(), sequence++ ) );
> }
>
> …
>
> catch ( CursorException e )
> {
> // no cursor close here
> }
> catch ( LdapException e )
> {
> // or here
> }
> finally
> {
> closeAdminConnection( ld );
> // and worse? Not here either
> }
>
> return groupList;
> }
> ```
>
> —
> Shawn
>
> [1](https://github.com/apache/directory-fortress-core/blob/master/src/main/java/org/apache/directory/fortress/core/impl/GroupDAO.java)
>
> [2](https://directory.apache.org/api/user-guide/2.3-searching.html)
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
--
Best regards,
Maxim
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]