From 39d11fa4b15d95decb7b3dbc2a1aece66517fdf9 Mon Sep 17 00:00:00 2001 From: Jody Grassel Date: Tue, 27 Sep 2011 19:06:19 +0000 Subject: [PATCH] Revert 'OPENJPA-1993:Deadlock Potential with ORM XML Processing' rev-1099630 git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/1.0.x@1176532 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/openjpa/conf/Compatibility.java | 19 ----- .../openjpa/lib/meta/XMLMetaDataParser.java | 81 ++++++------------- .../openjpa/lib/util/J2DoPrivHelper.java | 18 ----- .../openjpa/lib/meta/localizer.properties | 2 - .../XMLPersistenceMetaDataParser.java | 8 -- 5 files changed, 23 insertions(+), 105 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java index 49a38f11f..9ee0e7747 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/Compatibility.java @@ -31,7 +31,6 @@ public class Compatibility { private boolean _quotedNumbers = false; private boolean _nonOptimisticVersionCheck = false; private boolean _flushBeforeDetach = true; - private boolean _overrideContextClassloader = false; /** * Whether to require exact identity value types when creating object @@ -193,22 +192,4 @@ public class Compatibility { _flushBeforeDetach = beforeDetach; } - /** - * Whether to temporally override the thread's Context Classloader when processing - * ORM XML documents to avoid deadlock potential with certain Classloader hierarchy - * configurations. Defaults to false. - */ - public boolean getOverrideContextClassloader() { - return _overrideContextClassloader; - } - - /** - * Whether to temporally override the thread's Context Classloader when processing - * ORM XML documents to avoid deadlock potential with certain Classloader hierarchy - * configurations. Defaults to false. - */ - public void setOverrideContextClassloader(boolean overrideContextClassloader) { - _overrideContextClassloader = overrideContextClassloader; - } - } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java index ab384ac51..131dce98f 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/meta/XMLMetaDataParser.java @@ -105,16 +105,6 @@ public abstract class XMLMetaDataParser extends DefaultHandler private LexicalHandler _lh = null; private int _depth = -1; private int _ignore = Integer.MAX_VALUE; - - private boolean _overrideContextClassloader = false; - - public boolean getOverrideContextClassloader() { - return _overrideContextClassloader; - } - - public void setOverrideContextClassloader(boolean overrideCCL) { - _overrideContextClassloader = overrideCCL; - } /** * Whether to parse element text. @@ -359,61 +349,36 @@ public abstract class XMLMetaDataParser extends DefaultHandler // parse the metadata with a SAX parser try { _sourceName = sourceName; - SAXParser parser = null; - ClassLoader oldLoader = null; + SAXParser parser = XMLFactory.getSAXParser(validating, true); + Object schema = null; + if (validating) { + schema = schemaSource; + if (schema == null && getDocType() != null) + xml = new DocTypeReader(xml, getDocType()); + } - try { - if (_overrideContextClassloader == true) { - - oldLoader = (ClassLoader) AccessController.doPrivileged( - J2DoPrivHelper.getContextClassLoaderAction()); - AccessController.doPrivileged(J2DoPrivHelper.setContextClassLoaderAction( - XMLMetaDataParser.class.getClassLoader())); - } - - parser = XMLFactory.getSAXParser(validating, true); - Object schema = null; - if (validating) { - schema = schemaSource; - if (schema == null && getDocType() != null) - xml = new DocTypeReader(xml, getDocType()); - } - - if (_parseComments || _lh != null) - parser.setProperty + if (_parseComments || _lh != null) + parser.setProperty ("http://xml.org/sax/properties/lexical-handler", this); - if (schema != null) { - parser.setProperty + if (schema != null) { + parser.setProperty ("http://java.sun.com/xml/jaxp/properties/schemaLanguage", - "http://www.w3.org/2001/XMLSchema"); - parser.setProperty + "http://www.w3.org/2001/XMLSchema"); + parser.setProperty ("http://java.sun.com/xml/jaxp/properties/schemaSource", schema); - } - - InputSource is = new InputSource(xml); - if (_systemId && sourceName != null) - is.setSystemId(sourceName); - parser.parse(is, this); - finish(); - } catch (SAXException se) { - IOException ioe = new IOException(se.toString()); - JavaVersions.initCause(ioe, se); - throw ioe; - } finally { - if (_overrideContextClassloader == true && oldLoader != null) { - // Restore the old ContextClassloader - try { - AccessController.doPrivileged(J2DoPrivHelper.setContextClassLoaderAction(oldLoader)); - } catch (Throwable t) { - if (_log != null && _log.isTraceEnabled()) { - _log.trace(_loc.get("restore-contextclassloader-failed")); - } - } - - } } + + InputSource is = new InputSource(xml); + if (_systemId && sourceName != null) + is.setSystemId(sourceName); + parser.parse(is, this); + finish(); + } catch (SAXException se) { + IOException ioe = new IOException(se.toString()); + JavaVersions.initCause(ioe, se); + throw ioe; } finally { reset(); } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java index 7c3f9546e..a9d9b4286 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java @@ -788,24 +788,6 @@ public abstract class J2DoPrivHelper { } }; } - - /** - * Return a PrivilegeAction object for Thread.currentThread - * .setContextClassLoader(). - * - * Requires security policy: - * 'permission java.lang.RuntimePermission "setContextClassLoader";' - * - * @return ClassLoader - */ - public static final PrivilegedAction setContextClassLoaderAction(final ClassLoader loader) { - return new PrivilegedAction() { - public Object run() { - Thread.currentThread().setContextClassLoader(loader); - return Boolean.TRUE; - } - }; - } /** * Return a PrivilegedAction object for new Thread(). diff --git a/openjpa-lib/src/main/resources/org/apache/openjpa/lib/meta/localizer.properties b/openjpa-lib/src/main/resources/org/apache/openjpa/lib/meta/localizer.properties index 8b1550f0c..a5ce82cc0 100644 --- a/openjpa-lib/src/main/resources/org/apache/openjpa/lib/meta/localizer.properties +++ b/openjpa-lib/src/main/resources/org/apache/openjpa/lib/meta/localizer.properties @@ -25,8 +25,6 @@ cant-diff-elems: Unable to differentiate between given package and class \ elements for class arg parsing. No element can be a complete prefix of \ another. class-arg: Error extracting class information from "{0}". -restore-contextclassloader-failed: An error occurred restoring the Thread's \ - context classloader. parse-error: An error was encountered while parsing element "{0}". Make sure \ the metadata file is correctly formatted. no-file: No source file found for "{0}". diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java index 20efa9a29..c8c789d56 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataParser.java @@ -235,14 +235,6 @@ public class XMLPersistenceMetaDataParser if (repos != null && (repos.getValidate() & repos.VALIDATE_RUNTIME) != 0) setParseComments(false); - - if (repos != null) { - // Determine if the Thread Context Classloader needs to be temporally overridden to the Classloader - // that loaded the OpenJPA classes, to avoid a potential deadlock issue with the way Xerces - // handles parsers and classloaders. - this.setOverrideContextClassloader(repos.getConfiguration().getCompatibilityInstance(). - getOverrideContextClassloader()); - } } /**