java.lang.IllegalStateException: No value for key [org.springframework.ldap.pool.factory.PoolingContextSource@2b30a42c] bound to thread [main]

Spring JIRA | cleverpig | 2 years ago
  1. 0

    No value for key exception: Spring ldap's ContextSourceTransactionManager call doCleanupAfterCompletion method twice When transaction was rollback

    Stack Overflow | 2 years ago
    java.lang.IllegalStateException: No value for key [org.springframework.ldap.pool.factory.PoolingContextSource@2b30a42c] bound to thread [main]
  2. 0

    I created a Test with spring test context: {code:java} @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( locations={"classpath:applicationContext.xml"} ) @TransactionConfiguration(transactionManager = "txManager",defaultRollback = true) @Transactional public class RoleRepoImplTest{ @Autowired private RoleRepo roleRepo; private Logger log= LoggerFactory.getLogger(RoleRepoImplTest.class); @Test public void testQueryRoleMap() throws Exception { Map<String,String> roleMap=roleRepo.queryRoleMap(); assertNotNull(roleMap); for(String roleName:roleMap.keySet()){ log.debug("{}:{}",roleName,roleMap.get(roleName)); } } {code} But I ran this test,exception will throw: {noformat} 14:40:21,073 DEBUG AbstractCompensatingTransactionManagerDelegate:120 - Cleaning stored transaction synchronization 14:40:21,077 WARN TestContextManager:409 - Caught exception while allowing TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener@480d3575] to process 'after' execution for test: method [public void com.bjinfotech.tri.cas.manager.repository.impl.RoleRepoImplTest.testQueryRoleMap() throws java.lang.Exception], instance [com.bjinfotech.tri.cas.manager.repository.impl.RoleRepoImplTest@17f6480], exception [null] java.lang.IllegalStateException: No value for key [org.springframework.ldap.pool.factory.PoolingContextSource@2b30a42c] bound to thread [main] at org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(TransactionSynchronizationManager.java:209) at org.springframework.transaction.compensating.support.AbstractCompensatingTransactionManagerDelegate.doCleanupAfterCompletion(AbstractCompensatingTransactionManagerDelegate.java:121) at org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager.doCleanupAfterCompletion(ContextSourceTransactionManager.java:133) at org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:1008) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:875) at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:822) at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.endTransaction(TransactionalTestExecutionListener.java:518) at org.springframework.test.context.transaction.TransactionalTestExecutionListener.endTransaction(TransactionalTestExecutionListener.java:292) at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:185) at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:406) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:91) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.junit.runner.JUnitCore.run(JUnitCore.java:157) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) 14:40:21,188 DEBUG DirtiesContextTestExecutionListener:86 - After test method: context [[TestContext@6fadae5d testClass = RoleRepoImplTest, testInstance = com.bjinfotech.tri.cas.manager.repository.impl.RoleRepoImplTest@17f6480, testMethod = testQueryRoleMap@RoleRepoImplTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@2d6e8792 testClass = RoleRepoImplTest, locations = '{classpath:applicationContext-for-test.xml}', classes = '{}', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader']]], class dirties context [false], class mode [null], method dirties context [false]. {noformat} I debuged code,and found when the transaction begin rollback,ContextSourceTransactionManager call doCleanupAfterCompletion method twice:one was called by itself,and another was called by TransactionalTestExecutionListener.

    Spring JIRA | 2 years ago | cleverpig
    java.lang.IllegalStateException: No value for key [org.springframework.ldap.pool.factory.PoolingContextSource@2b30a42c] bound to thread [main]
  3. 0

    I created a Test with spring test context: {code:java} @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( locations={"classpath:applicationContext.xml"} ) @TransactionConfiguration(transactionManager = "txManager",defaultRollback = true) @Transactional public class RoleRepoImplTest{ @Autowired private RoleRepo roleRepo; private Logger log= LoggerFactory.getLogger(RoleRepoImplTest.class); @Test public void testQueryRoleMap() throws Exception { Map<String,String> roleMap=roleRepo.queryRoleMap(); assertNotNull(roleMap); for(String roleName:roleMap.keySet()){ log.debug("{}:{}",roleName,roleMap.get(roleName)); } } {code} But I ran this test,exception will throw: {noformat} 14:40:21,073 DEBUG AbstractCompensatingTransactionManagerDelegate:120 - Cleaning stored transaction synchronization 14:40:21,077 WARN TestContextManager:409 - Caught exception while allowing TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener@480d3575] to process 'after' execution for test: method [public void com.bjinfotech.tri.cas.manager.repository.impl.RoleRepoImplTest.testQueryRoleMap() throws java.lang.Exception], instance [com.bjinfotech.tri.cas.manager.repository.impl.RoleRepoImplTest@17f6480], exception [null] java.lang.IllegalStateException: No value for key [org.springframework.ldap.pool.factory.PoolingContextSource@2b30a42c] bound to thread [main] at org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(TransactionSynchronizationManager.java:209) at org.springframework.transaction.compensating.support.AbstractCompensatingTransactionManagerDelegate.doCleanupAfterCompletion(AbstractCompensatingTransactionManagerDelegate.java:121) at org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager.doCleanupAfterCompletion(ContextSourceTransactionManager.java:133) at org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:1008) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:875) at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:822) at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.endTransaction(TransactionalTestExecutionListener.java:518) at org.springframework.test.context.transaction.TransactionalTestExecutionListener.endTransaction(TransactionalTestExecutionListener.java:292) at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:185) at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:406) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:91) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.junit.runner.JUnitCore.run(JUnitCore.java:157) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) 14:40:21,188 DEBUG DirtiesContextTestExecutionListener:86 - After test method: context [[TestContext@6fadae5d testClass = RoleRepoImplTest, testInstance = com.bjinfotech.tri.cas.manager.repository.impl.RoleRepoImplTest@17f6480, testMethod = testQueryRoleMap@RoleRepoImplTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@2d6e8792 testClass = RoleRepoImplTest, locations = '{classpath:applicationContext-for-test.xml}', classes = '{}', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader']]], class dirties context [false], class mode [null], method dirties context [false]. {noformat} I debuged code,and found when the transaction begin rollback,ContextSourceTransactionManager call doCleanupAfterCompletion method twice:one was called by itself,and another was called by TransactionalTestExecutionListener.

    Spring JIRA | 2 years ago | cleverpig
    java.lang.IllegalStateException: No value for key [org.springframework.ldap.pool.factory.PoolingContextSource@2b30a42c] bound to thread [main]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    No value for key [org.springframework.ldap.core.support.LdapContextSource@27bd27bd] bound to thread [main]

    Stack Overflow | 2 years ago | Santhoshkumar R
    java.lang.IllegalStateException: No value for key [org.springframework.ldap.core.support.LdapContextSource@27bd27bd] bound to thread [main]
  6. 0

    java.lang.IllegalStateException: No value for key bound to thread

    Stack Overflow | 4 years ago | jurma
    java.lang.IllegalStateException: No value for key [org.hibernate.impl.SessionFactoryImpl@1ff8c2a] bound to thread ["http-apr-83"-exec-3]

    8 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      No value for key [org.springframework.ldap.pool.factory.PoolingContextSource@2b30a42c] bound to thread [main]

      at org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource()
    2. Spring Tx
      TransactionSynchronizationManager.unbindResource
      1. org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(TransactionSynchronizationManager.java:209)
      1 frame
    3. spring-ldap-core
      ContextSourceTransactionManager.doCleanupAfterCompletion
      1. org.springframework.transaction.compensating.support.AbstractCompensatingTransactionManagerDelegate.doCleanupAfterCompletion(AbstractCompensatingTransactionManagerDelegate.java:121)
      2. org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager.doCleanupAfterCompletion(ContextSourceTransactionManager.java:133)
      2 frames
    4. Spring Tx
      AbstractPlatformTransactionManager.rollback
      1. org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:1008)
      2. org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:875)
      3. org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:822)
      3 frames
    5. Spring TestContext
      SpringJUnit4ClassRunner.runChild
      1. org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.endTransaction(TransactionalTestExecutionListener.java:518)
      2. org.springframework.test.context.transaction.TransactionalTestExecutionListener.endTransaction(TransactionalTestExecutionListener.java:292)
      3. org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:185)
      4. org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:406)
      5. org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:91)
      6. org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
      7. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
      7 frames
    6. JUnit
      ParentRunner$2.evaluate
      1. org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
      2. org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
      3. org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
      4. org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
      5. org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
      6. org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
      6 frames
    7. Spring TestContext
      RunAfterTestClassCallbacks.evaluate
      1. org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      2. org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
      2 frames
    8. JUnit
      ParentRunner.run
      1. org.junit.runners.ParentRunner.run(ParentRunner.java:236)
      1 frame
    9. Spring TestContext
      SpringJUnit4ClassRunner.run
      1. org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
      1 frame
    10. JUnit
      JUnitCore.run
      1. org.junit.runner.JUnitCore.run(JUnitCore.java:157)
      1 frame
    11. IntelliJ junit4 module
      JUnit4IdeaTestRunner.startRunnerWithArgs
      1. com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
      1 frame
    12. IDEA
      JUnitStarter.main
      1. com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
      2. com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
      2 frames
    13. Java RT
      Method.invoke
      1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      4. java.lang.reflect.Method.invoke(Method.java:497)
      4 frames
    14. IDEA
      AppMain.main
      1. com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
      1 frame