[SJN-73] Using shared memory (org.osjava.sj.jndi.shared=true) causes javax.naming.NameAlreadyBoundException | |
| Status: | Closed |
| Project: | Simple-JNDI |
| Component/s: | |
| Affects Version/s: | 0.11.1 |
| Fix Version/s: | 0.11.3 |
| Type: | Bug | Priority: | Major |
| Reporter: | Morten Hattesen | Assignee: | Henri Yandell |
| Resolution: | Fixed | ||
| Environment: | Windows XP; JRE 1.4.2_06 (and 1.5.0) | ||
| Description |
| Using shared memory (org.osjava.sj.jndi.shared=true) causes a javax.naming.NameAlreadyBoundException to occur when instantiating an InitialContext object for the second time, since it seems org.osjava.sj.SimpleContext attempts to reload the jndi values into the already initialized StaticHashTable on subsequent instantiations. Reproduce by inserting this method into org.osjava.sj.SimpleContextTest testcase: public void testSharedMemory() throws Exception { String propShared = "org.osjava.sj.jndi.shared"; System.setProperty(propShared, "true"); Context ctx = new InitialContext(); assertNotNull(ctx.lookup("test.value")); Context ctx1 = new InitialContext(); assertNotNull(ctx1.lookup("test.value")); System.getProperties().remove(propShared); } Running the above test method results in this stack trace: javax.naming.NameAlreadyBoundException at org.osjava.sj.memory.MemoryContext.createSubcontext(MemoryContext.java:159) at org.osjava.sj.jndi.AbstractContext.createSubcontext(AbstractContext.java:590) at javax.naming.InitialContext.createSubcontext(InitialContext.java:413) at org.osjava.sj.jndi.DelegatingContext.createSubcontext(DelegatingContext.java:124) at org.osjava.sj.loader.JndiLoader.loadDirectory(JndiLoader.java:138) at org.osjava.sj.loader.JndiLoader.loadDirectory(JndiLoader.java:104) at org.osjava.sj.SimpleContext.<init>(SimpleContext.java:96) at org.osjava.sj.SimpleContextFactory.getInitialContext(SimpleContextFactory.java:69) at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243) at javax.naming.InitialContext.init(InitialContext.java:219) at javax.naming.InitialContext.<init>(InitialContext.java:175) at org.osjava.sj.SimpleContextTest.setUp(SimpleContextTest.java:56) at junit.framework.TestCase.runBare(TestCase.java:125) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) |
| Comment by mortenhattesen [ Tue, 15 Nov 2005 06:53:18 -0800 (PST) ] |
| Simply adding this line... org.osjava.sj.jndi.shared=true ... to the jndi.properties file associated with the testcases org.osjava.sj.SimpleContextTest results in a different Exception when running the (unmodified) test case: javax.naming.NotContextException at org.osjava.sj.jndi.AbstractContext.destroySubcontext(AbstractContext.java:529) at org.osjava.sj.jndi.AbstractContext.destroySubcontext(AbstractContext.java:549) at org.osjava.sj.loader.JndiLoader.jndiPut(JndiLoader.java:315) at org.osjava.sj.loader.JndiLoader.load(JndiLoader.java:276) at org.osjava.sj.loader.JndiLoader.loadDirectory(JndiLoader.java:155) at org.osjava.sj.loader.JndiLoader.loadDirectory(JndiLoader.java:139) at org.osjava.sj.loader.JndiLoader.loadDirectory(JndiLoader.java:104) at org.osjava.sj.SimpleContext.<init>(SimpleContext.java:96) at org.osjava.sj.SimpleContextFactory.getInitialContext(SimpleContextFactory.java:69) at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243) at javax.naming.InitialContext.init(InitialContext.java:219) at javax.naming.InitialContext.<init>(InitialContext.java:175) at org.osjava.sj.SimpleContextTest.setUp(SimpleContextTest.java:56) at junit.framework.TestCase.runBare(TestCase.java:125) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) |
| Comment by bayard [ Sun, 6 Apr 2008 01:11:54 -0700 (PDT) ] |
| The main issue is, I believe, fixed:
r2670 | flamefew | 2008-04-05 21:50:13 -0700 (Sat, 05 Apr 2008) | 1 line Changed paths: M /trunk/simple-jndi/src/java/org/osjava/sj/SimpleContext.java M /trunk/simple-jndi/src/java/org/osjava/sj/jndi/AbstractContext.java Fixing ------------------------------------------------------------------------ r2669 | flamefew | 2008-04-05 21:49:44 -0700 (Sat, 05 Apr 2008) | 1 line Changed paths: M /trunk/simple-jndi/src/test/org/osjava/sj/memory/SharedMemoryTest.java Adding unit test for Making the jndi.properties for all the tests be shared is not; but I think that is because many of the tests are not expecting a shared context. |