Keith McNeill wrote: > I sorted out the problem. Which took quite awhile...but I'll get to > that later. The problem was that in: > > org.apache.mina.example.proxy.AbstractProxyIoHandler: > > public void sessionClosed( IoSession session ) throws Exception > { > if( session.getAttachment() != null ) > { > ( ( IoSession ) session.getAttachment() ).setAttachment( > null ); > ( ( IoSession ) session.getAttachment() ).close(); > session.setAttachment( null ); > } > } > > The call to session.setAttachemnt(null) throws an NullPointerException. > > In Mina 1.0 the backing Map for Attributes/Attachements is a HashMap. > In 1.1 it is a ConcurrentHashMap. ConcurrentHashMap throws a NPE > when one tries to put a null value into the map. HashMaps do not. > > There are a few ways to fix this...not sure what the mina folks want > to do: > > - special case nulls in setAttaachement() > - add a removeAttachement() call, like removeAttribute() > - change the backing map
1.1 must be compatible with 1.0 (i.e. allow null in call to setAttachment()) so either the first or last would be the appropriate alternatives. I'm not sure why 1.1 uses a ConcurrentHashMap when 1.0 uses a HashMap. Since the same Map is used to store all attributes I guess the use of ConcurrentHashMap could cause other incompatibilities, e.g. if someone uses null as an attribute name. That would work in 1.0 but not in 1.1. Though null isn't a very good attribute name and I'm sure no one does that. Could you add this to JIRA perhaps? > > This was hard to find because the NPE was being eaten. I added > logging filters to the app, but didn't do anything with the IO > adapters. Once I implemented exceptionCaught() in > AbstractProxyIoHandler, it was easy to find the problem. I think that > the default action for exceptionCaught should be to report the error > (in IoHandlerAdapter, and other places). Force people to turn it off > once they have figured things out. It will make debugging a lot easier. I think it's weird that the logging filter didn't see the exception. I think it should have so that could be a bug. Any one else out there who knows why it doesn't see it? Thanks for letting us know about these problems! -- Niklas Therning www.spamdrain.net