diff options
author | aefimov <none@none> | 2016-08-22 19:20:16 +0300 |
---|---|---|
committer | aefimov <none@none> | 2016-08-22 19:20:16 +0300 |
commit | 2ddee008ec27ad84763a6aad8e02ffb0a9b9755b (patch) | |
tree | 7bf6650ef0f6ee7fbd1efb4af444f4fe39e99b53 | |
parent | bdfda7ed7237b06e6b2d2f94d90cfc07b6a7b161 (diff) | |
download | jdk8u_jaxp-2ddee008ec27ad84763a6aad8e02ffb0a9b9755b.tar.gz |
8146961: Fix PermGen memory leaks caused by static final Exceptions
Reviewed-by: joehw, shade, clanger, plevart
3 files changed, 50 insertions, 26 deletions
diff --git a/src/com/sun/org/apache/xerces/internal/dom/AbortException.java b/src/com/sun/org/apache/xerces/internal/dom/AbortException.java new file mode 100644 index 0000000..3e178dd --- /dev/null +++ b/src/com/sun/org/apache/xerces/internal/dom/AbortException.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.org.apache.xerces.internal.dom; + +public class AbortException extends RuntimeException { + + private static final long serialVersionUID = 2608302175475740417L; + + /** + * Constructor AbortException + */ + public AbortException() { super(null, null, false, false); } +} diff --git a/src/com/sun/org/apache/xerces/internal/dom/DOMNormalizer.java b/src/com/sun/org/apache/xerces/internal/dom/DOMNormalizer.java index 3758f39..c4268dc 100644 --- a/src/com/sun/org/apache/xerces/internal/dom/DOMNormalizer.java +++ b/src/com/sun/org/apache/xerces/internal/dom/DOMNormalizer.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.io.StringReader; import java.util.Vector; +import com.sun.org.apache.xerces.internal.dom.AbortException; import com.sun.org.apache.xerces.internal.impl.Constants; import com.sun.org.apache.xerces.internal.impl.RevalidationHandler; import com.sun.org.apache.xerces.internal.impl.dtd.DTDGrammar; @@ -158,11 +159,6 @@ public class DOMNormalizer implements XMLDocumentHandler { // attribute value normalization final XMLString fNormalizedValue = new XMLString(new char[16], 0, 0); - /** - * If the user stops the process, this exception will be thrown. - */ - public static final RuntimeException abort = new RuntimeException(); - //DTD validator private XMLDTDValidator fDTDValidator; @@ -243,11 +239,10 @@ public class DOMNormalizer implements XMLDocumentHandler { XMLGrammarDescription.XML_SCHEMA, fValidationHandler); fValidationHandler = null; } - } - catch (RuntimeException e) { - if( e==abort ) - return; // processing aborted by the user - throw e; // otherwise re-throw. + } catch (AbortException e) { + return; + } catch (RuntimeException e) { + throw e; // otherwise re-throw. } } @@ -1372,10 +1367,10 @@ public class DOMNormalizer implements XMLDocumentHandler { error.fRelatedData = locator.fRelatedNode; if(!errorHandler.handleError(error)) - throw abort; + throw new AbortException(); } if( severity==DOMError.SEVERITY_FATAL_ERROR ) - throw abort; + throw new AbortException(); } protected final void updateQName (Node node, QName qname){ @@ -2044,5 +2039,4 @@ public class DOMNormalizer implements XMLDocumentHandler { return null; } - } // DOMNormalizer class diff --git a/src/com/sun/org/apache/xml/internal/serialize/DOMSerializerImpl.java b/src/com/sun/org/apache/xml/internal/serialize/DOMSerializerImpl.java index d17cf33..8f14d74 100644 --- a/src/com/sun/org/apache/xml/internal/serialize/DOMSerializerImpl.java +++ b/src/com/sun/org/apache/xml/internal/serialize/DOMSerializerImpl.java @@ -33,6 +33,7 @@ import java.net.URLConnection; import java.util.StringTokenizer; import java.util.Vector; +import com.sun.org.apache.xerces.internal.dom.AbortException; import com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl; import com.sun.org.apache.xerces.internal.dom.DOMErrorImpl; import com.sun.org.apache.xerces.internal.dom.DOMLocatorImpl; @@ -117,7 +118,6 @@ public class DOMSerializerImpl implements LSSerializer, DOMConfiguration { private DOMErrorHandler fErrorHandler = null; private final DOMErrorImpl fError = new DOMErrorImpl(); private final DOMLocatorImpl fLocator = new DOMLocatorImpl(); - private static final RuntimeException abort = new RuntimeException(); /** * Constructs a new LSSerializer. @@ -539,11 +539,9 @@ public class DOMSerializerImpl implements LSSerializer, DOMConfiguration { } catch (LSException lse) { // Rethrow LSException. throw lse; + } catch (AbortException e) { + return null; } catch (RuntimeException e) { - if (e == DOMNormalizer.abort){ - // stopped at user request - return null; - } throw (LSException) new LSException(LSException.SERIALIZE_ERR, e.toString()).initCause(e); } catch (IOException ioe) { // REVISIT: A generic IOException doesn't provide enough information @@ -836,11 +834,9 @@ public class DOMSerializerImpl implements LSSerializer, DOMConfiguration { } catch (LSException lse) { // Rethrow LSException. throw lse; + } catch (AbortException e) { + return false; } catch (RuntimeException e) { - if (e == DOMNormalizer.abort){ - // stopped at user request - return false; - } throw (LSException) DOMUtil.createLSException(LSException.SERIALIZE_ERR, e).fillInStackTrace(); } catch (Exception e) { if (ser.fDOMErrorHandler != null) { @@ -992,11 +988,9 @@ public class DOMSerializerImpl implements LSSerializer, DOMConfiguration { } catch (LSException lse) { // Rethrow LSException. throw lse; + } catch (AbortException e) { + return false; } catch (RuntimeException e) { - if (e == DOMNormalizer.abort){ - // stopped at user request - return false; - } throw (LSException) DOMUtil.createLSException(LSException.SERIALIZE_ERR, e).fillInStackTrace(); } catch (Exception e) { if (ser.fDOMErrorHandler != null) { |