diff -r e126d8eca69b -r b0c2840e2513 src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/property/SingleMapNodeProperty.java --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/property/SingleMapNodeProperty.java Thu Oct 31 12:36:20 2013 -0700 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/property/SingleMapNodeProperty.java Fri Nov 22 21:11:19 2013 +0100 @@ -42,7 +42,6 @@ import com.sun.xml.internal.bind.v2.ClassFactory; import com.sun.xml.internal.bind.v2.util.QNameMap; import com.sun.xml.internal.bind.v2.model.core.PropertyKind; -import com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator; import com.sun.xml.internal.bind.v2.model.runtime.RuntimeMapPropertyInfo; import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl; import com.sun.xml.internal.bind.v2.runtime.JaxBeanInfo; @@ -98,7 +97,8 @@ this.valueBeanInfo = context.getOrCreate(prop.getValueType()); // infer the implementation class - Class sig = ReflectionNavigator.REFLECTION.erasure(prop.getRawType()); + //noinspection unchecked + Class sig = (Class) Utils.REFLECTION_NAVIGATOR.erasure(prop.getRawType()); mapImplClass = ClassFactory.inferImplClass(sig,knownImplClasses); // TODO: error check for mapImplClass==null // what is the error reporting path for this part of the code? @@ -140,23 +140,22 @@ */ private final Loader itemsLoader = new Loader(false) { - private ThreadLocal> target = new ThreadLocal>(); - private ThreadLocal> map = new ThreadLocal>(); + private ThreadLocal target = new ThreadLocal(); + private ThreadLocal map = new ThreadLocal(); + private int depthCounter = 0; // needed to clean ThreadLocals @Override public void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException { // create or obtain the Map object try { - BeanT target = (BeanT) state.prev.target; - ValueT mapValue = acc.get(target); - if(mapValue == null) - mapValue = ClassFactory.create(mapImplClass); - else - mapValue.clear(); - - Stack.push(this.target, target); - Stack.push(map, mapValue); - state.target = mapValue; + target.set((BeanT)state.prev.target); + map.set(acc.get(target.get())); + depthCounter++; + if(map.get() == null) { + map.set(ClassFactory.create(mapImplClass)); + } + map.get().clear(); + state.target = map.get(); } catch (AccessorException e) { // recover from error by setting a dummy Map that receives and discards the values handleGenericException(e,true); @@ -168,7 +167,11 @@ public void leaveElement(State state, TagName ea) throws SAXException { super.leaveElement(state, ea); try { - acc.set(Stack.pop(target), Stack.pop(map)); + acc.set(target.get(), map.get()); + if (--depthCounter == 0) { + target.remove(); + map.remove(); + } } catch (AccessorException ex) { handleGenericException(ex,true); } @@ -286,36 +289,4 @@ return acc; return null; } - - private static final class Stack { - private Stack parent; - private T value; - - private Stack(Stack parent, T value) { - this.parent = parent; - this.value = value; - } - - private Stack(T value) { - this.value = value; - } - - private static void push(ThreadLocal> holder, T value) { - Stack parent = holder.get(); - if (parent == null) - holder.set(new Stack(value)); - else - holder.set(new Stack(parent, value)); - } - - private static T pop(ThreadLocal> holder) { - Stack current = holder.get(); - if (current.parent == null) - holder.remove(); - else - holder.set(current.parent); - return current.value; - } - - } }