Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 086497d

Browse files
committed
Minor cleanup.
1 parent f89daf6 commit 086497d

File tree

9 files changed

+18
-16
lines changed

9 files changed

+18
-16
lines changed

core/src/main/java/org/springframework/ldap/config/ContextSourceParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private void populatePoolValidationProperties(BeanDefinitionBuilder builder, Ele
197197
try {
198198
nonTransientExceptionClasses.add(ClassUtils.getDefaultClassLoader().loadClass(className));
199199
} catch (ClassNotFoundException e) {
200-
throw new IllegalArgumentException(String.format("%s is not a valid class name", className));
200+
throw new IllegalArgumentException(String.format("%s is not a valid class name", className), e);
201201
}
202202
}
203203

core/src/main/java/org/springframework/ldap/core/DistinguishedName.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.ldap.core;
1717

18+
import org.springframework.ldap.UncategorizedLdapException;
1819
import org.springframework.util.ObjectUtils;
1920
import org.springframework.util.StringUtils;
2021
import org.slf4j.Logger;
@@ -536,7 +537,7 @@ public Object clone() {
536537
}
537538
catch (CloneNotSupportedException e) {
538539
log.error("CloneNotSupported thrown from superclass - this should not happen");
539-
throw new RuntimeException("Fatal error in clone", e);
540+
throw new UncategorizedLdapException("Fatal error in clone", e);
540541
}
541542
}
542543

core/src/main/java/org/springframework/ldap/core/LdapOperations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ boolean authenticate(String base, String filter, String password,
18111811
* @throws org.springframework.ldap.NamingException on error.
18121812
* @since 2.0
18131813
*/
1814-
public <T> List<T> find(Name base, Filter filter, SearchControls searchControls, Class<T> clazz);
1814+
<T> List<T> find(Name base, Filter filter, SearchControls searchControls, Class<T> clazz);
18151815

18161816
/**
18171817
* Search for entries in the LDAP directory. The referenced class must have object-directory

core/src/main/java/org/springframework/ldap/core/NameAwareAttribute.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public void initValuesAsNames() {
163163
newValuesAsNames.put(LdapUtils.newLdapName(s), s);
164164
} catch (InvalidNameException e) {
165165
throw new IllegalArgumentException("This instance has values that are not valid distinguished names; " +
166-
"cannot handle Name values");
166+
"cannot handle Name values", e);
167167
}
168168
} else {
169169
throw new IllegalArgumentException("This instance has non-string attribute values; " +

core/src/main/java/org/springframework/ldap/filter/BinaryLogicalFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
public abstract class BinaryLogicalFilter extends AbstractFilter {
2929

30-
protected List<Filter> queryList = new LinkedList<Filter>();
30+
private List<Filter> queryList = new LinkedList<Filter>();
3131

3232
public StringBuffer encode(StringBuffer buff) {
3333
if (queryList.size() <= 0) {
@@ -47,7 +47,7 @@ else if (queryList.size() == 1) {
4747
buff.append("(").append(getLogicalOperator());
4848

4949
for (Filter query : queryList) {
50-
buff = query.encode(buff);
50+
query.encode(buff);
5151
}
5252

5353
buff.append(")");

core/src/main/java/org/springframework/ldap/filter/WhitespaceWildcardsFilter.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ protected String encodeValue(String value) {
4949
return "*";
5050
}
5151

52-
// trim value, we will add in stars first and last anywhay
53-
value = value.trim();
54-
5552
// filter encode so that any stars etc. are preserved
56-
String filterEncoded = LdapEncoder.filterEncode(value);
53+
String filterEncoded = LdapEncoder.filterEncode(value.trim());
5754

5855
// Now replace all whitespace with stars
5956
Matcher m = starReplacePattern.matcher(filterEncoded);

core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private EntityData addManagedClass(Class<?> managedClass) {
130130
managedClass.getConstructor();
131131
} catch (NoSuchMethodException e) {
132132
throw new InvalidEntryException(String.format(
133-
"The class %1$s must have a zero argument constructor to be an Entry", managedClass));
133+
"The class %1$s must have a zero argument constructor to be an Entry", managedClass), e);
134134
}
135135

136136
// Check we have all of the necessary converters for the class

odm/src/main/java/org/springframework/ldap/odm/tools/SchemaToJava.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,9 @@ private static File makeOutputFile(String outputDir, String packageName, String
316316
directory.mkdirs();
317317
outputFile.createNewFile();
318318
} catch (SecurityException se) {
319-
throw new IOException(String.format("Can't write to output file %1$s", outputFile.getAbsoluteFile()));
319+
throw new IOException(String.format("Can't write to output file %1$s", outputFile.getAbsoluteFile()), se);
320320
} catch (IOException ioe) {
321-
throw new IOException(String.format("Can't write to output file %1$s", outputFile.getAbsoluteFile()));
321+
throw new IOException(String.format("Can't write to output file %1$s", outputFile.getAbsoluteFile()), ioe);
322322
}
323323

324324
return outputFile;

test-support/src/main/java/org/springframework/ldap/test/LdapTestUtils.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
import org.apache.commons.io.IOUtils;
2020
import org.apache.directory.server.core.DefaultDirectoryService;
2121
import org.apache.directory.server.protocol.shared.store.LdifFileLoader;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
2224
import org.springframework.core.io.Resource;
25+
import org.springframework.ldap.UncategorizedLdapException;
2326
import org.springframework.ldap.core.ContextSource;
2427
import org.springframework.ldap.core.LdapAttributes;
2528
import org.springframework.ldap.core.support.DefaultDirObjectFactory;
@@ -46,6 +49,7 @@
4649
* @author Mattias Hellborg Arthursson
4750
*/
4851
public final class LdapTestUtils {
52+
private final static Logger logger = LoggerFactory.getLogger(LdapTestUtils.class);
4953

5054
public static final String DEFAULT_PRINCIPAL = "uid=admin,ou=system";
5155
public static final String DEFAULT_PASSWORD = "secret";
@@ -103,7 +107,7 @@ public static void startEmbeddedServer(int port, String defaultPartitionSuffix,
103107
try {
104108
embeddedServer = EmbeddedLdapServer.newEmbeddedServer(defaultPartitionName, defaultPartitionSuffix, port);
105109
} catch (Exception e) {
106-
throw new RuntimeException("Failed to start embedded server");
110+
throw new UncategorizedLdapException("Failed to start embedded server", e);
107111
}
108112
}
109113

@@ -190,7 +194,7 @@ public static void clearSubContexts(DirContext ctx, Name name) throws NamingExce
190194
}
191195
}
192196
} catch (NamingException e) {
193-
e.printStackTrace();
197+
logger.debug("Error cleaning sub-contexts", e);
194198
} finally {
195199
try {
196200
enumeration.close();
@@ -254,7 +258,7 @@ private static void loadLdif(DirContext context, Name rootNode, Resource ldifFil
254258
context.bind(dn, null, record);
255259
}
256260
} catch (Exception e) {
257-
throw new RuntimeException("Failed to populate LDIF", e);
261+
throw new UncategorizedLdapException("Failed to populate LDIF", e);
258262
}
259263
}
260264

0 commit comments

Comments
 (0)