mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
25.26.2016 9a300db9864e8da7187930315a9784369ace9c74
AutoRefactor'ed use try-with-resources
19 files modified
703 ■■■■■ changed files
opendj-config/src/main/java/org/forgerock/opendj/config/ManagedObjectDefinitionResource.java 10 ●●●● patch | view | raw | blame | history
opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/BuildVersion.java 7 ●●●● patch | view | raw | blame | history
opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/DSConfig.java 36 ●●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldif/ConnectionEntryReaderTestCase.java 65 ●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFChangeRecordReaderTestCase.java 144 ●●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFChangeRecordWriterTestCase.java 26 ●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFEntryReaderTestCase.java 61 ●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFEntryWriterTestCase.java 11 ●●●● patch | view | raw | blame | history
opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFTestCase.java 66 ●●●● patch | view | raw | blame | history
opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/DefaultTCPNIOTransportTestCase.java 4 ●●● patch | view | raw | blame | history
opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactoryTestCase.java 29 ●●●● patch | view | raw | blame | history
opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionTestCase.java 4 ●●● patch | view | raw | blame | history
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFModify.java 18 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/forgerock/opendj/adapter/server3x/Converters.java 76 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/TrustStoreBackend.java 8 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/IndexQueryFactoryImpl.java 102 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/PersistentCompressedSchema.java 21 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/server/changelog/file/ReplicationEnvironmentTest.java 5 ●●●● patch | view | raw | blame | history
opendj-server/src/main/java/org/forgerock/opendj/server/core/ProductInformation.java 10 ●●●● patch | view | raw | blame | history
opendj-config/src/main/java/org/forgerock/opendj/config/ManagedObjectDefinitionResource.java
@@ -12,13 +12,10 @@
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2008 Sun Microsystems, Inc.
 * Portions copyright 2014-2015 ForgeRock AS.
 * Portions copyright 2014-2016 ForgeRock AS.
 */
package org.forgerock.opendj.config;
import static org.forgerock.util.Utils.closeSilently;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -107,15 +104,12 @@
                throw new MissingResourceException("Can't find resource " + path, baseName, "");
            }
            final InputStream is = new BufferedInputStream(stream);
            p = new Properties();
            try {
            try (InputStream is = new BufferedInputStream(stream)) {
                p.load(is);
            } catch (IOException e) {
                throw new MissingResourceException("Can't load resource " + path
                        + " due to IO exception: " + e.getMessage(), baseName, "");
            } finally {
                closeSilently(is);
            }
            // Cache the resource.
opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/BuildVersion.java
@@ -18,7 +18,6 @@
import static com.forgerock.opendj.ldap.config.ConfigMessages.*;
import static com.forgerock.opendj.util.StaticUtils.stackTraceToSingleLineString;
import static org.forgerock.util.Utils.closeSilently;
import java.io.BufferedReader;
import java.io.File;
@@ -109,9 +108,7 @@
    public static BuildVersion instanceVersion() throws ConfigException {
        final String buildInfo = ConfigurationFramework.getInstance().getInstancePath() + File.separator + "config"
                + File.separator + "buildinfo";
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(buildInfo));
        try (BufferedReader reader = new BufferedReader(new FileReader(buildInfo))) {
            final String s = reader.readLine();
            if (s != null) {
                return valueOf(s);
@@ -122,8 +119,6 @@
            throw new ConfigException(ERR_BUILDVERSION_NOT_FOUND.get(buildInfo));
        } catch (final IllegalArgumentException e) {
            throw new ConfigException(ERR_BUILDVERSION_MALFORMED.get(buildInfo));
        } finally {
            closeSilently(reader);
        }
    }
opendj-config/src/main/java/org/forgerock/opendj/config/dsconfig/DSConfig.java
@@ -27,11 +27,11 @@
import static org.forgerock.opendj.config.PropertyOption.*;
import static org.forgerock.opendj.config.dsconfig.ArgumentExceptionFactory.*;
import static org.forgerock.util.Utils.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
@@ -1345,10 +1345,7 @@
        }
        if (equivalentCommandFileArgument.isPresent()) {
            String file = equivalentCommandFileArgument.getValue();
            BufferedWriter writer = null;
            try {
                writer = new BufferedWriter(new FileWriter(file, true));
            try (BufferedWriter writer = new BufferedWriter(new FileWriter(file, true))) {
                if (!sessionStartTimePrinted) {
                    writer.write(SHELL_COMMENT_SEPARATOR + getSessionStartTimeMessage());
                    writer.newLine();
@@ -1372,8 +1369,6 @@
                writer.flush();
            } catch (IOException ioe) {
                errPrintln(ERR_DSCFG_ERROR_WRITING_EQUIVALENT_COMMAND_LINE.get(file, ioe));
            } finally {
                closeSilently(writer);
            }
        }
    }
@@ -1391,18 +1386,7 @@
    }
    private void handleBatch(String[] args) {
        BufferedReader bReader = null;
        try {
            if (batchArgument.isPresent()) {
                bReader = new BufferedReader(new InputStreamReader(System.in));
            } else if (batchFileArgument.isPresent()) {
                final String batchFilePath = batchFileArgument.getValue().trim();
                bReader = new BufferedReader(new FileReader(batchFilePath));
            } else {
                throw new IllegalArgumentException("Either --" + OPTION_LONG_BATCH
                    + " or --" + OPTION_LONG_BATCH_FILE_PATH + " argument should have been set");
            }
        try (BufferedReader bReader = batchCommandsReader()) {
            List<String> initialArgs = removeBatchArgs(args);
            // Split the CLI string into arguments array
@@ -1436,8 +1420,18 @@
            }
        } catch (IOException ex) {
            errPrintln(ERR_DSCFG_ERROR_READING_BATCH_FILE.get(ex));
        } finally {
            closeSilently(bReader);
        }
    }
    private BufferedReader batchCommandsReader() throws FileNotFoundException {
        if (batchArgument.isPresent()) {
            return new BufferedReader(new InputStreamReader(System.in));
        } else if (batchFileArgument.isPresent()) {
            final String batchFilePath = batchFileArgument.getValue().trim();
            return new BufferedReader(new FileReader(batchFilePath));
        } else {
            throw new IllegalArgumentException("Either --" + OPTION_LONG_BATCH
                + " or --" + OPTION_LONG_BATCH_FILE_PATH + " argument should have been set");
        }
    }
opendj-core/src/test/java/org/forgerock/opendj/ldif/ConnectionEntryReaderTestCase.java
@@ -59,60 +59,47 @@
    @Test
    public final void testHasNextWhenError() throws Exception {
        final ConnectionEntryReader reader = newReader(ERROR);
        try {
        try (ConnectionEntryReader reader = newReader(ERROR)) {
            reader.hasNext();
            fail();
        } catch (final LdapException e) {
            assertThat(e.getResult()).isSameAs(ERROR);
        } finally {
            reader.close();
        }
    }
    @Test
    public final void testReadEntry() throws Exception {
        final ConnectionEntryReader reader = newReader(ENTRY1, SUCCESS);
        try {
        try (ConnectionEntryReader reader = newReader(ENTRY1, SUCCESS)) {
            assertThat(reader.hasNext()).isTrue();
            assertThat(reader.isEntry()).isTrue();
            assertThat(reader.isReference()).isFalse();
            assertThat(reader.readEntry()).isSameAs(ENTRY1);
            assertThat(reader.hasNext()).isFalse();
            assertThat(reader.readResult()).isSameAs(SUCCESS);
        } finally {
            reader.close();
        }
    }
    @Test
    public final void testReadEntryWhenError() throws Exception {
        final ConnectionEntryReader reader = newReader(ERROR);
        try {
        try (ConnectionEntryReader reader = newReader(ERROR)) {
            reader.readEntry();
            fail();
        } catch (final LdapException e) {
            assertThat(e.getResult()).isSameAs(ERROR);
        } finally {
            reader.close();
        }
    }
    @Test(expectedExceptions = NoSuchElementException.class)
    public final void testReadEntryWhenNoMore() throws Exception {
        final ConnectionEntryReader reader = newReader(SUCCESS);
        try {
        try (ConnectionEntryReader reader = newReader(SUCCESS)) {
            assertThat(reader.hasNext()).isFalse();
            reader.readEntry();
        } finally {
            reader.close();
        }
    }
    @Test
    public final void testReadEntryWhenReference() throws Exception {
        final ConnectionEntryReader reader = newReader(REF, SUCCESS);
        try {
        try (ConnectionEntryReader reader = newReader(REF, SUCCESS)) {
            assertThat(reader.hasNext()).isTrue();
            try {
                reader.readEntry();
@@ -122,15 +109,12 @@
            }
            assertThat(reader.hasNext()).isFalse();
            assertThat(reader.readResult()).isSameAs(SUCCESS);
        } finally {
            reader.close();
        }
    }
    @Test
    public final void testReadMultipleResults() throws Exception {
        final ConnectionEntryReader reader = newReader(ENTRY1, ENTRY2, REF, ENTRY3, SUCCESS);
        try {
        try (ConnectionEntryReader reader = newReader(ENTRY1, ENTRY2, REF, ENTRY3, SUCCESS)) {
            assertThat(reader.hasNext()).isTrue();
            assertThat(reader.readEntry()).isSameAs(ENTRY1);
            assertThat(reader.hasNext()).isTrue();
@@ -141,94 +125,71 @@
            assertThat(reader.readEntry()).isSameAs(ENTRY3);
            assertThat(reader.hasNext()).isFalse();
            assertThat(reader.readResult()).isSameAs(SUCCESS);
        } finally {
            reader.close();
        }
    }
    @Test
    public final void testReadReference() throws Exception {
        final ConnectionEntryReader reader = newReader(REF, SUCCESS);
        try {
        try (ConnectionEntryReader reader = newReader(REF, SUCCESS)) {
            assertThat(reader.hasNext()).isTrue();
            assertThat(reader.isEntry()).isFalse();
            assertThat(reader.isReference()).isTrue();
            assertThat(reader.readReference()).isSameAs(REF);
            assertThat(reader.hasNext()).isFalse();
            assertThat(reader.readResult()).isSameAs(SUCCESS);
        } finally {
            reader.close();
        }
    }
    @Test
    public final void testReadReferenceWhenEntry() throws Exception {
        final ConnectionEntryReader reader = newReader(ENTRY1, SUCCESS);
        try {
        try (ConnectionEntryReader reader = newReader(ENTRY1, SUCCESS)) {
            assertThat(reader.hasNext()).isTrue();
            assertThat(reader.readReference()).isNull();
            assertThat(reader.readEntry()).isSameAs(ENTRY1);
            assertThat(reader.hasNext()).isFalse();
            assertThat(reader.readResult()).isSameAs(SUCCESS);
        } finally {
            reader.close();
        }
    }
    @Test
    public final void testReadReferenceWhenError() throws Exception {
        final ConnectionEntryReader reader = newReader(ERROR);
        try {
        try (ConnectionEntryReader reader = newReader(ERROR)) {
            reader.readReference();
            fail();
        } catch (final LdapException e) {
            assertThat(e.getResult()).isSameAs(ERROR);
        } finally {
            reader.close();
        }
    }
    @Test(expectedExceptions = NoSuchElementException.class)
    public final void testReadReferenceWhenNoMore() throws Exception {
        final ConnectionEntryReader reader = newReader(SUCCESS);
        try {
        try (ConnectionEntryReader reader = newReader(SUCCESS)) {
            assertThat(reader.hasNext()).isFalse();
            reader.readReference();
        } finally {
            reader.close();
        }
    }
    @Test
    public final void testReadResult() throws Exception {
        final ConnectionEntryReader reader = newReader(SUCCESS);
        try {
        try (ConnectionEntryReader reader = newReader(SUCCESS)) {
            assertThat(reader.readResult()).isSameAs(SUCCESS);
        } finally {
            reader.close();
        }
    }
    @Test
    public final void testReadResultWhenError() throws Exception {
        final ConnectionEntryReader reader = newReader(ERROR);
        try {
        try (ConnectionEntryReader reader = newReader(ERROR)) {
            reader.readResult();
            fail();
        } catch (final LdapException e) {
            assertThat(e.getResult()).isSameAs(ERROR);
        } finally {
            reader.close();
        }
    }
    @Test(expectedExceptions = IllegalStateException.class)
    public final void testReadResultWhenEntry() throws Exception {
        final ConnectionEntryReader reader = newReader(ENTRY1, SUCCESS);
        try {
        try (ConnectionEntryReader reader = newReader(ENTRY1, SUCCESS)) {
            reader.readResult();
        } finally {
            reader.close();
        }
    }
opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFChangeRecordReaderTestCase.java
@@ -542,17 +542,13 @@
     */
    @Test(expectedExceptions = DecodeException.class)
    public void testReadAddRecordWithEmptyPairKeyChangeType() throws Exception {
        // @formatter:off
        LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
            // @formatter:off
            "dn: dc=example,dc=com",
            ":add" // if empty spaces, ko.
        );
        // @formatter:on
        try {
            // @formatter:on
        )) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
@@ -564,19 +560,16 @@
     */
    @Test(expectedExceptions = DecodeException.class)
    public void testReadAddRecordWithWrongChangeType() throws Exception {
        // @formatter:off
        LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
            // @formatter:off
            "dn: dc=example,dc=com",
            "changetype: oops", // wrong
            "objectClass: top",
            "objectClass: domainComponent",
            "dc: example"
        );
        // @formatter:on
        try {
            // @formatter:on
        )) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
@@ -987,8 +980,8 @@
        final String url = file.toURI().toURL().toString();
        file.delete();
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
        // @formatter:off
        final  LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
            "version: 1",
            "# Add a new entry",
            "dn: cn=Fiona Jensen, ou=Marketing, dc=airius, dc=com",
@@ -1001,13 +994,9 @@
            "uid: fiona",
            "telephonenumber: +1 408 555 1212",
            "jpegphoto:< " + url
        );
        // @formatter:on
        try {
            // @formatter:on
        )) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
@@ -1521,21 +1510,17 @@
    @Test(expectedExceptions = DecodeException.class)
    public void testParseChangeRecordEntryRejectedWhenControlIsEmpty() throws Exception {
        // @formatter:off
        final  LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
                // @formatter:off
                "dn: ou=Product Development, dc=airius, dc=com",
                "control:",
                "changetype: add",
                "objectClass: top",
                "objectClass: organization",
                "o: testing"
        );
        // @formatter:on
        try {
                // @formatter:on
        )) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
@@ -2014,18 +1999,12 @@
     */
    @Test(expectedExceptions = DecodeException.class)
    public void testParseModifyDNChangeRecordEntryMalformedMissedNewRDN() throws Exception {
        // @formatter:off
        final LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
            "version: 1",
            "dn: cn=scarter,dc=example,dc=com",
            "changetype: modrdn"
        );
        // @formatter:on
        try {
        )) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
@@ -2037,20 +2016,16 @@
     */
    @Test(expectedExceptions = DecodeException.class)
    public void testParseModifyDNChangeRecordEntryKeyMalformedEmptyNewRDN() throws Exception {
        // @formatter:off
        final LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
            // @formatter:off
            "version: 1",
            "dn: cn=scarter,dc=example,dc=com",
            "changetype: modrdn",
            "newrdn:",
            "deleteoldrdn: 1"
        );
        // @formatter:on
        try {
            // @formatter:on
        )) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
@@ -2062,19 +2037,16 @@
     */
    @Test(expectedExceptions = DecodeException.class)
    public void testParseModifyDNChangeRecordEntryKeyValueMalformedRDN() throws Exception {
        // @formatter:off
        final LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
            // @formatter:off
            "version: 1",
            "dn: cn=scarter,dc=example,dc=com",
            "changetype: modrdn",
            "newrdn:oops", // wrong
            "deleteoldrdn: 1"
        );
        // @formatter:on
        try {
            // @formatter:on
        )) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
@@ -2086,20 +2058,16 @@
     */
    @Test(expectedExceptions = DecodeException.class)
    public void testParseModifyDNChangeRecordEntryKeyValueMalformedDeleteOldRDN() throws Exception {
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
        // @formatter:off
        final LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
            "version: 1",
            "dn: cn=scarter,dc=example,dc=com",
            "changetype: modrdn",
            "newrdn:cn=Susan Jacobs",
            "deleteoldrdn: cn=scarter,dc=example,dc=com" // wrong
        );
        // @formatter:on
        try {
            // @formatter:on
        )) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
@@ -2111,19 +2079,16 @@
     */
    @Test(expectedExceptions = DecodeException.class)
    public void testParseModifyDNChangeRecordEntryKeyValueMalformedDeleteOldRDN2() throws Exception {
        // @formatter:off
        final LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
              // @formatter:off
            "version: 1",
            "dn: cn=scarter,dc=example,dc=com",
            "changetype: modrdn",
            "newrdn:cn=Susan Jacobs",
            "deleteold: 1" // wrong
        );
        // @formatter:on
        try {
            // @formatter:on
        )) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
@@ -2134,20 +2099,16 @@
     */
    @Test(expectedExceptions = DecodeException.class)
    public void testParseModifyDNChangeRecordEntryKeyValueMalformedDeleteOldRDN3() throws Exception {
        // @formatter:off
        final LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
            // @formatter:off
            "version: 1",
            "dn: cn=scarter,dc=example,dc=com",
            "changetype: modrdn",
            "newrdn:cn=Susan Jacobs"
            // missing deleteoldrn: 1/0||true/false||yes/no
        );
        // @formatter:on
        try {
            // @formatter:on
        )) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
@@ -2220,19 +2181,16 @@
     */
    @Test(expectedExceptions = DecodeException.class)
    public void testParseModifyRecordEntryNewSuperiorMalformed() throws Exception {
        // @formatter:off
        LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
            // @formatter:off
            "dn: cn=scarter,ou=People,dc=example,dc=com",
            "changeType: modrdn",
            "newrdn: cn=Susan Jacobs",
            "deleteOldRdn: 1",
            "newSuperior:" // wrong
        );
        // @formatter:on
        try {
            // @formatter:on
        )) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
@@ -2244,20 +2202,16 @@
     */
    @Test(expectedExceptions = DecodeException.class)
    public void testParseModifyRecordEntryNewSuperiorMalformed2() throws Exception {
        // @formatter:off
        LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(
            // @formatter:off
            "dn: cn=scarter,ou=People,dc=example,dc=com",
            "changeType: modrdn",
            "newrdn: cn=Susan Jacobs",
            "deleteOldRdn: 1",
            "newSuperior: Susan Jacobs" // wrong
        );
        // @formatter:on
        try {
            // @formatter:on
        )) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
@@ -2331,11 +2285,8 @@
    @Test(expectedExceptions = NoSuchElementException.class)
    public void testChangeRecordReaderDoesntAllowNull() throws Exception {
        List<String> cr = Collections.emptyList();
        LDIFChangeRecordReader reader = new LDIFChangeRecordReader(cr);
        try {
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(cr)) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
@@ -2347,11 +2298,8 @@
     */
    @Test(expectedExceptions = NoSuchElementException.class)
    public void testChangeRecordReaderLDIFLineDoesntAllowNull() throws Exception {
        LDIFChangeRecordReader reader = new LDIFChangeRecordReader(new String());
        try {
        try (LDIFChangeRecordReader reader = new LDIFChangeRecordReader(new String())) {
            reader.readChangeRecord();
        } finally {
            reader.close();
        }
    }
opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFChangeRecordWriterTestCase.java
@@ -179,12 +179,8 @@
    @Test(expectedExceptions = NullPointerException.class)
    public void testSetExcludeAttributeDoesntAllowNull() throws Exception {
        final List<String> actual = new ArrayList<>();
        final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);
        try {
        try (LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual)) {
            writer.setExcludeAttribute(null);
        } finally {
            writer.close();
        }
    }
@@ -267,12 +263,8 @@
    @Test(expectedExceptions = NullPointerException.class)
    public void testSetExcludeBranchDoesntAllowNull() throws Exception {
        final List<String> actual = new ArrayList<>();
        final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);
        try {
        try (LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual)) {
            writer.setExcludeBranch(null);
        } finally {
            writer.close();
        }
    }
@@ -387,11 +379,8 @@
    @Test(expectedExceptions = NullPointerException.class)
    public void testSetIncludeAttributeDoesntAllowNull() throws Exception {
        final List<String> actual = new ArrayList<>();
        final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);
        try {
        try (LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual)) {
            writer.setIncludeAttribute(null);
        } finally {
            writer.close();
        }
    }
@@ -452,11 +441,8 @@
    @Test(expectedExceptions = NullPointerException.class)
    public void testSetIncludeBranchDoesntAllowNull() throws Exception {
        final List<String> actual = new ArrayList<>();
        final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);
        try {
        try (LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual)) {
            writer.setIncludeBranch(null);
        } finally {
            writer.close();
        }
    }
@@ -1356,14 +1342,12 @@
    @Test
    public void testWriteChangeRecordFlushClose() throws Exception {
        final OutputStream mockOutput = mock(OutputStream.class);
        final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(mockOutput);
        try {
        try (LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(mockOutput)) {
            writer.writeComment("TLDIFChangeRecordWriter, this is a comment.");
            writer.flush();
            writer.flush();
            verify(mockOutput, times(2)).flush();
        } finally {
            writer.close();
            verify(mockOutput, times(1)).close();
        }
    }
opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFEntryReaderTestCase.java
@@ -14,7 +14,6 @@
 * Copyright 2009-2010 Sun Microsystems, Inc.
 * Portions copyright 2012-2016 ForgeRock AS.
 */
package org.forgerock.opendj.ldif;
import static org.testng.Assert.assertNotNull;
@@ -49,9 +48,7 @@
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
/**
 * This class tests the LDIFEntryReader functionality.
 */
/** This class tests the LDIFEntryReader functionality. */
@SuppressWarnings("javadoc")
public final class LDIFEntryReaderTestCase extends AbstractLDIFTestCase {
    /**
@@ -93,9 +90,7 @@
        // @formatter:on
    }
    /**
     * Number of attributes of the standard entry.
     */
    /** Number of attributes of the standard entry. */
    public final int nbStandardEntryAttributes = new LinkedHashMapEntry(getStandardEntry())
            .getAttributeCount();
@@ -930,12 +925,9 @@
        } finally {
            reader.close();
        }
    }
    /**
     * Test to read an entry containing spaces before the attribute.
     */
    /** Test to read an entry containing spaces before the attribute. */
    @Test
    public void testReadEntryWithAttributesSpacesAtStart() throws Exception {
        // @formatter:off
@@ -1019,8 +1011,7 @@
    public void testReadEntry() throws Exception {
        final String path = TestCaseUtils.createTempFile(getStandardEntry());
        final FileInputStream in = new FileInputStream(path);
        final LDIFEntryReader reader = new LDIFEntryReader(in);
        try {
        try (LDIFEntryReader reader = new LDIFEntryReader(in)) {
            Assert.assertTrue(reader.hasNext());
            final Entry entry = reader.readEntry();
            assertNotNull(entry);
@@ -1028,8 +1019,6 @@
                    .valueOf("uid=user.0,ou=People,dc=example,dc=com"));
            Assert.assertFalse(reader.hasNext());
            reader.readEntry();
        } finally {
            reader.close();
        }
    }
@@ -1149,8 +1138,7 @@
        // @formatter:on
        final String path = TestCaseUtils.createTempFile(strEntry);
        final FileInputStream in = new FileInputStream(path);
        final LDIFEntryReader reader = new LDIFEntryReader(in);
        try {
        try (LDIFEntryReader reader = new LDIFEntryReader(in)) {
            assertThat(reader.hasNext());
            final Entry entry = reader.readEntry();
            assertThat(entry.getName().toString()).isEqualTo(
@@ -1161,8 +1149,6 @@
            assertThat(entry.getAttribute("ds-cfg-character-set")).isNotEmpty();
            assertThat(entry.getAttribute("ds-cfg-character-set").toArray().length).isEqualTo(4);
            assertThat(reader.hasNext()).isFalse();
        } finally {
            reader.close();
        }
    }
@@ -1258,13 +1244,9 @@
        };
        // @formatter:on
        final LDIFEntryReader reader = new LDIFEntryReader(strEntry);
        try {
        try (LDIFEntryReader reader = new LDIFEntryReader(strEntry)) {
            reader.readEntry();
        } finally {
            reader.close();
        }
    }
    /**
@@ -1316,9 +1298,8 @@
     */
    @Test(expectedExceptions = DecodeException.class)
    public void testValueOfLDIFEntryReadEntryContainingMalformedURL() throws Exception {
        // @formatter:off
        final LDIFEntryReader reader = new LDIFEntryReader(
        try (LDIFEntryReader reader = new LDIFEntryReader(
                // @formatter:off
                "version: 1",
                "dn:: b3U95Za25qWt6YOoLG89QWlyaXVz",
                "# dn:: ou=<JapaneseOU>,o=Airius",
@@ -1332,13 +1313,10 @@
                "telephonenumber: +1 408 555 1212",
                "jpegphoto:< invalidProtocol",
                " ",
                " ");
        // @formatter:on
        try {
                " "
                // @formatter:on
        )) {
            reader.readEntry();
        } finally {
            reader.close();
        }
    }
@@ -1361,11 +1339,8 @@
        // @formatter:on
        final FileInputStream in = new FileInputStream(path);
        final LDIFEntryReader reader = new LDIFEntryReader(in);
        try {
        try (LDIFEntryReader reader = new LDIFEntryReader(in)) {
            reader.readEntry();
        } finally {
            reader.close();
        }
    }
@@ -1376,9 +1351,8 @@
     */
    @Test(expectedExceptions = DecodeException.class)
    public void testReadEntryBase64EncodedMalformedBase64Attribute() throws Exception {
        // @formatter:off
        final LDIFEntryReader reader = new LDIFEntryReader(Arrays.asList(
        try (LDIFEntryReader reader = new LDIFEntryReader(Arrays.asList(
            // @formatter:off
            "version: 1",
            "dn: cn=Gern Jensen, ou=Product Testing, dc=airius, dc=com",
            "objectclass: top",
@@ -1393,12 +1367,9 @@
            + "IGlzIGJhc2UtNjQtZW5aaaaaaaaaaajb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdG"
            + "VyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQg"
            + "b3V0IG1vcmUu"
        ));
        // @formatter:on
        try {
            // @formatter:off
        ))) {
            reader.readEntry();
        } finally {
            reader.close();
        }
    }
opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFEntryWriterTestCase.java
@@ -12,7 +12,7 @@
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2009-2010 Sun Microsystems, Inc.
 * Portions copyright 2012-2015 ForgeRock AS.
 * Portions copyright 2012-2016 ForgeRock AS.
 */
package org.forgerock.opendj.ldif;
@@ -777,12 +777,9 @@
        doThrow(new IOException()).when(mockOutput).write(any(byte[].class));
        doThrow(new IOException()).when(mockOutput).write(any(byte[].class), anyInt(), anyInt());
        LDIFEntryWriter writer = new LDIFEntryWriter(mockOutput);
        try {
        try (LDIFEntryWriter writer = new LDIFEntryWriter(mockOutput)) {
            CharSequence comment = "This is a new comment";
            writer.writeComment(comment);
        } finally {
            writer.close();
        }
    }
@@ -795,13 +792,11 @@
    @Test
    public void testWriteEntryUsingMockOutputForFlushAndClose() throws Exception {
        OutputStream mockOutput = mock(OutputStream.class);
        LDIFEntryWriter writer = new LDIFEntryWriter(mockOutput);
        try {
        try (LDIFEntryWriter writer = new LDIFEntryWriter(mockOutput)) {
            writer.flush();
            writer.flush();
            verify(mockOutput, times(2)).flush();
        } finally {
            writer.close();
            verify(mockOutput, times(1)).close();
        }
    }
opendj-core/src/test/java/org/forgerock/opendj/ldif/LDIFTestCase.java
@@ -162,11 +162,8 @@
    @Test(expectedExceptions = NullPointerException.class)
    public final void testLdifSearchDoesntAllowNullSearchRequest() throws Exception {
        final EntryReader reader = new LDIFEntryReader(getStandardEntry());
        try {
        try (EntryReader reader = new LDIFEntryReader(getStandardEntry())) {
            LDIF.search(reader, null);
        } finally {
            reader.close();
        }
    }
@@ -743,7 +740,7 @@
            "changetype: delete"
        );
        // @formatter:on
        final java.util.List<String> actual = new ArrayList<>();
        final List<String> actual = new ArrayList<>();
        final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);
        try {
@@ -795,7 +792,7 @@
     */
    @Test(expectedExceptions = NullPointerException.class)
    public final void testLdifCopyToChangeRecordDoesntAllowNullReader() throws Exception {
        final java.util.List<String> actual = new ArrayList<>();
        final List<String> actual = new ArrayList<>();
        final LDIFChangeRecordWriter writer = new LDIFChangeRecordWriter(actual);
        LDIF.copyTo(null, writer);
@@ -2431,12 +2428,8 @@
                "manager: uid=joneill,ou=People,dc=example,dc=com"
        );
        // @formatter:on
        EntryReader reader = new LDIFEntryReader();
        try {
            reader = LDIF.patch(input, patch);
        try (EntryReader reader = LDIF.patch(input, patch)) {
            reader.readEntry();
        } finally {
            reader.close();
        }
    }
@@ -2468,11 +2461,8 @@
            "work-phone: 650/506-7000"
        );
        // @formatter:on
        EntryReader reader = new LDIFEntryReader();
        try {
            reader = LDIF.patch(input, patch, listener);
        } finally {
            reader.close();
        try (EntryReader reader = LDIF.patch(input, patch, listener)) {
            // should throw
        }
    }
@@ -2504,22 +2494,17 @@
            "work-phone: 650/506-7000"
        );
        // @formatter:on
        EntryReader reader = new LDIFEntryReader();
        try {
            reader = LDIF.patch(input, patch, listener);
        try (EntryReader reader = LDIF.patch(input, patch, listener)) {
            Entry entry = reader.readEntry();
            assertThat(entry.getName().toString()).isEqualTo("uid=scarter,ou=People,dc=example,dc=com");
            assertThat(entry.getAttributeCount()).isEqualTo(3);
            assertThat(entry.getAttribute("objectClass").firstValueAsString()).isEqualTo(
                    "person");
            assertThat(entry.getAttribute("objectClass").firstValueAsString()).isEqualTo("person");
            assertThat(entry.getAttribute("sn").firstValueAsString()).isEqualTo(
                    "new user");
            assertThat(entry.getAttribute("mail").firstValueAsString()).isEqualTo(
                    "mail@mailme.org");
            assertThat(reader.hasNext()).isFalse();
            assertThat(entry.getAttribute("work-phone")).isNull();
        } finally {
            reader.close();
        }
    }
@@ -2550,11 +2535,8 @@
            "deleteoldrdn: 1"
        );
        // @formatter:on
        EntryReader reader = new LDIFEntryReader();
        try {
            reader = LDIF.patch(input, patch, listener);
        } finally {
            reader.close();
        try (EntryReader reader = LDIF.patch(input, patch, listener)) {
            // should throw
        }
    }
@@ -2586,9 +2568,7 @@
            "deleteoldrdn: 1"
        );
        // @formatter:on
        EntryReader reader = new LDIFEntryReader();
        try {
            reader = LDIF.patch(input, patch, listener);
        try (EntryReader reader = LDIF.patch(input, patch, listener)) {
            Entry entry = reader.readEntry();
            assertThat(entry.getName().toString()).isEqualTo("uid=scarter,ou=People,dc=example,dc=com");
            assertThat(entry.getName().toString()).isNotEqualTo("uid=scarter,ou=Human Resources,dc=example,dc=com");
@@ -2600,8 +2580,6 @@
            assertThat(entry.getAttribute("mail").firstValueAsString()).isEqualTo(
                    "mail@mailme.org");
            assertThat(reader.hasNext()).isFalse();
        } finally {
            reader.close();
        }
    }
@@ -2642,11 +2620,8 @@
            "deleteoldrdn: 0"
        );
        // @formatter:on
        EntryReader reader = new LDIFEntryReader();
        try {
            reader = LDIF.patch(input, patch, listener);
        } finally {
            reader.close();
        try (EntryReader reader = LDIF.patch(input, patch, listener)) {
            // should throw
        }
    }
@@ -2688,21 +2663,14 @@
            "deleteoldrdn: 0"
        );
        // @formatter:on
        EntryReader reader = new LDIFEntryReader();
        try {
            reader = LDIF.patch(input, patch, listener);
        try (EntryReader reader = LDIF.patch(input, patch, listener)) {
            Entry entry = reader.readEntry();
            assertThat(entry.getName().toString()).isEqualTo("uid=user.2,ou=People,dc=example,dc=com");
            assertThat(entry.getAttributeCount()).isEqualTo(4);
            assertThat(entry.getAttribute("objectClass").firstValueAsString()).isEqualTo(
                    "person");
            assertThat(entry.getAttribute("sn").firstValueAsString()).isEqualTo(
                    "new user");
            assertThat(entry.getAttribute("mail").firstValueAsString()).isEqualTo(
                    "mail@mailme.org");
            assertThat(entry.getAttribute("objectClass").firstValueAsString()).isEqualTo("person");
            assertThat(entry.getAttribute("sn").firstValueAsString()).isEqualTo("new user");
            assertThat(entry.getAttribute("mail").firstValueAsString()).isEqualTo("mail@mailme.org");
            assertThat(reader.hasNext()).isFalse();
        } finally {
            reader.close();
        }
    }
opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/DefaultTCPNIOTransportTestCase.java
@@ -50,15 +50,13 @@
        SocketAddress socketAddress = transport.get().bind(loopbackWithDynamicPort()).getLocalAddress();
        // Establish a socket connection to see if the transport factory works.
        final Socket socket = new Socket();
        try {
        try (Socket socket = new Socket()) {
            socket.connect(socketAddress);
            // Successfully connected if there is no exception.
            assertTrue(socket.isConnected());
            // Don't stop the transport because it is shared with the ldap server.
        } finally {
            socket.close();
            transport.release();
        }
    }
opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionFactoryTestCase.java
@@ -120,10 +120,9 @@
    @Test(description = "OPENDJ-1197")
    public void testClientSideConnectTimeout() throws Exception {
        // Use an non-local unreachable network address.
        final ConnectionFactory factory = new LDAPConnectionFactory("10.20.30.40", 1389,
            Options.defaultOptions().set(CONNECT_TIMEOUT, duration("1 ms")));
        try {
        // Use a non-local unreachable network address.
        try (ConnectionFactory factory = new LDAPConnectionFactory("10.20.30.40", 1389,
            Options.defaultOptions().set(CONNECT_TIMEOUT, duration("1 ms")))) {
            for (int i = 0; i < ITERATIONS; i++) {
                final PromiseImpl<LdapException, NeverThrowsException> promise = PromiseImpl.create();
                final Promise<? extends Connection, LdapException> connectionPromise = factory.getConnectionAsync();
@@ -139,8 +138,6 @@
                    assertThat(ce.getResult().getResultCode()).isEqualTo(ResultCode.CLIENT_SIDE_CONNECT_ERROR);
                }
            }
        } finally {
            factory.close();
        }
    }
@@ -157,8 +154,7 @@
        registerBindEvent();
        registerCloseEvent();
        final Connection connection = factory.getConnection();
        try {
        try (Connection connection = factory.getConnection()) {
            waitForConnect();
            final MockConnectionEventListener listener = new MockConnectionEventListener();
            connection.addConnectionEventListener(listener);
@@ -188,8 +184,6 @@
            connection.close();
            waitForClose();
            verifyNoAbandonSent();
        } finally {
            connection.close();
        }
    }
@@ -205,8 +199,7 @@
        registerCloseEvent();
        for (int i = 0; i < ITERATIONS; i++) {
            final Connection connection = pool.getConnection();
            try {
            try (Connection connection = pool.getConnection()) {
                waitForConnect();
                final MockConnectionEventListener listener = new MockConnectionEventListener();
                connection.addConnectionEventListener(listener);
@@ -240,8 +233,6 @@
                connection.close();
                waitForClose();
                verifyNoAbandonSent();
            } finally {
                connection.close();
            }
        }
    }
@@ -260,8 +251,7 @@
        registerAbandonEvent();
        for (int i = 0; i < ITERATIONS; i++) {
            final Connection connection = factory.getConnection();
            try {
            try (Connection connection = factory.getConnection()) {
                waitForConnect();
                final ConnectionEventListener listener = mock(ConnectionEventListener.class);
                connection.addConnectionEventListener(listener);
@@ -289,8 +279,6 @@
                 * LDAPConnection for explanation).
                 */
                // waitForAbandon();
            } finally {
                connection.close();
            }
        }
    }
@@ -333,8 +321,7 @@
        resetState();
        for (int i = 0; i < ITERATIONS; i++) {
            final Connection connection = factory.getConnection();
            try {
            try (Connection connection = factory.getConnection()) {
                waitForConnect();
                final MockConnectionEventListener listener = new MockConnectionEventListener();
                connection.addConnectionEventListener(listener);
@@ -344,8 +331,6 @@
                // Wait for the error notification to reach the client.
                listener.awaitError(TEST_TIMEOUT, TimeUnit.SECONDS);
            } finally {
                connection.close();
            }
        }
    }
opendj-grizzly/src/test/java/org/forgerock/opendj/grizzly/GrizzlyLDAPConnectionTestCase.java
@@ -88,8 +88,7 @@
                                                                  address.getPort(),
                                                                  Options.defaultOptions()
                                                                         .set(REQUEST_TIMEOUT, duration("100 ms")));
        GrizzlyLDAPConnection connection = (GrizzlyLDAPConnection) factory.getConnectionAsync().getOrThrow();
        try {
        try (GrizzlyLDAPConnection connection = (GrizzlyLDAPConnection) factory.getConnectionAsync().getOrThrow()) {
            SearchRequest request =
                    Requests.newSearchRequest("dc=test", SearchScope.BASE_OBJECT, "(objectClass=*)");
            if (isPersistentSearch) {
@@ -112,7 +111,6 @@
                        ResultCode.CLIENT_SIDE_TIMEOUT);
            }
        } finally {
            connection.close();
            listener.close();
            factory.close();
        }
opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFModify.java
@@ -36,7 +36,6 @@
import java.io.PrintStream;
import java.util.List;
import com.forgerock.opendj.cli.IntegerArgument;
import org.forgerock.i18n.LocalizableException;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.DecodeException;
@@ -51,12 +50,13 @@
import org.forgerock.opendj.ldif.LDIFEntryReader;
import org.forgerock.opendj.ldif.LDIFEntryWriter;
import org.forgerock.opendj.ldif.RejectedChangeRecordListener;
import org.forgerock.util.annotations.VisibleForTesting;
import com.forgerock.opendj.cli.ArgumentException;
import com.forgerock.opendj.cli.ArgumentParser;
import com.forgerock.opendj.cli.BooleanArgument;
import com.forgerock.opendj.cli.IntegerArgument;
import com.forgerock.opendj.cli.StringArgument;
import org.forgerock.util.annotations.VisibleForTesting;
/**
 * A tool that can be used to issue update (Add/Delete/Modify/ModifyDN) requests
@@ -142,17 +142,12 @@
            return ResultCode.SUCCESS.intValue();
        }
        InputStream sourceInputStream = null;
        OutputStream outputStream = null;
        final List<String> trailingArguments = argParser.getTrailingArguments();
        LDIFEntryReader sourceReader = null;
        LDIFChangeRecordReader changesReader = null;
        LDIFEntryWriter outputWriter = null;
        try {
            final List<String> trailingArguments = argParser.getTrailingArguments();
            sourceInputStream = getLDIFToolInputStream(this, trailingArguments.get(0));
            outputStream = getLDIFToolOutputStream(this, outputFilename);
        try (InputStream sourceInputStream = getLDIFToolInputStream(this, trailingArguments.get(0));
                OutputStream outputStream = getLDIFToolOutputStream(this, outputFilename)) {
            final int nbTrailingArgs = trailingArguments.size();
            final boolean readChangesFromStdin = nbTrailingArgs == 1
                    || (nbTrailingArgs == 2 && USE_SYSTEM_STREAM_TOKEN.equals(trailingArguments.get(1)));
@@ -253,8 +248,7 @@
        } catch (final ArgumentException ae) {
            throw newToolParamException(ae, ae.getMessageObject());
        } finally {
            closeSilently(sourceReader, changesReader, outputWriter,
                          sourceInputStream, outputStream);
            closeSilently(sourceReader, changesReader, outputWriter);
        }
        return ResultCode.SUCCESS.intValue();
opendj-server-legacy/src/main/java/org/forgerock/opendj/adapter/server3x/Converters.java
@@ -114,7 +114,7 @@
    }
    /**
     * Converts from OpenDJ LDAP SDK {@link org.forgerock.opendj.ldap.responses.SearchResultEntry} to OpenDJ
     * Converts from OpenDJ LDAP SDK {@link SearchResultEntry} to OpenDJ
     * server {@link org.opends.server.types.SearchResultEntry}.
     *
     * @param value
@@ -122,7 +122,7 @@
     * @return the converted value
     */
    public static org.opends.server.types.SearchResultEntry to(
            final org.forgerock.opendj.ldap.responses.SearchResultEntry value) {
            final SearchResultEntry value) {
        if (value != null) {
            org.opends.server.types.Entry entry =
                new org.opends.server.types.Entry(value.getName(), null, null, null);
@@ -186,19 +186,19 @@
    /**
     * Converts from OpenDJ LDAP SDK {@link Control} to OpenDJ server
     * {@link org.opends.server.protocols.ldap.LDAPControl}.
     * {@link LDAPControl}.
     *
     * @param control
     *          value to convert
     * @return the converted value
     */
    public static org.opends.server.protocols.ldap.LDAPControl to(final Control control) {
    public static LDAPControl to(final Control control) {
        return new LDAPControl(control.getOID(), control.isCritical(), control.getValue());
    }
    /**
     * Converts from a <code>List</code> of OpenDJ LDAP SDK
     * {@link org.forgerock.opendj.ldap.controls.Control} to a <code>List</code>
     * {@link Control} to a <code>List</code>
     * of OpenDJ server {@link org.opends.server.types.Control}.
     *
     * @param listOfControl
@@ -206,16 +206,16 @@
     * @return the converted value
     */
    public static List<org.opends.server.types.Control> to(
            final List<org.forgerock.opendj.ldap.controls.Control> listOfControl) {
            final List<Control> listOfControl) {
        List<org.opends.server.types.Control> toListOfControl = new ArrayList<>(listOfControl.size());
        for (org.forgerock.opendj.ldap.controls.Control c : listOfControl) {
        for (Control c : listOfControl) {
            toListOfControl.add(to(c));
        }
        return toListOfControl;
    }
    /**
     * Converts from OpenDJ LDAP SDK {@link org.forgerock.opendj.ldap.Attribute}
     * Converts from OpenDJ LDAP SDK {@link Attribute}
     * to OpenDJ server {@link org.opends.server.types.RawAttribute}.
     *
     * @param attribute
@@ -223,14 +223,14 @@
     * @return the converted value
     */
    public static org.opends.server.types.RawAttribute to(
            final org.forgerock.opendj.ldap.Attribute attribute) {
            final Attribute attribute) {
        ArrayList<ByteString> listAttributeValues = newArrayList(attribute.toArray());
        return new LDAPAttribute(attribute.getAttributeDescriptionAsString(), listAttributeValues);
    }
    /**
     * Converts from an <code>Iterable</code> of OpenDJ LDAP SDK
     * {@link org.forgerock.opendj.ldap.Attribute} to a <code>List</code> of
     * {@link Attribute} to a <code>List</code> of
     * OpenDJ server {@link org.opends.server.types.RawAttribute}.
     *
     * @param listOfAttributes
@@ -238,10 +238,10 @@
     * @return the converted value
     */
    public static List<org.opends.server.types.RawAttribute> to(
            final Iterable<org.forgerock.opendj.ldap.Attribute> listOfAttributes) {
            final Iterable<Attribute> listOfAttributes) {
        List<org.opends.server.types.RawAttribute> toListOfAttributes =
                new ArrayList<>(((Collection<?>) listOfAttributes).size());
        for (org.forgerock.opendj.ldap.Attribute a : listOfAttributes) {
        for (Attribute a : listOfAttributes) {
            toListOfAttributes.add(to(a));
        }
        return toListOfAttributes;
@@ -282,7 +282,7 @@
    }
    /**
     * Converts from OpenDJ LDAP SDK {@link org.forgerock.opendj.ldap.Attribute}
     * Converts from OpenDJ LDAP SDK {@link Attribute}
     * to OpenDJ server {@link org.opends.server.types.Attribute}.
     *
     * @param attribute
@@ -290,7 +290,7 @@
     * @return the converted value
     */
    public static org.opends.server.types.Attribute toAttribute(
            final org.forgerock.opendj.ldap.Attribute attribute) {
            final Attribute attribute) {
        final AttributeBuilder attrBuilder =
            new AttributeBuilder(attribute.getAttributeDescriptionAsString());
        for (ByteString b : attribute.toArray()) {
@@ -301,7 +301,7 @@
    /**
     * Converts from an <code>Iterable</code> of OpenDJ LDAP SDK
     * {@link org.forgerock.opendj.ldap.Attribute} to a <code>List</code> of
     * {@link Attribute} to a <code>List</code> of
     * OpenDJ server {@link org.opends.server.types.RawAttribute}.
     *
     * @param listOfAttributes
@@ -309,7 +309,7 @@
     * @return the converted value
     */
    public static List<org.opends.server.types.Attribute> toAttributes(
            final Iterable<org.forgerock.opendj.ldap.Attribute> listOfAttributes) {
            final Iterable<Attribute> listOfAttributes) {
        List<org.opends.server.types.Attribute> toListOfAttributes = new ArrayList<>();
        Iterator<Attribute> it = listOfAttributes.iterator();
        while (it.hasNext())
@@ -354,14 +354,14 @@
    /**
     * Converts from OpenDJ server
     * {@link org.opends.server.protocols.ldap.LDAPControl} to OpenDJ LDAP SDK
     * {@link LDAPControl} to OpenDJ LDAP SDK
     * {@link Control}.
     *
     * @param ldapControl
     *          value to convert
     * @return the converted value
     */
    public static Control from(final org.opends.server.protocols.ldap.LDAPControl ldapControl) {
    public static Control from(final LDAPControl ldapControl) {
        return GenericControl.newControl(ldapControl.getOID(), ldapControl.isCritical(),
                ldapControl.getValue());
    }
@@ -388,8 +388,8 @@
        }
        final ByteString sdkByteString = builder.toByteString();
        final org.forgerock.opendj.io.ASN1Reader sdkReaderASN1 =
                org.forgerock.opendj.io.ASN1.getReader(sdkByteString.toByteArray());
        final ASN1Reader sdkReaderASN1 =
                ASN1.getReader(sdkByteString.toByteArray());
        // Reads the ASN1 SDK byte string.
        try {
@@ -414,15 +414,15 @@
    /**
     * Converts from a <code>List</code> of OpenDJ server
     * {@link org.opends.server.types.Control} to a <code>List</code> of OpenDJ
     * LDAP SDK {@link org.forgerock.opendj.ldap.controls.Control}.
     * LDAP SDK {@link Control}.
     *
     * @param listOfControl
     *          value to convert
     * @return the converted value
     */
    public static List<org.forgerock.opendj.ldap.controls.Control> from(
    public static List<Control> from(
            final List<org.opends.server.types.Control> listOfControl) {
        List<org.forgerock.opendj.ldap.controls.Control> fromListofControl = new ArrayList<>(listOfControl.size());
        List<Control> fromListofControl = new ArrayList<>(listOfControl.size());
        for (org.opends.server.types.Control c : listOfControl) {
            fromListofControl.add(from(c));
        }
@@ -445,13 +445,13 @@
    /**
     * Converts from OpenDJ server {@link org.opends.server.types.Attribute} to
     * OpenDJ LDAP SDK {@link org.forgerock.opendj.ldap.Attribute}.
     * OpenDJ LDAP SDK {@link Attribute}.
     *
     * @param attribute
     *          value to convert
     * @return the converted value
     */
    public static org.forgerock.opendj.ldap.Attribute from(
    public static Attribute from(
            final org.opends.server.types.Attribute attribute) {
        Attribute sdkAttribute = new LinkedAttribute(attribute.getAttributeDescription());
        for (ByteString value : attribute) {
@@ -462,7 +462,7 @@
    /**
     * Converts from OpenDJ server {@link org.opends.server.types.Attribute} to OpenDJ LDAP SDK
     * {@link org.forgerock.opendj.ldap.Attribute}. This method is an optimization of the equivalent from() method. It's
     * {@link Attribute}. This method is an optimization of the equivalent from() method. It's
     * only used in encoding/decoding and as such only wrap the required methods: the returned object partially wrap the
     * incoming one.
     *
@@ -470,7 +470,7 @@
     *            value to convert
     * @return the converted value
     */
    public static org.forgerock.opendj.ldap.Attribute partiallyWrap(final org.opends.server.types.Attribute attribute) {
    public static Attribute partiallyWrap(final org.opends.server.types.Attribute attribute) {
        return new Attribute() {
            @Override
@@ -589,15 +589,15 @@
    /**
     * Converts from an <code>Iterable</code> of OpenDJ server
     * {@link org.opends.server.types.Attribute} to a <code>List</code> of OpenDJ
     * LDAP SDK {@link org.forgerock.opendj.ldap.Attribute}.
     * LDAP SDK {@link Attribute}.
     *
     * @param listOfAttributes
     *          value to convert
     * @return the converted value
     */
    public static List<org.forgerock.opendj.ldap.Attribute> from(
    public static List<Attribute> from(
            final Iterable<org.opends.server.types.Attribute> listOfAttributes) {
        List<org.forgerock.opendj.ldap.Attribute> fromListofAttributes =
        List<Attribute> fromListofAttributes =
                new ArrayList<>(((Collection<?>) listOfAttributes).size());
        for (org.opends.server.types.Attribute a : listOfAttributes) {
            fromListofAttributes.add(from(a));
@@ -608,13 +608,13 @@
    /**
     * Converts from OpenDJ server
     * {@link org.opends.server.types.SearchResultEntry} to OpenDJ LDAP SDK
     * {@link org.forgerock.opendj.ldap.responses.SearchResultEntry}.
     * {@link SearchResultEntry}.
     *
     * @param srvResultEntry
     *          value to convert
     * @return the converted value
     */
    public static org.forgerock.opendj.ldap.responses.SearchResultEntry from(
    public static SearchResultEntry from(
            final org.opends.server.types.SearchResultEntry srvResultEntry) {
        final SearchResultEntry searchResultEntry =
@@ -630,7 +630,7 @@
    /**
     * Converts from OpenDJ server {@link org.opends.server.types.SearchResultEntry} to OpenDJ LDAP SDK
     * {@link org.forgerock.opendj.ldap.responses.SearchResultEntry}. This method is an optimization of the equivalent
     * {@link SearchResultEntry}. This method is an optimization of the equivalent
     * from() method. It's only used in encoding/decoding and as such only wrap the required methods: the returned
     * object partially wrap the incoming one.
     *
@@ -640,12 +640,12 @@
     *            Version of the ldap protocol
     * @return the converted value
     */
    public static org.forgerock.opendj.ldap.responses.SearchResultEntry partiallyWrap(
    public static SearchResultEntry partiallyWrap(
            final org.opends.server.types.SearchResultEntry srvResultEntry, final int ldapVersion) {
        final ArrayList<Control> controls = new ArrayList<>(srvResultEntry.getControls().size());
        for (org.opends.server.types.Control control : srvResultEntry.getControls()) {
            controls.add(Converters.from(control));
            controls.add(from(control));
        }
        return new SearchResultEntry() {
@@ -810,8 +810,8 @@
    /**
     * Converts from OpenDJ server
     * {@link org.forgerock.opendj.server.config.meta.VirtualAttributeCfgDefn.Scope}
     *  to OpenDJ LDAP SDK {@link org.forgerock.opendj.ldap.SearchScope}.
     * {@link VirtualAttributeCfgDefn.Scope}
     *  to OpenDJ LDAP SDK {@link SearchScope}.
     *
     * @param srvScope
     *          The server scope value.
@@ -922,7 +922,7 @@
                reader.readStartSequence();
                return reader.readOctetString(TYPE_PASSWORD_MODIFY_GENERATED_PASSWORD);
            } catch (IOException e) {
                throw LdapException.newLdapException(ResultCode.PROTOCOL_ERROR,
                throw newLdapException(ResultCode.PROTOCOL_ERROR,
                        ERR_EXTOP_PASSMOD_CANNOT_DECODE_REQUEST.get(getExceptionMessage(e)), e);
            }
        }
opendj-server-legacy/src/main/java/org/opends/server/backends/TrustStoreBackend.java
@@ -988,13 +988,9 @@
          File tempDir = getFileForPath("config");
          File tempFile = File.createTempFile(configuration.getBackendId(),
                                              certAlias, tempDir);
          try
          try (FileOutputStream outputStream = new FileOutputStream(tempFile.getPath(), false))
          {
            try (FileOutputStream outputStream = new FileOutputStream(tempFile.getPath(), false))
            {
              certBytes.copyTo(outputStream);
            }
            certBytes.copyTo(outputStream);
            certificateManager.addCertificate(certAlias, tempFile);
          }
          finally
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/IndexQueryFactoryImpl.java
@@ -244,75 +244,67 @@
          return newUndefinedSet();
        }
        try
        try (Cursor<ByteString, EntryIDSet> cursor = index.openCursor(txn))
        {
          // Total number of IDs found so far.
          int totalIDCount = 0;
          boolean success;
          // Set the lower bound if necessary.
          if (lower.length() > 0)
          {
            // Initialize the cursor to the lower bound.
            success = cursor.positionToKeyOrNext(lower);
            // Advance past the lower bound if necessary.
            if (success && !lowerIncluded && cursor.getKey().equals(lower))
            {
              // Do not include the lower value.
              success = cursor.next();
            }
          }
          else
          {
            success = cursor.next();
          }
          if (!success)
          {
            // There are no values.
            return EntryIDSet.newDefinedSet();
          }
          ArrayList<EntryIDSet> sets = new ArrayList<>();
          Cursor<ByteString, EntryIDSet> cursor = index.openCursor(txn);
          try
          // Step through the keys until we hit the upper bound or the last key.
          while (success)
          {
            boolean success;
            // Set the lower bound if necessary.
            if (lower.length() > 0)
            // Check against the upper bound if necessary
            if (upper.length() > 0)
            {
              // Initialize the cursor to the lower bound.
              success = cursor.positionToKeyOrNext(lower);
              // Advance past the lower bound if necessary.
              if (success && !lowerIncluded && cursor.getKey().equals(lower))
              int cmp = cursor.getKey().compareTo(upper);
              if (cmp > 0 || (cmp == 0 && !upperIncluded))
              {
                // Do not include the lower value.
                success = cursor.next();
                break;
              }
            }
            else
            EntryIDSet set = cursor.getValue();
            if (!set.isDefined())
            {
              success = cursor.next();
              // There is no point continuing.
              return set;
            }
            if (!success)
            totalIDCount += set.size();
            if (totalIDCount > IndexFilter.CURSOR_ENTRY_LIMIT)
            {
              // There are no values.
              return EntryIDSet.newDefinedSet();
              // There are too many. Give up and return an undefined list.
              // Use any key to have debugsearchindex return LIMIT-EXCEEDED instead of NOT-INDEXED.
              return newUndefinedSetWithKey(cursor.getKey());
            }
            // Step through the keys until we hit the upper bound or the last key.
            while (success)
            {
              // Check against the upper bound if necessary
              if (upper.length() > 0)
              {
                int cmp = cursor.getKey().compareTo(upper);
                if (cmp > 0 || (cmp == 0 && !upperIncluded))
                {
                  break;
                }
              }
              EntryIDSet set = cursor.getValue();
              if (!set.isDefined())
              {
                // There is no point continuing.
                return set;
              }
              totalIDCount += set.size();
              if (totalIDCount > IndexFilter.CURSOR_ENTRY_LIMIT)
              {
                // There are too many. Give up and return an undefined list.
                // Use any key to have debugsearchindex return LIMIT-EXCEEDED instead of NOT-INDEXED.
                return newUndefinedSetWithKey(cursor.getKey());
              }
              sets.add(set);
              success = cursor.next();
            }
            return EntryIDSet.newSetFromUnion(sets);
            sets.add(set);
            success = cursor.next();
          }
          finally
          {
            cursor.close();
          }
          return EntryIDSet.newSetFromUnion(sets);
        }
        catch (StorageRuntimeException e)
        {
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/PersistentCompressedSchema.java
@@ -16,6 +16,8 @@
 */
package org.opends.server.backends.pluggable;
import static org.opends.messages.BackendMessages.*;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
@@ -40,8 +42,6 @@
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import static org.opends.messages.BackendMessages.*;
/**
 * This class provides a compressed schema implementation whose definitions are
 * persisted in a tree.
@@ -146,8 +146,7 @@
    // Cursor through the object class database and load the object class set
    // definitions. At the same time, figure out the highest token value and
    // initialize the object class counter to one greater than that.
    final Cursor<ByteString, ByteString> ocCursor = txn.openCursor(ocTreeName);
    try
    try (Cursor<ByteString, ByteString> ocCursor = txn.openCursor(ocTreeName))
    {
      while (ocCursor.next())
      {
@@ -168,15 +167,9 @@
      logger.traceException(e);
      throw new InitializationException(ERR_COMPSCHEMA_CANNOT_DECODE_OC_TOKEN.get(e.getMessage()), e);
    }
    finally
    {
      ocCursor.close();
    }
    // Cursor through the attribute description database and load the attribute
    // set definitions.
    final Cursor<ByteString, ByteString> adCursor = txn.openCursor(adTreeName);
    try
    // Cursor through the attribute description database and load the attribute set definitions.
    try (Cursor<ByteString, ByteString> adCursor = txn.openCursor(adTreeName))
    {
      while (adCursor.next())
      {
@@ -198,10 +191,6 @@
      logger.traceException(e);
      throw new InitializationException(ERR_COMPSCHEMA_CANNOT_DECODE_AD_TOKEN.get(e.getMessage()), e);
    }
    finally
    {
      adCursor.close();
    }
  }
  private boolean store(final TreeName treeName, final byte[] key, final ByteStringBuilder value)
opendj-server-legacy/src/test/java/org/opends/server/replication/server/changelog/file/ReplicationEnvironmentTest.java
@@ -340,9 +340,7 @@
    final TimeService time = mock(TimeService.class);
    when(time.now()).thenReturn(100L, 200L);
    ReplicationEnvironment environment = new ReplicationEnvironment(rootPath.getAbsolutePath(), null, time);
    Log<Long,ChangeNumberIndexRecord> cnIndexDB = environment.getOrCreateCNIndexDB();
    try {
    try (Log<Long,ChangeNumberIndexRecord> cnIndexDB = environment.getOrCreateCNIndexDB()) {
      environment.notifyLogFileRotation(cnIndexDB);
      // check runtime change of last rotation time is effective
@@ -351,7 +349,6 @@
    }
    finally
    {
      cnIndexDB.close();
      environment.shutdown();
    }
opendj-server/src/main/java/org/forgerock/opendj/server/core/ProductInformation.java
@@ -11,13 +11,10 @@
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2014 ForgeRock AS.
 * Copyright 2014-2016 ForgeRock AS.
 */
package org.forgerock.opendj.server.core;
import static org.forgerock.util.Utils.closeSilently;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -54,14 +51,11 @@
        }
        properties = new Properties();
        final InputStream is = new BufferedInputStream(stream);
        try {
        try (InputStream is = new BufferedInputStream(stream)) {
            properties.load(is);
        } catch (final IOException e) {
            throw new MissingResourceException("Can't load product information " + resourceName
                    + " due to IO exception: " + e.getMessage(), productName, "");
        } finally {
            closeSilently(is);
        }
        versionFull =