SJN-77 problem

2 views
Skip to first unread message

bulente

unread,
Feb 17, 2008, 6:15:16 AM2/17/08
to osjava
Hi, using the MemoryContext, simplejndi throws a ClassCastException
during the close() call as explained in the issue
http://issues.osjava.org/jira/browse/SJN-77 .

I traced the problem and saw that the code assumes that there're
Thread objects bound to JNDI. I wonder why this is so.

Can anybody comment on how to fix this issue ?

Regards,
Bulent Erdemir


Comment from the JIRA:
==================

Hi, the problem is in the AbstractContext's close() method. This
method iterates through the internal HashTable (called table) in which
it holds the JNDI bound objects. And while iterating it casts each
object from this table to a Thread and tries to see it the thread's
are alive by calling isAlive() on them.

So, obviously, if you've bound an object to the JNDI which is NOT a
Thread, then the cast operation fails. Here's the code:

while(table.size() > 0 || subContexts.size() > 0) {
it = table.keySet().iterator();
while(it.hasNext()) {
Name name = (Name)it.next();
if(!((Thread)table.get(name)).isAlive()) {
table.remove(name);
}
}

I don't understand why the author does this (Thread casting and
calling isAlive()), however, this is the cause of your problem. And
mine, too... :)

Here's a JUnit 4 test to reproduce the problem:

package org.falez.falez.jndi.test;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.junit.Before;
import org.junit.Test;

public class TestMemoryContext {
InitialContext ic;
@Before
public void setup() throws NamingException {
System.setProperty("java.naming.factory.initial",
"org.osjava.sj.memory.MemoryContextFactory");
ic = new InitialContext();
}
@Test
public void testPut() throws NamingException {
String name = "falez:/hoba";
String value = "hoba1";
ic.bind(name, value);
String result = (String) ic.lookup(name);
ic.close();
}
}

Henri Yandell

unread,
Mar 22, 2008, 1:30:40 PM3/22/08
to osj...@googlegroups.com
I've put in protection from the ClassCast as a first step, and fixed
the NotContextException in shared mode.

Question being - what should be in the close() method. Robert, still around?

Hen

Robert M. Zigweid

unread,
Mar 23, 2008, 4:18:03 PM3/23/08
to osj...@googlegroups.com
Robert is currently swamped at work, but I'll see if I can get to this
in the coming week when a couple of my work projects are finished.

My apologies for the delays here.

Reply all
Reply to author
Forward
0 new messages