spring-ldap
spring-ldap copied to clipboard
java.lang.reflect.UndeclaredThrowableException with spring-ldap-core 2.3.2.RELEASE and above
I am using the following version of Java:
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-8u312-b07-0ubuntu1~18.04-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)
When I make the following lookup using StartTLS with spring-ldap-core 2.3.1.RELEASE for a non existent dn:
DefaultTlsDirContextAuthenticationStrategy tlsAuthStratagy = new DefaultTlsDirContextAuthenticationStrategy();
tlsAuthStratagy.setShutdownTlsGracefully(true);
contextSource.setAuthenticationStrategy(tlsAuthStratagy);
PoolingContextSource poolingContextSource = new PoolingContextSource();
poolingContextSource.setMaxActive(5);
poolingContextSource.setContextSource(contextSource);
proxy = new TransactionAwareContextSourceProxy(poolingContextSource);
LdapTemplate ldapTemplate = new LdapTemplate(proxy);
ldapTemplate.lookup(dn);
I receive the following exception as expected:
org.springframework.ldap.NameNotFoundException
However, from spring-ldap-core 2.3.2.RELEASE and above, I received the following exception:
java.lang.reflect.UndeclaredThrowableException
This only happens when I attempt to use StartTLS ie. call setAuthenticationStrategy().
Thanks for the report, @aplatt. The only commit I can see between those two releases that may be related is c0def8583fd888acbc154192083db47dfb42dc06.
I have not been able to reproduce this yet, though I imagine it has something to do with the above arrangement is propagating exceptions. Does the UndeclaredThrowableException have a caused by or anything else that indicates what its cause is? Or, are you able to produce a GitHub sample that demonstrates the error?
Yes, the cause is actually the exception that was thrown prior to spring-ldap-core 2.3.2.RELEASE. It appears that all the LDAP exceptions thrown prior to spring-ldap-core 2.3.2.RELEASE have been translated to java.lang.reflect.UndeclaredThrowableException exceptions with the cause being the original exception. Only when using StartTLS (see original code snippet above).
Caused by: javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3286)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3207)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2998)
at com.sun.jndi.ldap.LdapCtx.c_rename(LdapCtx.java:755)
at com.sun.jndi.toolkit.ctx.ComponentContext.p_rename(ComponentContext.java:709)
at com.sun.jndi.toolkit.ctx.PartialCompositeContext.rename(PartialCompositeContext.java:269)
at javax.naming.InitialContext.rename(InitialContext.java:455)
@aplatt Were you able to resolve this? With 3.3.2 the cause seems to be null
I stayed with 2.3.1.RELEASE which didn't have the problem.