You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2019/01/02 16:02:27 UTC
[directory-ldap-api] branch master updated: Fixed 20 blocker issues
(Sonar)
This is an automated email from the ASF dual-hosted git repository.
elecharny pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git
The following commit(s) were added to refs/heads/master by this push:
new cb78ad6 Fixed 20 blocker issues (Sonar)
cb78ad6 is described below
commit cb78ad62bc5a3f7a9c038962b9cd3f38c0fe1919
Author: Emmanuel Lecharny <el...@apache.org>
AuthorDate: Wed Jan 2 17:02:25 2019 +0100
Fixed 20 blocker issues (Sonar)
---
.../api/dsmlv2/request/ModifyDNRequestDsml.java | 33 ----
.../directory/ldap/client/api/LdifAnonymizer.java | 177 +++++++++++----------
.../client/api/future/MultipleResponseFuture.java | 28 ++--
.../ldap/codec/osgi/DefaultLdapCodecService.java | 2 +-
.../controls/vlv/VirtualListViewRequestImpl.java | 11 +-
.../StartTransactionResponseImpl.java | 3 +-
.../directory/api/ldap/model/ldif/LdifEntry.java | 9 +-
.../model/message/extended/NoticeOfDisconnect.java | 4 +
.../apache/directory/api/ldap/model/name/Rdn.java | 3 +-
.../directory/api/ldap/model/password/BCrypt.java | 4 +-
10 files changed, 123 insertions(+), 151 deletions(-)
diff --git a/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/ModifyDNRequestDsml.java b/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/ModifyDNRequestDsml.java
index 6926e92..f9bcc60 100644
--- a/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/ModifyDNRequestDsml.java
+++ b/dsml/parser/src/main/java/org/apache/directory/api/dsmlv2/request/ModifyDNRequestDsml.java
@@ -143,39 +143,6 @@ public class ModifyDNRequestDsml
/**
- * Set the flag to delete the old Rdn
- *
- * @param deleteOldRDN The deleteOldRDN to set.
- */
- public void setDeleteOldRDN( boolean deleteOldRDN )
- {
- getDecorated().setDeleteOldRdn( deleteOldRDN );
- }
-
-
- /**
- * Get the new Rdn
- *
- * @return Returns the newRDN.
- */
- public Rdn getNewRDN()
- {
- return getDecorated().getNewRdn();
- }
-
-
- /**
- * Set the new Rdn
- *
- * @param newRdn The newRdn to set.
- */
- public void setNewRDN( Rdn newRdn )
- {
- getDecorated().setNewRdn( newRdn );
- }
-
-
- /**
* Get the newSuperior
*
* @return Returns the newSuperior.
diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdifAnonymizer.java b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdifAnonymizer.java
index db22d7e..0b92054 100644
--- a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdifAnonymizer.java
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdifAnonymizer.java
@@ -533,121 +533,122 @@ public class LdifAnonymizer
return;
}
- LdifReader ldifReader = new LdifReader( inputFile, schemaManager );
- int count = 0;
- List<LdifEntry> errors = new ArrayList<>();
- List<String> errorTexts = new ArrayList<>();
-
- try
+ try ( LdifReader ldifReader = new LdifReader( inputFile, schemaManager ) )
{
- for ( LdifEntry ldifEntry : ldifReader )
+ int count = 0;
+ List<LdifEntry> errors = new ArrayList<>();
+ List<String> errorTexts = new ArrayList<>();
+
+ try
{
- count++;
-
- try
+ for ( LdifEntry ldifEntry : ldifReader )
{
- if ( ldifEntry.isEntry() && !ldifEntry.isChangeAdd() )
- {
- // process a full entry. Add changes aren't processed here.
- Entry newEntry = anonymizeEntry( ldifEntry );
-
- writer.write( LdifUtils.convertToLdif( newEntry ) );
- writer.write( "\n" );
- }
- else if ( ldifEntry.isChangeDelete() )
+ count++;
+
+ try
{
- // A Delete operation
- LdifEntry newLdifEntry = anonymizeChangeDelete( ldifEntry );
-
- if ( ldifEntry != null )
+ if ( ldifEntry.isEntry() && !ldifEntry.isChangeAdd() )
{
- writer.write( newLdifEntry.toString() );
+ // process a full entry. Add changes aren't processed here.
+ Entry newEntry = anonymizeEntry( ldifEntry );
+
+ writer.write( LdifUtils.convertToLdif( newEntry ) );
writer.write( "\n" );
}
- }
- else if ( ldifEntry.isChangeAdd() )
- {
- // A Add operation
- LdifEntry newLdifEntry = anonymizeChangeAdd( ldifEntry );
-
- if ( ldifEntry != null )
+ else if ( ldifEntry.isChangeDelete() )
{
- writer.write( newLdifEntry.toString() );
- writer.write( "\n" );
+ // A Delete operation
+ LdifEntry newLdifEntry = anonymizeChangeDelete( ldifEntry );
+
+ if ( ldifEntry != null )
+ {
+ writer.write( newLdifEntry.toString() );
+ writer.write( "\n" );
+ }
}
- }
- else if ( ldifEntry.isChangeModify() )
- {
- // A Modify operation
- LdifEntry newLdifEntry = anonymizeChangeModify( ldifEntry );
-
- if ( ldifEntry != null )
+ else if ( ldifEntry.isChangeAdd() )
{
- writer.write( newLdifEntry.toString() );
- writer.write( "\n" );
+ // A Add operation
+ LdifEntry newLdifEntry = anonymizeChangeAdd( ldifEntry );
+
+ if ( ldifEntry != null )
+ {
+ writer.write( newLdifEntry.toString() );
+ writer.write( "\n" );
+ }
}
- }
- else if ( ldifEntry.isChangeModDn() || ldifEntry.isChangeModRdn() )
- {
- // A MODDN operation
- LdifEntry newLdifEntry = anonymizeChangeModDn( ldifEntry );
-
- if ( ldifEntry != null )
+ else if ( ldifEntry.isChangeModify() )
{
- writer.write( newLdifEntry.toString() );
- writer.write( "\n" );
+ // A Modify operation
+ LdifEntry newLdifEntry = anonymizeChangeModify( ldifEntry );
+
+ if ( ldifEntry != null )
+ {
+ writer.write( newLdifEntry.toString() );
+ writer.write( "\n" );
+ }
+ }
+ else if ( ldifEntry.isChangeModDn() || ldifEntry.isChangeModRdn() )
+ {
+ // A MODDN operation
+ LdifEntry newLdifEntry = anonymizeChangeModDn( ldifEntry );
+
+ if ( ldifEntry != null )
+ {
+ writer.write( newLdifEntry.toString() );
+ writer.write( "\n" );
+ }
+ }
+
+ System.out.print( '.' );
+
+ if ( count % 100 == 0 )
+ {
+ println();
}
}
-
- System.out.print( '.' );
-
- if ( count % 100 == 0 )
+ catch ( Exception e )
{
- println();
+ System.out.print( '*' );
+
+ if ( count % 100 == 0 )
+ {
+ println();
+ }
+
+ errors.add( ldifEntry );
+ errorTexts.add( e.getMessage() );
}
}
- catch ( Exception e )
+
+ println();
+
+ if ( !errors.isEmpty() )
{
- System.out.print( '*' );
-
- if ( count % 100 == 0 )
+ println( "There are " + errors.size() + " bad entries" );
+ int i = 0;
+
+ for ( LdifEntry ldifEntry : errors )
{
- println();
+ println( "---------------------------------------------------" );
+ println( "error : " + errorTexts.get( i ) );
+ println( ldifEntry.getDn().toString() );
+ i++;
}
-
- errors.add( ldifEntry );
- errorTexts.add( e.getMessage() );
}
}
-
- println();
-
- if ( !errors.isEmpty() )
+ finally
{
- println( "There are " + errors.size() + " bad entries" );
- int i = 0;
-
- for ( LdifEntry ldifEntry : errors )
+ println();
+
+ if ( !errors.isEmpty() )
{
- println( "---------------------------------------------------" );
- println( "error : " + errorTexts.get( i ) );
- println( ldifEntry.getDn().toString() );
- i++;
+ println( "There are " + errors.size() + " bad entries" );
}
+
+ println( "Nb entries : " + count );
}
}
- finally
- {
- println();
-
- if ( !errors.isEmpty() )
- {
- println( "There are " + errors.size() + " bad entries" );
- }
-
- println( "Nb entries : " + count );
- ldifReader.close();
- }
}
diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/future/MultipleResponseFuture.java b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/future/MultipleResponseFuture.java
index 3833352..e6b3a5c 100644
--- a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/future/MultipleResponseFuture.java
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/future/MultipleResponseFuture.java
@@ -73,24 +73,22 @@ public abstract class MultipleResponseFuture<R extends Response> implements Resp
@Override
public boolean cancel( boolean mayInterruptIfRunning )
{
- if ( cancelled )
+ if ( !cancelled )
{
- return cancelled;
+ // set the cancel flag first
+ cancelled = true;
+
+ // Send an abandonRequest only if this future exists
+ if ( !connection.isRequestCompleted( messageId ) )
+ {
+ connection.abandon( messageId );
+ }
+
+ // then clear the queue, cause the might be some incoming messages before this abandon request
+ // hits the server
+ queue.clear();
}
- // set the cancel flag first
- cancelled = true;
-
- // Send an abandonRequest only if this future exists
- if ( !connection.isRequestCompleted( messageId ) )
- {
- connection.abandon( messageId );
- }
-
- // then clear the queue, cause the might be some incoming messages before this abandon request
- // hits the server
- queue.clear();
-
return cancelled;
}
diff --git a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/osgi/DefaultLdapCodecService.java b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/osgi/DefaultLdapCodecService.java
index e4371f6..e7bed54 100644
--- a/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/osgi/DefaultLdapCodecService.java
+++ b/ldap/codec/core/src/main/java/org/apache/directory/api/ldap/codec/osgi/DefaultLdapCodecService.java
@@ -255,7 +255,7 @@ public class DefaultLdapCodecService implements LdapApiService
@Override
public boolean isControlRegistered( String oid )
{
- return requestControlFactories.containsKey( oid ) | responseControlFactories.containsKey( oid );
+ return requestControlFactories.containsKey( oid ) || responseControlFactories.containsKey( oid );
}
diff --git a/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/controls/vlv/VirtualListViewRequestImpl.java b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/controls/vlv/VirtualListViewRequestImpl.java
index 2305bfc..ec42433 100644
--- a/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/controls/vlv/VirtualListViewRequestImpl.java
+++ b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/controls/vlv/VirtualListViewRequestImpl.java
@@ -55,10 +55,11 @@ public class VirtualListViewRequestImpl extends AbstractControl implements Virtu
/** The assertionValue */
private byte[] assertionValue;
+ private static final boolean OFFSET_CHOICE = true;
+
/** A flag used for the target. It default to OFFSET */
- private boolean targetType = OFFSET;
+ private boolean targetType = OFFSET_CHOICE;
- private static final boolean OFFSET = true;
private static final boolean ASSERTION_VALUE = false;
@@ -128,7 +129,7 @@ public class VirtualListViewRequestImpl extends AbstractControl implements Virtu
public void setOffset( int offset )
{
this.offset = offset;
- targetType = OFFSET;
+ targetType = OFFSET_CHOICE;
}
@@ -199,7 +200,7 @@ public class VirtualListViewRequestImpl extends AbstractControl implements Virtu
@Override
public boolean hasOffset()
{
- return targetType == OFFSET;
+ return targetType == OFFSET_CHOICE;
}
@@ -280,7 +281,7 @@ public class VirtualListViewRequestImpl extends AbstractControl implements Virtu
sb.append( " afterCount : '" ).append( afterCount ).append( "'\n" );
sb.append( " target : \n" );
- if ( targetType == OFFSET )
+ if ( targetType == OFFSET_CHOICE )
{
sb.append( " offset : '" ).append( offset ).append( "'\n" );
sb.append( " contentCount : '" ).append( contentCount ).append( "'\n" );
diff --git a/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/startTransaction/StartTransactionResponseImpl.java b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/startTransaction/StartTransactionResponseImpl.java
index 1176c5d..1054ead 100644
--- a/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/startTransaction/StartTransactionResponseImpl.java
+++ b/ldap/extras/codec-api/src/main/java/org/apache/directory/api/ldap/extras/extended/startTransaction/StartTransactionResponseImpl.java
@@ -63,7 +63,8 @@ public class StartTransactionResponseImpl extends AbstractExtendedResponse imple
{
case SUCCESS:
this.transactionId = Strings.copy( transactionId );
- // pass through ...
+ break;
+
case CANCELED:
case CANNOT_CANCEL:
case NO_SUCH_OPERATION:
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/ldif/LdifEntry.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/ldif/LdifEntry.java
index 872fab0..2c3d174 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/ldif/LdifEntry.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/ldif/LdifEntry.java
@@ -244,12 +244,11 @@ public class LdifEntry implements Cloneable, Externalizable, Iterable<Attribute>
}
// Now, parse the Ldif and convert it to a LdifEntry
- LdifReader reader = new LdifReader();
- List<LdifEntry> ldifEntries = reader.parseLdif( sb.toString() );
-
- try
+ List<LdifEntry> ldifEntries = null;
+
+ try ( LdifReader reader = new LdifReader() )
{
- reader.close();
+ ldifEntries = reader.parseLdif( sb.toString() );
}
catch ( IOException e )
{
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/extended/NoticeOfDisconnect.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/extended/NoticeOfDisconnect.java
index e75ef1e..37b5b9c 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/extended/NoticeOfDisconnect.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/message/extended/NoticeOfDisconnect.java
@@ -163,15 +163,19 @@ public final class NoticeOfDisconnect extends AbstractExtendedResponse
{
case UNAVAILABLE:
nod = UNAVAILABLE;
+ break;
case PROTOCOL_ERROR:
nod = PROTOCOLERROR;
+ break;
case STRONG_AUTH_REQUIRED:
nod = STRONGAUTHREQUIRED;
+ break;
default:
nod = new NoticeOfDisconnect( rcode );
+ break;
}
nod.getLdapResult().setDiagnosticMessage( rcode.toString() + ": The server will disconnect!" );
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
index 342ee76..0d5e9a4 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/name/Rdn.java
@@ -1411,8 +1411,9 @@ public class Rdn implements Cloneable, Externalizable, Iterable<Ava>, Comparable
{
// '#' are allowed if not in first position
bytes[pos++] = '#';
- break;
}
+
+ break;
case ' ':
if ( ( i == 0 ) || ( i == chars.length - 1 ) )
diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/password/BCrypt.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/password/BCrypt.java
index 145252b..f32c7bc 100644
--- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/password/BCrypt.java
+++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/password/BCrypt.java
@@ -884,7 +884,7 @@ public class BCrypt
* 2**log_rounds.
* @return an encoded salt value
*/
- public static String gensalt( int logRounds )
+ public static String genSalt( int logRounds )
{
return genSalt( logRounds, new SecureRandom() );
}
@@ -898,7 +898,7 @@ public class BCrypt
*/
public static String genSalt()
{
- return gensalt( GENSALT_DEFAULT_LOG2_ROUNDS );
+ return genSalt( GENSALT_DEFAULT_LOG2_ROUNDS );
}