jaxws/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/property/SingleMapNodeProperty.java
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/property/SingleMapNodeProperty.java Wed Jul 05 19:21:29 2017 +0200
+++ b/jaxws/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<ValueT> sig = ReflectionNavigator.REFLECTION.erasure(prop.getRawType());
+ //noinspection unchecked
+ Class<ValueT> sig = (Class<ValueT>) 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<Stack<BeanT>> target = new ThreadLocal<Stack<BeanT>>();
- private ThreadLocal<Stack<ValueT>> map = new ThreadLocal<Stack<ValueT>>();
+ private ThreadLocal<BeanT> target = new ThreadLocal<BeanT>();
+ private ThreadLocal<ValueT> map = new ThreadLocal<ValueT>();
+ 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<T> {
- private Stack<T> parent;
- private T value;
-
- private Stack(Stack<T> parent, T value) {
- this.parent = parent;
- this.value = value;
- }
-
- private Stack(T value) {
- this.value = value;
- }
-
- private static <T> void push(ThreadLocal<Stack<T>> holder, T value) {
- Stack<T> parent = holder.get();
- if (parent == null)
- holder.set(new Stack<T>(value));
- else
- holder.set(new Stack<T>(parent, value));
- }
-
- private static <T> T pop(ThreadLocal<Stack<T>> holder) {
- Stack<T> current = holder.get();
- if (current.parent == null)
- holder.remove();
- else
- holder.set(current.parent);
- return current.value;
- }
-
- }
}