Skip to content

Commit

Permalink
8322214: Return value of XMLInputFactory.getProperty() changed from b…
Browse files Browse the repository at this point in the history
…oolean to String in JDK 22 early access builds

Reviewed-by: lancea
  • Loading branch information
JoeWang-Java committed Jan 4, 2024
1 parent 1cf9335 commit 755722c
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, 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 @@ -46,7 +46,7 @@
* @author K Venugopal
* @author Sunitha Reddy
*
* @LastModified: Nov 2023
* @LastModified: Jan 2024
*/
public class PropertyManager {

Expand Down Expand Up @@ -184,6 +184,9 @@ public boolean containsProperty(String property) {
* @return the value of a property
*/
public Object getProperty(String property) {
if (XMLInputFactory.SUPPORT_DTD.equals(property)) {
return fSecurityManager.is(XMLSecurityManager.Limit.STAX_SUPPORT_DTD);
}
/**
* Check to see if the property is managed by the security manager *
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand Down Expand Up @@ -79,7 +79,7 @@
* @author Arnaud Le Hors, IBM
* @author Andy Clark, IBM
*
* @LastModified: July 2023
* @LastModified: Jan 2024
*/
@SuppressWarnings("deprecation")
public abstract class AbstractSAXParser
Expand Down Expand Up @@ -1831,6 +1831,11 @@ else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) {
}
*/

// Handle properties managed by XMLSecurityManager
if (featureId.equals(XMLSecurityManager.DISALLOW_DTD)) {
return securityManager.is(XMLSecurityManager.Limit.XERCES_DISALLOW_DTD);
}

return fConfiguration.getFeature(featureId);
}
catch (XMLConfigurationException e) {
Expand Down
132 changes: 132 additions & 0 deletions test/jaxp/javax/xml/jaxp/unittest/common/dtd/DTDPropertiesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2024, 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.
*
* 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 common.dtd;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.stream.XMLInputFactory;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.xml.sax.XMLReader;

/*
* @test
* @bug 8322214
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
* @run testng common.dtd.DTDPropertiesTest
* @summary Verifies the getProperty function on DTD properties works the same
* as before the property 'jdk.xml.dtd.support' was introduced.
*/
public class DTDPropertiesTest {
// Xerces Property
public static final String DISALLOW_DTD = "http://apache.org/xml/features/disallow-doctype-decl";

/*
* DataProvider for verifying Xerces' disallow-DTD feature
* Fields: property name, setting (null indicates not specified), expected
*/
@DataProvider(name = "XercesProperty")
public Object[][] getXercesProperty() throws Exception {
return new Object[][] {
{ DISALLOW_DTD, null, false},
{ DISALLOW_DTD, true, true},
{ DISALLOW_DTD, false, false},
};
}

/*
* DataProvider for verifying StAX's supportDTD feature
* Fields: property name, setting (null indicates not specified), expected
*/
@DataProvider(name = "StAXProperty")
public Object[][] getStAXProperty() throws Exception {
return new Object[][] {
{ XMLInputFactory.SUPPORT_DTD, null, true},
{ XMLInputFactory.SUPPORT_DTD, true, true},
{ XMLInputFactory.SUPPORT_DTD, false, false},
};
}

/**
* Verifies the disallow DTD feature with SAX.
*
* @param name the name of the property
* @param setting the setting of the property, null means not specified
* @param expected the expected value
* @throws Exception if the test fails
*/
@Test(dataProvider = "XercesProperty")
public void testSAX(String name, Boolean setting, Boolean expected) throws Exception {
SAXParserFactory spf = SAXParserFactory.newDefaultInstance();
if (setting != null) {
spf.setFeature(name, setting);
}
Assert.assertEquals((Boolean)spf.getFeature(name), expected);
System.out.println(spf.getFeature(name));


SAXParser saxParser = spf.newSAXParser();
XMLReader reader = saxParser.getXMLReader();
Assert.assertEquals((Boolean)reader.getFeature(name), expected);
System.out.println(reader.getFeature(name));
}

/**
* Verifies the disallow DTD feature with DOM.
*
* @param name the name of the property
* @param setting the setting of the property, null means not specified
* @param expected the expected value
* @throws Exception if the test fails
*/
@Test(dataProvider = "XercesProperty")
public void testDOM(String name, Boolean setting, Boolean expected) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newDefaultInstance();
if (setting != null) {
dbf.setFeature(name, setting);
}
Assert.assertEquals((Boolean)dbf.getFeature(name), expected);
System.out.println(dbf.getFeature(name));
}

/**
* Verifies the StAX's supportDTD feature.
*
* @param name the name of the property
* @param setting the setting of the property, null means not specified
* @param expected the expected value
* @throws Exception if the test fails
*/
@Test(dataProvider = "StAXProperty")
public void testStAX(String name, Boolean setting, Boolean expected) throws Exception {
XMLInputFactory xif = XMLInputFactory.newInstance();
if (setting != null) {
xif.setProperty(name, setting);
}
Assert.assertEquals((Boolean)xif.getProperty(name), expected);
System.out.println((Boolean)xif.getProperty(name));
}
}

3 comments on commit 755722c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@JoeWang-Java
Copy link
Member Author

Choose a reason for hiding this comment

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

/backport jdk22

@openjdk
Copy link

@openjdk openjdk bot commented on 755722c Jan 4, 2024

Choose a reason for hiding this comment

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

@JoeWang-Java the backport was successfully created on the branch backport-JoeWang-Java-755722ce in my personal fork of openjdk/jdk22. To create a pull request with this backport targeting openjdk/jdk22:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 755722ce from the openjdk/jdk repository.

The commit being backported was authored by Joe Wang on 4 Jan 2024 and was reviewed by Lance Andersen.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk22:

$ git fetch https://github.com/openjdk-bots/jdk22.git backport-JoeWang-Java-755722ce:backport-JoeWang-Java-755722ce
$ git checkout backport-JoeWang-Java-755722ce
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk22.git backport-JoeWang-Java-755722ce

Please sign in to comment.