From 23cf07c2c64ba72f59b3257b9b91f4c8814b05ce Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Mon, 16 May 2011 16:29:37 +0000
Subject: [PATCH] Fix for Issue OPENDJ-151 - Resolve a couple of potential issues raised by FindBugs.
---
opends/src/server/org/opends/server/backends/TrustStoreBackend.java | 49 +++++++++++++++++++++---
opends/src/server/org/opends/server/backends/LDIFBackend.java | 23 ++++++-----
opends/src/server/org/opends/server/backends/SchemaBackend.java | 3 -
opends/src/server/org/opends/server/replication/common/ChangeNumberGenerator.java | 8 +++-
opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java | 33 ++++++++++++++--
5 files changed, 90 insertions(+), 26 deletions(-)
diff --git a/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java b/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
index 60f3a0c..2b0f427 100644
--- a/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
+++ b/opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
@@ -23,6 +23,7 @@
*
*
* Copyright 2007-2010 Sun Microsystems, Inc.
+ * Portions Copyright 2011 ForgeRock AS
*/
package org.opends.server.admin.client.cli;
@@ -814,10 +815,11 @@
else
if (trustStorePathArg.isPresent())
{
+ FileInputStream fos = null;
+
try
{
- FileInputStream fos =
- new FileInputStream(trustStorePathArg.getValue());
+ fos = new FileInputStream(trustStorePathArg.getValue());
String trustStorePasswordStringValue = null;
char[] trustStorePasswordValue = null;
if (trustStorePasswordArg.isPresent())
@@ -845,7 +847,6 @@
truststore = KeyStore.getInstance(KeyStore.getDefaultType());
truststore.load(fos, trustStorePasswordValue);
- fos.close();
}
catch (KeyStoreException e)
{
@@ -875,6 +876,17 @@
// are in a best effort mode.
LOG.log(Level.WARNING, "Error with the truststore", e);
}
+ finally
+ {
+ if (fos != null)
+ {
+ try
+ {
+ fos.close();
+ }
+ catch (Exception e) {}
+ }
+ }
}
trustManager = new ApplicationTrustManager(truststore);
}
@@ -893,9 +905,10 @@
char[] keyStorePasswordValue = null;
if (keyStorePathArg.isPresent())
{
+ FileInputStream fos = null;
try
{
- FileInputStream fos = new FileInputStream(keyStorePathArg.getValue());
+ fos = new FileInputStream(keyStorePathArg.getValue());
if (keyStorePasswordArg.isPresent())
{
keyStorePasswordStringValue = keyStorePasswordArg.getValue();
@@ -911,7 +924,6 @@
keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(fos,keyStorePasswordValue);
- fos.close();
}
catch (KeyStoreException e)
{
@@ -948,6 +960,17 @@
// in a best effort mode.
LOG.log(Level.WARNING, "Error with the keystore", e);
}
+ finally
+ {
+ if (fos != null)
+ {
+ try {
+ fos.close();
+ }
+ catch (Exception e) {}
+ }
+ }
+
char[] password = null;
if (keyStorePasswordStringValue != null)
{
diff --git a/opends/src/server/org/opends/server/backends/LDIFBackend.java b/opends/src/server/org/opends/server/backends/LDIFBackend.java
index 761a3b9..6f19225 100644
--- a/opends/src/server/org/opends/server/backends/LDIFBackend.java
+++ b/opends/src/server/org/opends/server/backends/LDIFBackend.java
@@ -23,6 +23,7 @@
*
*
* Copyright 2007-2008 Sun Microsystems, Inc.
+ * Portions Copyright 2011 ForgeRock AS
*/
package org.opends.server.backends;
@@ -637,19 +638,21 @@
else
{
DN matchedDN = null;
- // BUG: parentDN can be null when entering the loop
- while (true)
+ if (parentDN != null)
{
- parentDN = parentDN.getParentDNInSuffix();
- if (parentDN == null)
+ while (true)
{
- break;
- }
+ parentDN = parentDN.getParentDNInSuffix();
+ if (parentDN == null)
+ {
+ break;
+ }
- if (entryMap.containsKey(parentDN))
- {
- matchedDN = parentDN;
- break;
+ if (entryMap.containsKey(parentDN))
+ {
+ matchedDN = parentDN;
+ break;
+ }
}
}
diff --git a/opends/src/server/org/opends/server/backends/SchemaBackend.java b/opends/src/server/org/opends/server/backends/SchemaBackend.java
index f140ac6..fbec4d3 100644
--- a/opends/src/server/org/opends/server/backends/SchemaBackend.java
+++ b/opends/src/server/org/opends/server/backends/SchemaBackend.java
@@ -4435,9 +4435,8 @@
* Import an entry in a new schema by :
* - duplicating the schema
* - iterating over each element of the newSchemaEntry and comparing
- * with the xisting schema
+ * with the existing schema
* - if the new schema element do not exist : add it
- * - if the new schema.
*
* FIXME : attributeTypes and objectClasses are the only elements
* currently taken into account.
diff --git a/opends/src/server/org/opends/server/backends/TrustStoreBackend.java b/opends/src/server/org/opends/server/backends/TrustStoreBackend.java
index 7cd1125..325c01e 100644
--- a/opends/src/server/org/opends/server/backends/TrustStoreBackend.java
+++ b/opends/src/server/org/opends/server/backends/TrustStoreBackend.java
@@ -23,6 +23,7 @@
*
*
* Copyright 2007-2010 Sun Microsystems, Inc.
+ * Portions Copyright 2011 ForgeRock AS
*/
package org.opends.server.backends;
@@ -230,6 +231,8 @@
String pinStr = configuration.getTrustStorePin();
if (pinStr == null)
{
+ // This should be an Error. Otherwise, programs fails.
+ // Is there a Unit Test?
trustStorePIN = null;
}
else
@@ -1364,14 +1367,14 @@
throws DirectoryException
{
KeyStore keyStore;
+ FileInputStream inputStream = null;
try
{
keyStore = KeyStore.getInstance(trustStoreType);
- FileInputStream inputStream =
+ inputStream =
new FileInputStream(getFileForPath(trustStoreFile));
keyStore.load(inputStream, trustStorePIN);
- inputStream.close();
}
catch (Exception e)
{
@@ -1385,6 +1388,17 @@
throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
message, e);
}
+ finally
+ {
+ if (inputStream != null)
+ {
+ try
+ {
+ inputStream.close();
+ }
+ catch (Exception e){}
+ }
+ }
try
@@ -1424,14 +1438,14 @@
throws DirectoryException
{
KeyStore trustStore;
+ FileInputStream inputStream = null;
try
{
trustStore = KeyStore.getInstance(trustStoreType);
- FileInputStream inputStream =
+ inputStream =
new FileInputStream(getFileForPath(trustStoreFile));
trustStore.load(inputStream, trustStorePIN);
- inputStream.close();
}
catch (Exception e)
{
@@ -1445,6 +1459,17 @@
throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
message, e);
}
+ finally
+ {
+ if (inputStream != null)
+ {
+ try
+ {
+ inputStream.close();
+ }
+ catch (Exception e){}
+ }
+ }
try
@@ -1492,14 +1517,14 @@
throws DirectoryException
{
KeyStore trustStore;
+ FileInputStream inputStream = null;
try
{
trustStore = KeyStore.getInstance(trustStoreType);
- FileInputStream inputStream =
+ inputStream =
new FileInputStream(getFileForPath(trustStoreFile));
trustStore.load(inputStream, trustStorePIN);
- inputStream.close();
}
catch (Exception e)
{
@@ -1513,7 +1538,17 @@
throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
message, e);
}
-
+ finally
+ {
+ if (inputStream != null)
+ {
+ try
+ {
+ inputStream.close();
+ }
+ catch (Exception e){}
+ }
+ }
try
{
diff --git a/opends/src/server/org/opends/server/replication/common/ChangeNumberGenerator.java b/opends/src/server/org/opends/server/replication/common/ChangeNumberGenerator.java
index af9174d..70b55bb 100644
--- a/opends/src/server/org/opends/server/replication/common/ChangeNumberGenerator.java
+++ b/opends/src/server/org/opends/server/replication/common/ChangeNumberGenerator.java
@@ -23,6 +23,7 @@
*
*
* Copyright 2006-2009 Sun Microsystems, Inc.
+ * Portions Copyright 2011 ForgeRock AS
*/
package org.opends.server.replication.common;
@@ -118,8 +119,11 @@
{
if (number==null)
{
- lastTime = TimeThread.getTime();
- seqnum = 0;
+ synchronized(this)
+ {
+ lastTime = TimeThread.getTime();
+ seqnum = 0;
+ }
return;
}
--
Gitblit v1.10.0