# HG changeset patch # User Greg Lewis # Date 1504852630 25200 # Node ID c3298bf492b181b494bc63a2b09746ba20a7816b # Parent 96518f358a981f4ec17a663accb46bf86c089bbd# Parent 9a5675f6421ef4fb5aae2d1fbcce24a15fb85f99 Merge from main OpenJDK repository diff -r 96518f358a98 -r c3298bf492b1 .hgtags --- a/.hgtags Sun May 28 21:31:36 2017 -0700 +++ b/.hgtags Thu Sep 07 23:37:10 2017 -0700 @@ -615,3 +615,5 @@ f347b141975453f642ae1140a45aa7c6127551dd jdk7u141-b00 e096a279a1c226d7d3a4aa19d5beeba1fb0507cf jdk7u141-b01 b4b91a7beb185c0a8a14b83d2b05cfd7fc33c6fe jdk7u141-b02 +26391fa1d876e3bf563f21328d7ea24d5d657b21 jdk7u151-b00 +57fc772ac86ac6cbd297cd6f09a63f9c016c271c jdk7u151-b01 diff -r 96518f358a98 -r c3298bf492b1 src/com/sun/org/apache/xalan/internal/res/XSLTErrorResources_sv.java --- a/src/com/sun/org/apache/xalan/internal/res/XSLTErrorResources_sv.java Sun May 28 21:31:36 2017 -0700 +++ b/src/com/sun/org/apache/xalan/internal/res/XSLTErrorResources_sv.java Thu Sep 07 23:37:10 2017 -0700 @@ -483,7 +483,7 @@ {"ER0000" , "{0}" }, { ER_NO_CURLYBRACE, - "Fel: Uttryck kan inte inneh\u00E5lla '{'"}, + "Fel: Uttryck f\u00E5r inte inneh\u00E5lla '{'"}, { ER_ILLEGAL_ATTRIBUTE , "{0} har ett otill\u00E5tet attribut: {1}"}, diff -r 96518f358a98 -r c3298bf492b1 src/com/sun/org/apache/xerces/internal/impl/msg/XIncludeMessages_sv.properties --- a/src/com/sun/org/apache/xerces/internal/impl/msg/XIncludeMessages_sv.properties Sun May 28 21:31:36 2017 -0700 +++ b/src/com/sun/org/apache/xerces/internal/impl/msg/XIncludeMessages_sv.properties Thu Sep 07 23:37:10 2017 -0700 @@ -33,4 +33,4 @@ # Messages from erroneous set-up IncompatibleNamespaceContext = Typ av NamespaceContext \u00E4r inkompatibel med XInclude; det kr\u00E4vs en instans av XIncludeNamespaceSupport -ExpandedSystemId = Kunde inte ut\u00F6ka system-ID:t f\u00F6r inkluderad resurs +ExpandedSystemId = Kunde inte ut\u00F6ka system-id:t f\u00F6r inkluderad resurs diff -r 96518f358a98 -r c3298bf492b1 src/com/sun/org/apache/xerces/internal/impl/msg/XMLSchemaMessages_sv.properties --- a/src/com/sun/org/apache/xerces/internal/impl/msg/XMLSchemaMessages_sv.properties Sun May 28 21:31:36 2017 -0700 +++ b/src/com/sun/org/apache/xerces/internal/impl/msg/XMLSchemaMessages_sv.properties Thu Sep 07 23:37:10 2017 -0700 @@ -80,7 +80,7 @@ cvc-pattern-valid = cvc-pattern-valid: V\u00E4rdet ''{0}'' \u00E4r ogiltigt med aktuellt m\u00F6nster ''{1}'' f\u00F6r typ ''{2}''. cvc-totalDigits-valid = cvc-totalDigits-valid: V\u00E4rdet ''{0}'' har {1} siffror, men det totala antalet siffror \u00E4r begr\u00E4nsat till {2}. cvc-type.2 = cvc-type.2: Typdefinitionen kan inte vara abstrakt f\u00F6r elementet {0}. - cvc-type.3.1.1 = cvc-type.3.1.1: Elementet ''{0}'' har enkel typ och kan inte inneh\u00E5lla attribut, ut\u00F6ver s\u00E5dana vars namnrymd \u00E4r identisk med ''http://www.w3.org/2001/XMLSchema-instance'' och vars [lokala namn] har n\u00E5gotdera av ''type'', ''nil'', ''schemaLocation'' eller ''noNamespaceSchemaLocation''. Hittade dock attributet ''{1}''. + cvc-type.3.1.1 = cvc-type.3.1.1: Elementet ''{0}'' har enkel typ och f\u00E5r inte inneh\u00E5lla attribut, ut\u00F6ver s\u00E5dana vars namnrymd \u00E4r identisk med ''http://www.w3.org/2001/XMLSchema-instance'' och vars [lokala namn] har n\u00E5gotdera av ''type'', ''nil'', ''schemaLocation'' eller ''noNamespaceSchemaLocation''. Hittade dock attributet ''{1}''. cvc-type.3.1.2 = cvc-type.3.1.2: Elementet ''{0}'' har enkel typ och f\u00E5r inte inneh\u00E5lla [underordnade] med elementinformation. cvc-type.3.1.3 = cvc-type.3.1.3: V\u00E4rdet ''{1}'' i elementet ''{0}'' \u00E4r ogiltigt. @@ -251,7 +251,7 @@ rcase-RecurseUnordered.2 = rcase-RecurseUnordered.2: Det finns ingen fullst\u00E4ndigt fungerande mappning mellan partiklarna. # We're using sch-props-correct.2 instead of the old src-redefine.1 # src-redefine.1 = src-redefine.1: The component ''{0}'' is begin redefined, but its corresponding component isn't in the schema document being redefined (with namespace ''{2}''), but in a different document, with namespace ''{1}''. - sch-props-correct.2 = sch-props-correct.2: Ett schema kan inte inneh\u00E5lla tv\u00E5 globala komponenter med samma namn. Detta schema har tv\u00E5 f\u00F6rekomster av ''{0}''. + sch-props-correct.2 = sch-props-correct.2: Ett schema f\u00E5r inte inneh\u00E5lla tv\u00E5 globala komponenter med samma namn. Detta schema har tv\u00E5 f\u00F6rekomster av ''{0}''. st-props-correct.2 = st-props-correct.2: Cirkul\u00E4ra definitioner har identifierats f\u00F6r enkel typ ''{0}''. Detta inneb\u00E4r att ''{0}'' ing\u00E5r i sin egen typhierarki, vilket \u00E4r fel. st-props-correct.3 = st-props-correct.3: Ett fel intr\u00E4ffade f\u00F6r typ ''{0}''. V\u00E4rdet f\u00F6r '{'slutgiltigt'}' i '{'bastypdefinitionen'}', ''{1}'', f\u00F6rbjuder h\u00E4rledning med begr\u00E4nsning. totalDigits-valid-restriction = totalDigits-valid-restriction: I definitionen f\u00F6r {2} \u00E4r v\u00E4rdet ''{0}'' f\u00F6r ''totalDigits'' ogiltigt eftersom det m\u00E5ste vara mindre \u00E4n eller lika med v\u00E4rdet f\u00F6r ''totalDigits'' som har angetts som ''{1}'' i n\u00E5gon typ f\u00F6r \u00F6verordnad. diff -r 96518f358a98 -r c3298bf492b1 src/com/sun/org/apache/xml/internal/dtm/DTMConfigurationException.java --- a/src/com/sun/org/apache/xml/internal/dtm/DTMConfigurationException.java Sun May 28 21:31:36 2017 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -/* - * reserved comment block - * DO NOT REMOVE OR ALTER! - */ -/* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* - * $Id: DTMConfigurationException.java,v 1.2.4.1 2005/09/15 08:14:52 suresh_emailid Exp $ - */ -package com.sun.org.apache.xml.internal.dtm; - -import javax.xml.transform.SourceLocator; - -/** - * Indicates a serious configuration error. - */ -public class DTMConfigurationException extends DTMException { - static final long serialVersionUID = -4607874078818418046L; - - /** - * Create a new DTMConfigurationException with no - * detail mesage. - */ - public DTMConfigurationException() { - super("Configuration Error"); - } - - /** - * Create a new DTMConfigurationException with - * the String specified as an error message. - * - * @param msg The error message for the exception. - */ - public DTMConfigurationException(String msg) { - super(msg); - } - - /** - * Create a new DTMConfigurationException with a - * given Exception base cause of the error. - * - * @param e The exception to be encapsulated in a - * DTMConfigurationException. - */ - public DTMConfigurationException(Throwable e) { - super(e); - } - - /** - * Create a new DTMConfigurationException with the - * given Exception base cause and detail message. - * - * @param msg The detail message. - * @param e The exception to be wrapped in a DTMConfigurationException - */ - public DTMConfigurationException(String msg, Throwable e) { - super(msg, e); - } - - /** - * Create a new DTMConfigurationException from a message and a Locator. - * - *

This constructor is especially useful when an application is - * creating its own exception from within a DocumentHandler - * callback.

- * - * @param message The error or warning message. - * @param locator The locator object for the error or warning. - */ - public DTMConfigurationException(String message, - SourceLocator locator) { - super(message, locator); - } - - /** - * Wrap an existing exception in a DTMConfigurationException. - * - * @param message The error or warning message, or null to - * use the message from the embedded exception. - * @param locator The locator object for the error or warning. - * @param e Any exception. - */ - public DTMConfigurationException(String message, - SourceLocator locator, - Throwable e) { - super(message, locator, e); - } -} diff -r 96518f358a98 -r c3298bf492b1 src/com/sun/org/apache/xml/internal/dtm/DTMException.java --- a/src/com/sun/org/apache/xml/internal/dtm/DTMException.java Sun May 28 21:31:36 2017 -0700 +++ b/src/com/sun/org/apache/xml/internal/dtm/DTMException.java Thu Sep 07 23:37:10 2017 -0700 @@ -1,13 +1,13 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -17,129 +17,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * $Id: DTMException.java,v 1.3 2005/09/28 13:48:50 pvedula Exp $ - */ package com.sun.org.apache.xml.internal.dtm; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import javax.xml.transform.SourceLocator; - -import com.sun.org.apache.xml.internal.res.XMLErrorResources; -import com.sun.org.apache.xml.internal.res.XMLMessages; - - /** - * This class specifies an exceptional condition that occured + * This class specifies an exceptional condition that occurred * in the DTM module. */ public class DTMException extends RuntimeException { static final long serialVersionUID = -775576419181334734L; - /** Field locator specifies where the error occured. - * @serial */ - SourceLocator locator; - - /** - * Method getLocator retrieves an instance of a SourceLocator - * object that specifies where an error occured. - * - * @return A SourceLocator object, or null if none was specified. - */ - public SourceLocator getLocator() { - return locator; - } - - /** - * Method setLocator sets an instance of a SourceLocator - * object that specifies where an error occured. - * - * @param location A SourceLocator object, or null to clear the location. - */ - public void setLocator(SourceLocator location) { - locator = location; - } - - /** Field containedException specifies a wrapped exception. May be null. - * @serial */ - Throwable containedException; - - /** - * This method retrieves an exception that this exception wraps. - * - * @return An Throwable object, or null. - * @see #getCause - */ - public Throwable getException() { - return containedException; - } - - /** - * Returns the cause of this throwable or null if the - * cause is nonexistent or unknown. (The cause is the throwable that - * caused this throwable to get thrown.) - */ - public Throwable getCause() { - - return ((containedException == this) - ? null - : containedException); - } - - /** - * Initializes the cause of this throwable to the specified value. - * (The cause is the throwable that caused this throwable to get thrown.) - * - *

This method can be called at most once. It is generally called from - * within the constructor, or immediately after creating the - * throwable. If this throwable was created - * with {@link #DTMException(Throwable)} or - * {@link #DTMException(String,Throwable)}, this method cannot be called - * even once. - * - * @param cause the cause (which is saved for later retrieval by the - * {@link #getCause()} method). (A null value is - * permitted, and indicates that the cause is nonexistent or - * unknown.) - * @return a reference to this Throwable instance. - * @throws IllegalArgumentException if cause is this - * throwable. (A throwable cannot - * be its own cause.) - * @throws IllegalStateException if this throwable was - * created with {@link #DTMException(Throwable)} or - * {@link #DTMException(String,Throwable)}, or this method has already - * been called on this throwable. - */ - public synchronized Throwable initCause(Throwable cause) { - - if ((this.containedException == null) && (cause != null)) { - throw new IllegalStateException(XMLMessages.createXMLMessage(XMLErrorResources.ER_CANNOT_OVERWRITE_CAUSE, null)); //"Can't overwrite cause"); - } - - if (cause == this) { - throw new IllegalArgumentException( - XMLMessages.createXMLMessage(XMLErrorResources.ER_SELF_CAUSATION_NOT_PERMITTED, null)); //"Self-causation not permitted"); - } - - this.containedException = cause; - - return this; - } - /** * Create a new DTMException. * * @param message The error or warning message. */ public DTMException(String message) { - super(message); - - this.containedException = null; - this.locator = null; } /** @@ -148,11 +41,7 @@ * @param e The exception to be wrapped. */ public DTMException(Throwable e) { - - super(e.getMessage()); - - this.containedException = e; - this.locator = null; + super(e); } /** @@ -166,220 +55,6 @@ * @param e Any exception */ public DTMException(String message, Throwable e) { - - super(((message == null) || (message.length() == 0)) - ? e.getMessage() - : message); - - this.containedException = e; - this.locator = null; - } - - /** - * Create a new DTMException from a message and a Locator. - * - *

This constructor is especially useful when an application is - * creating its own exception from within a DocumentHandler - * callback.

- * - * @param message The error or warning message. - * @param locator The locator object for the error or warning. - */ - public DTMException(String message, SourceLocator locator) { - - super(message); - - this.containedException = null; - this.locator = locator; - } - - /** - * Wrap an existing exception in a DTMException. - * - * @param message The error or warning message, or null to - * use the message from the embedded exception. - * @param locator The locator object for the error or warning. - * @param e Any exception - */ - public DTMException(String message, SourceLocator locator, - Throwable e) { - - super(message); - - this.containedException = e; - this.locator = locator; - } - - /** - * Get the error message with location information - * appended. - */ - public String getMessageAndLocation() { - - StringBuffer sbuffer = new StringBuffer(); - String message = super.getMessage(); - - if (null != message) { - sbuffer.append(message); - } - - if (null != locator) { - String systemID = locator.getSystemId(); - int line = locator.getLineNumber(); - int column = locator.getColumnNumber(); - - if (null != systemID) { - sbuffer.append("; SystemID: "); - sbuffer.append(systemID); - } - - if (0 != line) { - sbuffer.append("; Line#: "); - sbuffer.append(line); - } - - if (0 != column) { - sbuffer.append("; Column#: "); - sbuffer.append(column); - } - } - - return sbuffer.toString(); - } - - /** - * Get the location information as a string. - * - * @return A string with location info, or null - * if there is no location information. - */ - public String getLocationAsString() { - - if (null != locator) { - StringBuffer sbuffer = new StringBuffer(); - String systemID = locator.getSystemId(); - int line = locator.getLineNumber(); - int column = locator.getColumnNumber(); - - if (null != systemID) { - sbuffer.append("; SystemID: "); - sbuffer.append(systemID); - } - - if (0 != line) { - sbuffer.append("; Line#: "); - sbuffer.append(line); - } - - if (0 != column) { - sbuffer.append("; Column#: "); - sbuffer.append(column); - } - - return sbuffer.toString(); - } else { - return null; - } - } - - /** - * Print the the trace of methods from where the error - * originated. This will trace all nested exception - * objects, as well as this object. - */ - public void printStackTrace() { - printStackTrace(new java.io.PrintWriter(System.err, true)); - } - - /** - * Print the the trace of methods from where the error - * originated. This will trace all nested exception - * objects, as well as this object. - * @param s The stream where the dump will be sent to. - */ - public void printStackTrace(java.io.PrintStream s) { - printStackTrace(new java.io.PrintWriter(s)); - } - - /** - * Print the the trace of methods from where the error - * originated. This will trace all nested exception - * objects, as well as this object. - * @param s The writer where the dump will be sent to. - */ - public void printStackTrace(java.io.PrintWriter s) { - - if (s == null) { - s = new java.io.PrintWriter(System.err, true); - } - - try { - String locInfo = getLocationAsString(); - - if (null != locInfo) { - s.println(locInfo); - } - - super.printStackTrace(s); - } catch (Throwable e) {} - - boolean isJdk14OrHigher = false; - try { - Throwable.class.getMethod("getCause", (Class[]) null); - isJdk14OrHigher = true; - } catch (NoSuchMethodException nsme) { - // do nothing - } - - // The printStackTrace method of the Throwable class in jdk 1.4 - // and higher will include the cause when printing the backtrace. - // The following code is only required when using jdk 1.3 or lower - if (!isJdk14OrHigher) { - Throwable exception = getException(); - - for (int i = 0; (i < 10) && (null != exception); i++) { - s.println("---------"); - - try { - if (exception instanceof DTMException) { - String locInfo = - ((DTMException) exception) - .getLocationAsString(); - - if (null != locInfo) { - s.println(locInfo); - } - } - - exception.printStackTrace(s); - } catch (Throwable e) { - s.println("Could not print stack trace..."); - } - - try { - Method meth = - ((Object) exception).getClass().getMethod("getException", - (Class[]) null); - - if (null != meth) { - Throwable prev = exception; - - exception = (Throwable) meth.invoke(exception, (Object[]) null); - - if (prev == exception) { - break; - } - } else { - exception = null; - } - } catch (InvocationTargetException ite) { - exception = null; - } catch (IllegalAccessException iae) { - exception = null; - } catch (NoSuchMethodException nsme) { - exception = null; - } - } - } + super(message, e); } } diff -r 96518f358a98 -r c3298bf492b1 src/com/sun/org/apache/xml/internal/dtm/DTMManager.java --- a/src/com/sun/org/apache/xml/internal/dtm/DTMManager.java Sun May 28 21:31:36 2017 -0700 +++ b/src/com/sun/org/apache/xml/internal/dtm/DTMManager.java Thu Sep 07 23:37:10 2017 -0700 @@ -1,13 +1,13 @@ /* - * reserved comment block - * DO NOT REMOVE OR ALTER! + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. */ /* - * Copyright 1999-2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * @@ -17,9 +17,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * $Id: DTMManager.java,v 1.2.4.1 2005/09/15 08:14:54 suresh_emailid Exp $ - */ package com.sun.org.apache.xml.internal.dtm; import com.sun.org.apache.xml.internal.res.XMLErrorResources; @@ -27,7 +24,6 @@ import com.sun.org.apache.xml.internal.utils.PrefixResolver; import com.sun.org.apache.xml.internal.utils.XMLStringFactory; import com.sun.org.apache.xalan.internal.utils.ObjectFactory; -import com.sun.org.apache.xalan.internal.utils.SecuritySupport; /** * A DTMManager instance can be used to create DTM and @@ -130,17 +126,17 @@ * * @return new DTMManager instance, never null. * - * @throws DTMConfigurationException + * @throws DTMException * if the implementation is not available or cannot be instantiated. */ public static DTMManager newInstance(XMLStringFactory xsf) - throws DTMConfigurationException + throws DTMException { return newInstance(xsf, true); } public static DTMManager newInstance(XMLStringFactory xsf, boolean useServicesMechanism) - throws DTMConfigurationException + throws DTMException { DTMManager factoryImpl = null; try @@ -154,14 +150,14 @@ } catch (ConfigurationError e) { - throw new DTMConfigurationException(XMLMessages.createXMLMessage( + throw new DTMException(XMLMessages.createXMLMessage( XMLErrorResources.ER_NO_DEFAULT_IMPL, null), e.getException()); //"No default implementation found"); } if (factoryImpl == null) { - throw new DTMConfigurationException(XMLMessages.createXMLMessage( + throw new DTMException(XMLMessages.createXMLMessage( XMLErrorResources.ER_NO_DEFAULT_IMPL, null)); //"No default implementation found"); } @@ -375,20 +371,6 @@ // -------------------- private methods -------------------- - /** - * Temp debug code - this will be removed after we test everything - */ - private static boolean debug; - - static - { - try - { - debug = SecuritySupport.getSystemProperty("dtm.debug") != null; - } - catch (SecurityException ex){} - } - /** This value, set at compile time, controls how many bits of the * DTM node identifier numbers are used to identify a node within a * document, and thus sets the maximum number of nodes per diff -r 96518f358a98 -r c3298bf492b1 src/com/sun/org/apache/xml/internal/res/XMLErrorResources_sv.java --- a/src/com/sun/org/apache/xml/internal/res/XMLErrorResources_sv.java Sun May 28 21:31:36 2017 -0700 +++ b/src/com/sun/org/apache/xml/internal/res/XMLErrorResources_sv.java Thu Sep 07 23:37:10 2017 -0700 @@ -233,7 +233,7 @@ "Axeltravers underst\u00F6ds inte: {0}"}, { ER_NO_DTMIDS_AVAIL, - "Inga fler DTM-ID:n \u00E4r tillg\u00E4ngliga"}, + "Inga fler DTM-id:n \u00E4r tillg\u00E4ngliga"}, { ER_NOT_SUPPORTED, "Underst\u00F6ds inte: {0}"}, diff -r 96518f358a98 -r c3298bf492b1 src/javax/xml/transform/TransformerConfigurationException.java --- a/src/javax/xml/transform/TransformerConfigurationException.java Sun May 28 21:31:36 2017 -0700 +++ b/src/javax/xml/transform/TransformerConfigurationException.java Thu Sep 07 23:37:10 2017 -0700 @@ -30,6 +30,8 @@ */ public class TransformerConfigurationException extends TransformerException { + private static final long serialVersionUID = 1285547467942875745L; + /** * Create a new TransformerConfigurationException with no * detail mesage. diff -r 96518f358a98 -r c3298bf492b1 src/javax/xml/transform/TransformerException.java --- a/src/javax/xml/transform/TransformerException.java Sun May 28 21:31:36 2017 -0700 +++ b/src/javax/xml/transform/TransformerException.java Thu Sep 07 23:37:10 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2017, 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 @@ -27,34 +27,44 @@ import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; +import java.security.AccessControlContext; +import java.security.AccessController; +import java.security.CodeSigner; +import java.security.CodeSource; +import java.security.PermissionCollection; +import java.security.Permissions; +import java.security.PrivilegedAction; +import java.security.ProtectionDomain; /** - * This class specifies an exceptional condition that occured + * This class specifies an exceptional condition that occurred * during the transformation process. */ public class TransformerException extends Exception { - /** Field locator specifies where the error occured */ + private static final long serialVersionUID = 975798773772956428L; + + /** Field locator specifies where the error occurred */ SourceLocator locator; /** * Method getLocator retrieves an instance of a SourceLocator - * object that specifies where an error occured. + * object that specifies where an error occurred. * * @return A SourceLocator object, or null if none was specified. */ public SourceLocator getLocator() { - return locator; + return this.locator; } /** * Method setLocator sets an instance of a SourceLocator - * object that specifies where an error occured. + * object that specifies where an error occurred. * * @param location A SourceLocator object, or null to clear the location. */ public void setLocator(SourceLocator location) { - locator = location; + this.locator = location; } /** Field containedException specifies a wrapped exception. May be null. */ @@ -74,7 +84,9 @@ * Returns the cause of this throwable or null if the * cause is nonexistent or unknown. (The cause is the throwable that * caused this throwable to get thrown.) + * @return the cause, or null if unknown */ + @Override public Throwable getCause() { return ((containedException == this) @@ -106,6 +118,7 @@ * {@link #TransformerException(String,Throwable)}, or this method has already * been called on this throwable. */ + @Override public synchronized Throwable initCause(Throwable cause) { if (this.containedException != null) { @@ -128,11 +141,7 @@ * @param message The error or warning message. */ public TransformerException(String message) { - - super(message); - - this.containedException = null; - this.locator = null; + this(message, null, null); } /** @@ -141,11 +150,7 @@ * @param e The exception to be wrapped. */ public TransformerException(Throwable e) { - - super(e.toString()); - - this.containedException = e; - this.locator = null; + this(null, null, e); } /** @@ -159,13 +164,7 @@ * @param e Any exception */ public TransformerException(String message, Throwable e) { - - super(((message == null) || (message.length() == 0)) - ? e.toString() - : message); - - this.containedException = e; - this.locator = null; + this(message, null, e); } /** @@ -179,11 +178,7 @@ * @param locator The locator object for the error or warning. */ public TransformerException(String message, SourceLocator locator) { - - super(message); - - this.containedException = null; - this.locator = locator; + this(message, locator, null); } /** @@ -196,8 +191,9 @@ */ public TransformerException(String message, SourceLocator locator, Throwable e) { - - super(message); + super(((message == null) || (message.length() == 0)) + ? ((e == null) ? "" : e.toString()) + : message); this.containedException = e; this.locator = locator; @@ -211,33 +207,16 @@ * location information appended. */ public String getMessageAndLocation() { - - StringBuffer sbuffer = new StringBuffer(); - String message = super.getMessage(); + StringBuilder sbuffer = new StringBuilder(); + String message = super.getMessage(); + String location = getLocationAsString(); if (null != message) { sbuffer.append(message); } - if (null != locator) { - String systemID = locator.getSystemId(); - int line = locator.getLineNumber(); - int column = locator.getColumnNumber(); - - if (null != systemID) { - sbuffer.append("; SystemID: "); - sbuffer.append(systemID); - } - - if (0 != line) { - sbuffer.append("; Line#: "); - sbuffer.append(line); - } - - if (0 != column) { - sbuffer.append("; Column#: "); - sbuffer.append(column); - } + if (null != location) { + sbuffer.append(location); } return sbuffer.toString(); @@ -250,9 +229,34 @@ * if there is no location information. */ public String getLocationAsString() { + if (locator == null) { + return null; + } - if (null != locator) { - StringBuffer sbuffer = new StringBuffer(); + if (System.getSecurityManager() == null) { + return getLocationString(); + } else { + return AccessController.doPrivileged( + new PrivilegedAction() { + public String run() { + return getLocationString(); + } + }, + new AccessControlContext(new ProtectionDomain[] {getNonPrivDomain()}) + ); + } + } + + /** + * Constructs the location string. + * @return the location string + */ + private String getLocationString() { + if (locator == null) { + return null; + } + + StringBuilder sbuffer = new StringBuilder(); String systemID = locator.getSystemId(); int line = locator.getLineNumber(); int column = locator.getColumnNumber(); @@ -273,9 +277,6 @@ } return sbuffer.toString(); - } else { - return null; - } } /** @@ -283,6 +284,7 @@ * originated. This will trace all nested exception * objects, as well as this object. */ + @Override public void printStackTrace() { printStackTrace(new java.io.PrintWriter(System.err, true)); } @@ -293,6 +295,7 @@ * objects, as well as this object. * @param s The stream where the dump will be sent to. */ + @Override public void printStackTrace(java.io.PrintStream s) { printStackTrace(new java.io.PrintWriter(s)); } @@ -303,6 +306,7 @@ * objects, as well as this object. * @param s The writer where the dump will be sent to. */ + @Override public void printStackTrace(java.io.PrintWriter s) { if (s == null) { @@ -356,15 +360,22 @@ } else { exception = null; } - } catch (InvocationTargetException ite) { - exception = null; - } catch (IllegalAccessException iae) { - exception = null; - } catch (NoSuchMethodException nsme) { + } catch (InvocationTargetException | IllegalAccessException + | NoSuchMethodException e) { exception = null; } } // insure output is written s.flush(); } + + /** + * Creates a ProtectionDomain that has no permission. + * @return a ProtectionDomain + */ + private ProtectionDomain getNonPrivDomain() { + CodeSource nullSource = new CodeSource(null, (CodeSigner[]) null); + PermissionCollection noPermission = new Permissions(); + return new ProtectionDomain(nullSource, noPermission); } +}