Skip to content

Commit

Permalink
8303530: Redefine JAXP Configuration File
Browse files Browse the repository at this point in the history
Reviewed-by: naoto, lancea, alanb, smarks
  • Loading branch information
JoeWang-Java committed Jun 2, 2023
1 parent 1bb037b commit aff9cea
Show file tree
Hide file tree
Showing 56 changed files with 3,366 additions and 770 deletions.
37 changes: 37 additions & 0 deletions make/modules/java.xml/Copy.gmk
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Copyright (c) 2023, 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.
#

include CopyCommon.gmk

################################################################################

XML_LIB_SRC := $(TOPDIR)/src/java.xml/share/conf

$(CONF_DST_DIR)/jaxp.properties: $(XML_LIB_SRC)/jaxp.properties
$(call install-file)

TARGETS := $(CONF_DST_DIR)/jaxp.properties

################################################################################
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2023, 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
Expand Down Expand Up @@ -31,7 +31,7 @@
/**
* This is the base class for features and properties
*
* @LastModified: May 2021
* @LastModified: Mar 2023
*/
public abstract class FeaturePropertyBase {

Expand Down Expand Up @@ -205,7 +205,7 @@ void getSystemProperty(Enum<?> property, String systemProperty) {
return;
}

value = SecuritySupport.readJAXPProperty(systemProperty);
value = SecuritySupport.readConfig(systemProperty);
if (value != null) {
values[property.ordinal()] = value;
states[property.ordinal()] = State.JAXPDOTPROPERTIES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand Down Expand Up @@ -39,7 +39,7 @@
/**
* @author Rajiv Mordani
* @author Edwin Goei
* @LastModified: May 2021
* @LastModified: Mar 2023
*/
public class DocumentBuilderFactoryImpl extends DocumentBuilderFactory {
/** These are DocumentBuilderFactory attributes not DOM attributes */
Expand Down Expand Up @@ -148,7 +148,7 @@ public Object getAttribute(String name)
//check if the property is managed by security manager
String pName;
if ((pName = fSecurityManager.find(name)) != null) {
return attributes.get(pName);
return fSecurityManager.getLimitAsString(pName);
} else if ((pName = fSecurityPropertyMgr.find(name)) != null) {
return attributes.get(pName);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023, 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
Expand Down Expand Up @@ -512,22 +512,17 @@ public boolean printEntityCountInfo() {
}

/**
* Read from system properties, or those in jaxp.properties
* Read system properties, or the configuration file
*/
private void readSystemProperties() {

for (Limit limit : Limit.values()) {
if (!getSystemProperty(limit, limit.systemProperty())) {
//if system property is not found, try the older form if any
for (NameMap nameMap : NameMap.values()) {
String oldName = nameMap.getOldName(limit.systemProperty());
if (oldName != null) {
getSystemProperty(limit, oldName);
}
}
// attempts to read both the current and old system propery
if (!getSystemProperty(limit, limit.systemProperty())
&& (!getOldSystemProperty(limit))) {
//if system property is not found, try the config file
getPropertyConfig(limit, limit.systemProperty());
}
}

}

// Array list to store printed warnings for each SAX parser used
Expand All @@ -548,9 +543,9 @@ public static void printWarning(String parserClassName, String propertyName, SAX
}

/**
* Read from system properties, or those in jaxp.properties
* Reads a system property, sets value and state if found.
*
* @param property the type of the property
* @param limit the limit property
* @param sysPropertyName the name of system property
*/
private boolean getSystemProperty(Limit limit, String sysPropertyName) {
Expand All @@ -561,8 +556,42 @@ private boolean getSystemProperty(Limit limit, String sysPropertyName) {
states[limit.ordinal()] = State.SYSTEMPROPERTY;
return true;
}
} catch (NumberFormatException e) {
//invalid setting
throw new NumberFormatException("Invalid setting for system property: " + limit.systemProperty());
}
return false;
}

value = SecuritySupport.readJAXPProperty(sysPropertyName);
/**
* Reads the legacy system property.
* @param limit a limit object
* @return true if found, false otherwise
*/
private boolean getOldSystemProperty(Limit limit) {
boolean found = false;
for (NameMap nameMap : NameMap.values()) {
String oldName = nameMap.getOldName(limit.systemProperty());
if (oldName != null) {
if (getSystemProperty(limit, oldName)) {
found = true;
break;
}
}
}
return found;
}

/**
* Reads a property from a configuration file, if any.
*
* @param limit the limit property
* @param sysPropertyName the name of system property
* @return
*/
private boolean getPropertyConfig(Limit limit, String sysPropertyName) {
try {
String value = SecuritySupport.readConfig(sysPropertyName);
if (value != null && !value.equals("")) {
values[limit.ordinal()] = Integer.parseInt(value);
states[limit.ordinal()] = State.JAXPDOTPROPERTIES;
Expand All @@ -575,7 +604,6 @@ private boolean getSystemProperty(Limit limit, String sysPropertyName) {
return false;
}


/**
* Convert a value set through setProperty to XMLSecurityManager.
* If the value is an instance of XMLSecurityManager, use it to override the default;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023, 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
Expand Down Expand Up @@ -231,7 +231,7 @@ private void getSystemProperty(Property property, String systemProperty) {
return;
}

value = SecuritySupport.readJAXPProperty(systemProperty);
value = SecuritySupport.readConfig(systemProperty);
if (value != null) {
values[property.ordinal()] = value;
states[property.ordinal()] = State.JAXPDOTPROPERTIES;
Expand Down

1 comment on commit aff9cea

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.