diff --git a/core/src/main/java/org/springframework/ldap/config/ContextSourceParser.java b/core/src/main/java/org/springframework/ldap/config/ContextSourceParser.java index 0eb43fbb..68caef05 100644 --- a/core/src/main/java/org/springframework/ldap/config/ContextSourceParser.java +++ b/core/src/main/java/org/springframework/ldap/config/ContextSourceParser.java @@ -197,7 +197,7 @@ public class ContextSourceParser implements BeanDefinitionParser { try { nonTransientExceptionClasses.add(ClassUtils.getDefaultClassLoader().loadClass(className)); } catch (ClassNotFoundException e) { - throw new IllegalArgumentException(String.format("%s is not a valid class name", className)); + throw new IllegalArgumentException(String.format("%s is not a valid class name", className), e); } } diff --git a/core/src/main/java/org/springframework/ldap/core/DistinguishedName.java b/core/src/main/java/org/springframework/ldap/core/DistinguishedName.java index f2bc687e..87862556 100644 --- a/core/src/main/java/org/springframework/ldap/core/DistinguishedName.java +++ b/core/src/main/java/org/springframework/ldap/core/DistinguishedName.java @@ -15,6 +15,7 @@ */ package org.springframework.ldap.core; +import org.springframework.ldap.UncategorizedLdapException; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.slf4j.Logger; @@ -536,7 +537,7 @@ public class DistinguishedName implements Name { } catch (CloneNotSupportedException e) { log.error("CloneNotSupported thrown from superclass - this should not happen"); - throw new RuntimeException("Fatal error in clone", e); + throw new UncategorizedLdapException("Fatal error in clone", e); } } diff --git a/core/src/main/java/org/springframework/ldap/core/LdapOperations.java b/core/src/main/java/org/springframework/ldap/core/LdapOperations.java index 326e2f9b..d94214f0 100644 --- a/core/src/main/java/org/springframework/ldap/core/LdapOperations.java +++ b/core/src/main/java/org/springframework/ldap/core/LdapOperations.java @@ -1811,7 +1811,7 @@ public interface LdapOperations { * @throws org.springframework.ldap.NamingException on error. * @since 2.0 */ - public List find(Name base, Filter filter, SearchControls searchControls, Class clazz); + List find(Name base, Filter filter, SearchControls searchControls, Class clazz); /** * Search for entries in the LDAP directory. The referenced class must have object-directory diff --git a/core/src/main/java/org/springframework/ldap/core/NameAwareAttribute.java b/core/src/main/java/org/springframework/ldap/core/NameAwareAttribute.java index 6c4c53e5..eaf482d8 100644 --- a/core/src/main/java/org/springframework/ldap/core/NameAwareAttribute.java +++ b/core/src/main/java/org/springframework/ldap/core/NameAwareAttribute.java @@ -163,7 +163,7 @@ public final class NameAwareAttribute implements Attribute { newValuesAsNames.put(LdapUtils.newLdapName(s), s); } catch (InvalidNameException e) { throw new IllegalArgumentException("This instance has values that are not valid distinguished names; " + - "cannot handle Name values"); + "cannot handle Name values", e); } } else { throw new IllegalArgumentException("This instance has non-string attribute values; " + diff --git a/core/src/main/java/org/springframework/ldap/filter/BinaryLogicalFilter.java b/core/src/main/java/org/springframework/ldap/filter/BinaryLogicalFilter.java index 348c15fd..862baa13 100644 --- a/core/src/main/java/org/springframework/ldap/filter/BinaryLogicalFilter.java +++ b/core/src/main/java/org/springframework/ldap/filter/BinaryLogicalFilter.java @@ -27,7 +27,7 @@ import java.util.List; */ public abstract class BinaryLogicalFilter extends AbstractFilter { - protected List queryList = new LinkedList(); + private List queryList = new LinkedList(); public StringBuffer encode(StringBuffer buff) { if (queryList.size() <= 0) { @@ -47,7 +47,7 @@ public abstract class BinaryLogicalFilter extends AbstractFilter { buff.append("(").append(getLogicalOperator()); for (Filter query : queryList) { - buff = query.encode(buff); + query.encode(buff); } buff.append(")"); diff --git a/core/src/main/java/org/springframework/ldap/filter/WhitespaceWildcardsFilter.java b/core/src/main/java/org/springframework/ldap/filter/WhitespaceWildcardsFilter.java index 92fc96ac..c0c93cdc 100644 --- a/core/src/main/java/org/springframework/ldap/filter/WhitespaceWildcardsFilter.java +++ b/core/src/main/java/org/springframework/ldap/filter/WhitespaceWildcardsFilter.java @@ -49,11 +49,8 @@ public class WhitespaceWildcardsFilter extends EqualsFilter { return "*"; } - // trim value, we will add in stars first and last anywhay - value = value.trim(); - // filter encode so that any stars etc. are preserved - String filterEncoded = LdapEncoder.filterEncode(value); + String filterEncoded = LdapEncoder.filterEncode(value.trim()); // Now replace all whitespace with stars Matcher m = starReplacePattern.matcher(filterEncoded); diff --git a/core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java b/core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java index dc117165..5b716ee5 100644 --- a/core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java +++ b/core/src/main/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapper.java @@ -130,7 +130,7 @@ public class DefaultObjectDirectoryMapper implements ObjectDirectoryMapper { managedClass.getConstructor(); } catch (NoSuchMethodException e) { throw new InvalidEntryException(String.format( - "The class %1$s must have a zero argument constructor to be an Entry", managedClass)); + "The class %1$s must have a zero argument constructor to be an Entry", managedClass), e); } // Check we have all of the necessary converters for the class diff --git a/odm/src/main/java/org/springframework/ldap/odm/tools/SchemaToJava.java b/odm/src/main/java/org/springframework/ldap/odm/tools/SchemaToJava.java index 52654d96..66b21763 100755 --- a/odm/src/main/java/org/springframework/ldap/odm/tools/SchemaToJava.java +++ b/odm/src/main/java/org/springframework/ldap/odm/tools/SchemaToJava.java @@ -316,9 +316,9 @@ public final class SchemaToJava { directory.mkdirs(); outputFile.createNewFile(); } catch (SecurityException se) { - throw new IOException(String.format("Can't write to output file %1$s", outputFile.getAbsoluteFile())); + throw new IOException(String.format("Can't write to output file %1$s", outputFile.getAbsoluteFile()), se); } catch (IOException ioe) { - throw new IOException(String.format("Can't write to output file %1$s", outputFile.getAbsoluteFile())); + throw new IOException(String.format("Can't write to output file %1$s", outputFile.getAbsoluteFile()), ioe); } return outputFile; diff --git a/test-support/src/main/java/org/springframework/ldap/test/LdapTestUtils.java b/test-support/src/main/java/org/springframework/ldap/test/LdapTestUtils.java index adbcc8ff..e0948daf 100644 --- a/test-support/src/main/java/org/springframework/ldap/test/LdapTestUtils.java +++ b/test-support/src/main/java/org/springframework/ldap/test/LdapTestUtils.java @@ -19,7 +19,10 @@ package org.springframework.ldap.test; import org.apache.commons.io.IOUtils; import org.apache.directory.server.core.DefaultDirectoryService; import org.apache.directory.server.protocol.shared.store.LdifFileLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; +import org.springframework.ldap.UncategorizedLdapException; import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.core.LdapAttributes; import org.springframework.ldap.core.support.DefaultDirObjectFactory; @@ -46,6 +49,7 @@ import java.util.Set; * @author Mattias Hellborg Arthursson */ public final class LdapTestUtils { + private final static Logger logger = LoggerFactory.getLogger(LdapTestUtils.class); public static final String DEFAULT_PRINCIPAL = "uid=admin,ou=system"; public static final String DEFAULT_PASSWORD = "secret"; @@ -103,7 +107,7 @@ public final class LdapTestUtils { try { embeddedServer = EmbeddedLdapServer.newEmbeddedServer(defaultPartitionName, defaultPartitionSuffix, port); } catch (Exception e) { - throw new RuntimeException("Failed to start embedded server"); + throw new UncategorizedLdapException("Failed to start embedded server", e); } } @@ -190,7 +194,7 @@ public final class LdapTestUtils { } } } catch (NamingException e) { - e.printStackTrace(); + logger.debug("Error cleaning sub-contexts", e); } finally { try { enumeration.close(); @@ -254,7 +258,7 @@ public final class LdapTestUtils { context.bind(dn, null, record); } } catch (Exception e) { - throw new RuntimeException("Failed to populate LDIF", e); + throw new UncategorizedLdapException("Failed to populate LDIF", e); } }