Fri, 14 Feb 2014 10:53:55 +0100
8025030: Enhance stream handling
Summary: Avoiding caching data initialized via TCCL in static context; fix also reviewed by Iaroslav Savytskyi, Alexander Fomin
Reviewed-by: ahgross, mgrebac, skoivu
1.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/DatatypeConverterImpl.java Tue Feb 11 14:35:59 2014 -0800 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/DatatypeConverterImpl.java Fri Feb 14 10:53:55 2014 +0100 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -27,9 +27,14 @@ 1.11 1.12 import java.math.BigDecimal; 1.13 import java.math.BigInteger; 1.14 +import java.security.AccessController; 1.15 +import java.security.PrivilegedAction; 1.16 import java.util.Calendar; 1.17 +import java.util.Collections; 1.18 import java.util.GregorianCalendar; 1.19 +import java.util.Map; 1.20 import java.util.TimeZone; 1.21 +import java.util.WeakHashMap; 1.22 1.23 import javax.xml.bind.DatatypeConverter; 1.24 import javax.xml.bind.DatatypeConverterInterface; 1.25 @@ -356,7 +361,7 @@ 1.26 1.27 public static GregorianCalendar _parseDateTime(CharSequence s) { 1.28 String val = WhiteSpaceProcessor.trim(s).toString(); 1.29 - return datatypeFactory.newXMLGregorianCalendar(val).toGregorianCalendar(); 1.30 + return getDatatypeFactory().newXMLGregorianCalendar(val).toGregorianCalendar(); 1.31 } 1.32 1.33 public static String _printDateTime(Calendar val) { 1.34 @@ -722,14 +727,30 @@ 1.35 } 1.36 return false; 1.37 } 1.38 - private static final DatatypeFactory datatypeFactory; 1.39 1.40 - static { 1.41 - try { 1.42 - datatypeFactory = DatatypeFactory.newInstance(); 1.43 - } catch (DatatypeConfigurationException e) { 1.44 - throw new Error(e); 1.45 + private static final Map<ClassLoader, DatatypeFactory> DF_CACHE = Collections.synchronizedMap(new WeakHashMap<ClassLoader, DatatypeFactory>()); 1.46 + 1.47 + public static DatatypeFactory getDatatypeFactory() { 1.48 + ClassLoader tccl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { 1.49 + public ClassLoader run() { 1.50 + return Thread.currentThread().getContextClassLoader(); 1.51 + } 1.52 + }); 1.53 + DatatypeFactory df = DF_CACHE.get(tccl); 1.54 + if (df == null) { 1.55 + synchronized (DatatypeConverterImpl.class) { 1.56 + df = DF_CACHE.get(tccl); 1.57 + if (df == null) { // to prevent multiple initialization 1.58 + try { 1.59 + df = DatatypeFactory.newInstance(); 1.60 + } catch (DatatypeConfigurationException e) { 1.61 + throw new Error(Messages.FAILED_TO_INITIALE_DATATYPE_FACTORY.format(),e); 1.62 + } 1.63 + DF_CACHE.put(tccl, df); 1.64 + } 1.65 + } 1.66 } 1.67 + return df; 1.68 } 1.69 1.70 private static final class CalendarFormatter { 1.71 @@ -1045,7 +1066,7 @@ 1.72 1.73 @Deprecated 1.74 public Calendar parseTime(String lexicalXSDTime) { 1.75 - return datatypeFactory.newXMLGregorianCalendar(lexicalXSDTime).toGregorianCalendar(); 1.76 + return getDatatypeFactory().newXMLGregorianCalendar(lexicalXSDTime).toGregorianCalendar(); 1.77 } 1.78 1.79 @Deprecated 1.80 @@ -1055,7 +1076,7 @@ 1.81 1.82 @Deprecated 1.83 public Calendar parseDate(String lexicalXSDDate) { 1.84 - return datatypeFactory.newXMLGregorianCalendar(lexicalXSDDate).toGregorianCalendar(); 1.85 + return getDatatypeFactory().newXMLGregorianCalendar(lexicalXSDDate).toGregorianCalendar(); 1.86 } 1.87 1.88 @Deprecated
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/Messages.java Fri Feb 14 10:53:55 2014 +0100 2.3 @@ -0,0 +1,48 @@ 2.4 +/* 2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. Oracle designates this 2.11 + * particular file as subject to the "Classpath" exception as provided 2.12 + * by Oracle in the LICENSE file that accompanied this code. 2.13 + * 2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.17 + * version 2 for more details (a copy is included in the LICENSE file that 2.18 + * accompanied this code). 2.19 + * 2.20 + * You should have received a copy of the GNU General Public License version 2.21 + * 2 along with this work; if not, write to the Free Software Foundation, 2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.23 + * 2.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.25 + * or visit www.oracle.com if you need additional information or have any 2.26 + * questions. 2.27 + */ 2.28 + 2.29 +package com.sun.xml.internal.bind; 2.30 + 2.31 +import java.text.MessageFormat; 2.32 +import java.util.ResourceBundle; 2.33 + 2.34 +/** 2.35 + * Message resources 2.36 + */ 2.37 +enum Messages { 2.38 + FAILED_TO_INITIALE_DATATYPE_FACTORY, // 0 args 2.39 + ; 2.40 + 2.41 + private static final ResourceBundle rb = ResourceBundle.getBundle(Messages.class.getName()); 2.42 + 2.43 + @Override 2.44 + public String toString() { 2.45 + return format(); 2.46 + } 2.47 + 2.48 + public String format( Object... args ) { 2.49 + return MessageFormat.format( rb.getString(name()), args ); 2.50 + } 2.51 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/Messages.properties Fri Feb 14 10:53:55 2014 +0100 3.3 @@ -0,0 +1,27 @@ 3.4 +# 3.5 +# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.7 +# 3.8 +# This code is free software; you can redistribute it and/or modify it 3.9 +# under the terms of the GNU General Public License version 2 only, as 3.10 +# published by the Free Software Foundation. Oracle designates this 3.11 +# particular file as subject to the "Classpath" exception as provided 3.12 +# by Oracle in the LICENSE file that accompanied this code. 3.13 +# 3.14 +# This code is distributed in the hope that it will be useful, but WITHOUT 3.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 3.16 +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 3.17 +# version 2 for more details (a copy is included in the LICENSE file that 3.18 +# accompanied this code). 3.19 +# 3.20 +# You should have received a copy of the GNU General Public License version 3.21 +# 2 along with this work; if not, write to the Free Software Foundation, 3.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 3.23 +# 3.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 3.25 +# or visit www.oracle.com if you need additional information or have any 3.26 +# questions. 3.27 +# 3.28 + 3.29 +FAILED_TO_INITIALE_DATATYPE_FACTORY = \ 3.30 + Failed to initialize JAXP 1.3 DatatypeFactory class.
4.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/model/impl/Messages.java Tue Feb 11 14:35:59 2014 -0800 4.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/model/impl/Messages.java Fri Feb 14 10:53:55 2014 +0100 4.3 @@ -1,5 +1,5 @@ 4.4 /* 4.5 - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 4.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 4.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 * 4.9 * This code is free software; you can redistribute it and/or modify it 4.10 @@ -60,7 +60,6 @@ 4.11 PROPERTY_ORDER_CONTAINS_UNUSED_ENTRY, // 2 args 4.12 4.13 INVALID_XML_ENUM_VALUE, // 2 arg 4.14 - FAILED_TO_INITIALE_DATATYPE_FACTORY, // 0 args 4.15 NO_IMAGE_WRITER, // 1 arg 4.16 4.17 ILLEGAL_MIME_TYPE, // 2 args
5.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/model/impl/RuntimeBuiltinLeafInfoImpl.java Tue Feb 11 14:35:59 2014 -0800 5.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/model/impl/RuntimeBuiltinLeafInfoImpl.java Fri Feb 14 10:53:55 2014 +0100 5.3 @@ -1,5 +1,5 @@ 5.4 /* 5.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 5.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 5.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.8 * 5.9 * This code is free software; you can redistribute it and/or modify it 5.10 @@ -63,9 +63,7 @@ 5.11 import javax.imageio.stream.ImageOutputStream; 5.12 import javax.xml.bind.ValidationEvent; 5.13 import javax.xml.bind.helpers.ValidationEventImpl; 5.14 -import javax.xml.datatype.DatatypeConfigurationException; 5.15 import javax.xml.datatype.DatatypeConstants; 5.16 -import javax.xml.datatype.DatatypeFactory; 5.17 import javax.xml.datatype.Duration; 5.18 import javax.xml.datatype.XMLGregorianCalendar; 5.19 import javax.xml.namespace.QName; 5.20 @@ -568,7 +566,8 @@ 5.21 5.22 public XMLGregorianCalendar parse(CharSequence lexical) throws SAXException { 5.23 try { 5.24 - return datatypeFactory.newXMLGregorianCalendar(lexical.toString().trim()); // (.trim() - issue 396) 5.25 + return DatatypeConverterImpl.getDatatypeFactory() 5.26 + .newXMLGregorianCalendar(lexical.toString().trim()); // (.trim() - issue 396) 5.27 } catch (Exception e) { 5.28 UnmarshallingContext.getInstance().handleError(e); 5.29 return null; 5.30 @@ -838,7 +837,7 @@ 5.31 5.32 public Duration parse(CharSequence lexical) { 5.33 TODO.checkSpec("JSR222 Issue #42"); 5.34 - return datatypeFactory.newDuration(lexical.toString()); 5.35 + return DatatypeConverterImpl.getDatatypeFactory().newDuration(lexical.toString()); 5.36 } 5.37 }); 5.38 primaryList.add( 5.39 @@ -879,21 +878,6 @@ 5.40 } 5.41 } 5.42 5.43 - 5.44 - /** 5.45 - * Cached instance of {@link DatatypeFactory} to create 5.46 - * {@link XMLGregorianCalendar} and {@link Duration}. 5.47 - */ 5.48 - private static final DatatypeFactory datatypeFactory = init(); 5.49 - 5.50 - private static DatatypeFactory init() { 5.51 - try { 5.52 - return DatatypeFactory.newInstance(); 5.53 - } catch (DatatypeConfigurationException e) { 5.54 - throw new Error(Messages.FAILED_TO_INITIALE_DATATYPE_FACTORY.format(),e); 5.55 - } 5.56 - } 5.57 - 5.58 private static void checkXmlGregorianCalendarFieldRef(QName type, 5.59 XMLGregorianCalendar cal)throws javax.xml.bind.MarshalException{ 5.60 StringBuilder buf = new StringBuilder();
6.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/XMLStreamWriterOutput.java Tue Feb 11 14:35:59 2014 -0800 6.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/XMLStreamWriterOutput.java Fri Feb 14 10:53:55 2014 +0100 6.3 @@ -1,5 +1,5 @@ 6.4 /* 6.5 - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 6.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 6.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.8 * 6.9 * This code is free software; you can redistribute it and/or modify it 6.10 @@ -153,7 +153,6 @@ 6.11 } 6.12 } 6.13 6.14 - 6.15 /** 6.16 * Reference to FI's XMLStreamWriter class, if FI can be loaded. 6.17 */ 6.18 @@ -162,9 +161,8 @@ 6.19 6.20 private static Class initFIStAXWriterClass() { 6.21 try { 6.22 - ClassLoader loader = getClassLoader(); 6.23 - Class llfisw = Class.forName("com.sun.xml.internal.org.jvnet.fastinfoset.stax.LowLevelFastInfosetStreamWriter", true, loader); 6.24 - Class sds = loader.loadClass("com.sun.xml.internal.fastinfoset.stax.StAXDocumentSerializer"); 6.25 + Class<?> llfisw = Class.forName("com.sun.xml.internal.org.jvnet.fastinfoset.stax.LowLevelFastInfosetStreamWriter"); 6.26 + Class<?> sds = Class.forName("com.sun.xml.internal.fastinfoset.stax.StAXDocumentSerializer"); 6.27 // Check if StAXDocumentSerializer implements LowLevelFastInfosetStreamWriter 6.28 if (llfisw.isAssignableFrom(sds)) 6.29 return sds; 6.30 @@ -179,8 +177,7 @@ 6.31 try { 6.32 if (FI_STAX_WRITER_CLASS == null) 6.33 return null; 6.34 - ClassLoader loader = getClassLoader(); 6.35 - Class c = Class.forName("com.sun.xml.internal.bind.v2.runtime.output.FastInfosetStreamWriterOutput", true, loader); 6.36 + Class c = Class.forName("com.sun.xml.internal.bind.v2.runtime.output.FastInfosetStreamWriterOutput"); 6.37 return c.getConstructor(FI_STAX_WRITER_CLASS, JAXBContextImpl.class); 6.38 } catch (Throwable e) { 6.39 return null; 6.40 @@ -195,8 +192,7 @@ 6.41 6.42 private static Class initStAXExWriterClass() { 6.43 try { 6.44 - ClassLoader loader = getClassLoader(); 6.45 - return Class.forName("com.sun.xml.internal.org.jvnet.staxex.XMLStreamWriterEx",true,loader); 6.46 + return Class.forName("com.sun.xml.internal.org.jvnet.staxex.XMLStreamWriterEx"); 6.47 } catch (Throwable e) { 6.48 return null; 6.49 } 6.50 @@ -204,20 +200,11 @@ 6.51 6.52 private static Constructor<? extends XmlOutput> initStAXExOutputClass() { 6.53 try { 6.54 - ClassLoader loader = getClassLoader(); 6.55 - Class c = Class.forName("com.sun.xml.internal.bind.v2.runtime.output.StAXExStreamWriterOutput",true, loader); 6.56 + Class c = Class.forName("com.sun.xml.internal.bind.v2.runtime.output.StAXExStreamWriterOutput"); 6.57 return c.getConstructor(STAXEX_WRITER_CLASS); 6.58 } catch (Throwable e) { 6.59 return null; 6.60 } 6.61 } 6.62 6.63 - private static ClassLoader getClassLoader() { 6.64 - ClassLoader cl = SecureLoader.getClassClassLoader(UnmarshallerImpl.class); 6.65 - if (cl == null) { 6.66 - cl = SecureLoader.getContextClassLoader(); 6.67 - } 6.68 - return cl; 6.69 - } 6.70 - 6.71 }
7.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/reflect/Messages.properties Tue Feb 11 14:35:59 2014 -0800 7.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/reflect/Messages.properties Fri Feb 14 10:53:55 2014 +0100 7.3 @@ -1,5 +1,5 @@ 7.4 # 7.5 -# Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 7.6 +# Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 7.7 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.8 # 7.9 # This code is free software; you can redistribute it and/or modify it 7.10 @@ -38,3 +38,6 @@ 7.11 NO_GETTER = \ 7.12 The property has a setter "{0}" but no getter. \ 7.13 For marshaller, please define getters. 7.14 + 7.15 +INVALID_XML_ENUM_VALUE = \ 7.16 + "{0}" is not a valid value for {1}.
8.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/unmarshaller/StAXStreamConnector.java Tue Feb 11 14:35:59 2014 -0800 8.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/unmarshaller/StAXStreamConnector.java Fri Feb 14 10:53:55 2014 +0100 8.3 @@ -1,5 +1,5 @@ 8.4 /* 8.5 - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 8.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 8.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.8 * 8.9 * This code is free software; you can redistribute it and/or modify it 8.10 @@ -336,9 +336,8 @@ 8.11 8.12 private static Class initFIStAXReaderClass() { 8.13 try { 8.14 - ClassLoader cl = getClassLoader(); 8.15 - Class fisr = cl.loadClass("com.sun.xml.internal.org.jvnet.fastinfoset.stax.FastInfosetStreamReader"); 8.16 - Class sdp = cl.loadClass("com.sun.xml.internal.fastinfoset.stax.StAXDocumentParser"); 8.17 + Class<?> fisr = Class.forName("com.sun.xml.internal.org.jvnet.fastinfoset.stax.FastInfosetStreamReader"); 8.18 + Class<?> sdp = Class.forName("com.sun.xml.internal.fastinfoset.stax.StAXDocumentParser"); 8.19 // Check if StAXDocumentParser implements FastInfosetStreamReader 8.20 if (fisr.isAssignableFrom(sdp)) 8.21 return sdp; 8.22 @@ -354,7 +353,7 @@ 8.23 if (FI_STAX_READER_CLASS == null) 8.24 return null; 8.25 8.26 - Class c = getClassLoader().loadClass( 8.27 + Class c = Class.forName( 8.28 "com.sun.xml.internal.bind.v2.runtime.unmarshaller.FastInfosetConnector"); 8.29 return c.getConstructor(FI_STAX_READER_CLASS,XmlVisitor.class); 8.30 } catch (Throwable e) { 8.31 @@ -370,7 +369,7 @@ 8.32 8.33 private static Class initStAXExReader() { 8.34 try { 8.35 - return getClassLoader().loadClass("com.sun.xml.internal.org.jvnet.staxex.XMLStreamReaderEx"); 8.36 + return Class.forName("com.sun.xml.internal.org.jvnet.staxex.XMLStreamReaderEx"); 8.37 } catch (Throwable e) { 8.38 return null; 8.39 } 8.40 @@ -378,19 +377,11 @@ 8.41 8.42 private static Constructor<? extends StAXConnector> initStAXExConnector() { 8.43 try { 8.44 - Class c = getClassLoader().loadClass("com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXExConnector"); 8.45 + Class c = Class.forName("com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXExConnector"); 8.46 return c.getConstructor(STAX_EX_READER_CLASS,XmlVisitor.class); 8.47 } catch (Throwable e) { 8.48 return null; 8.49 } 8.50 } 8.51 8.52 - private static ClassLoader getClassLoader() { 8.53 - ClassLoader cl = SecureLoader.getClassClassLoader(UnmarshallerImpl.class); 8.54 - if (cl == null) { 8.55 - cl = SecureLoader.getContextClassLoader(); 8.56 - } 8.57 - return cl; 8.58 - } 8.59 - 8.60 }