[
https://issues.apache.org/jira/browse/SLING-2913?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Antonio Sanso updated SLING-2913:
---------------------------------
Attachment: SLING-2913-patch.txt
attaching proposed patch.
Tests to follow
> Issue in AbstractCreateOperation#deepGetOrCreateNode
> ----------------------------------------------------
>
> Key: SLING-2913
> URL: https://issues.apache.org/jira/browse/SLING-2913
> Project: Sling
> Issue Type: Bug
> Components: Servlets
> Reporter: Antonio Sanso
> Attachments: SLING-2913-patch.txt
>
>
> While updating the AbstractCreateOperation to use new CRUD support in POST
> servlet has been some lost in translation.
> The previous code looked like
> {code}
> protected Node deepGetOrCreateNode(Session session, String path,
> Map<String, RequestProperty> reqProperties, List<Modification>
> changes,
> VersioningConfiguration versioningConfiguration)
> throws RepositoryException {
> if (log.isDebugEnabled()) {
> log.debug("Deep-creating Node '{}'", path);
> }
> if (path == null || !path.startsWith("/")) {
> throw new IllegalArgumentException("path must be an absolute
> path.");
> }
> // get the starting node
> String startingNodePath = path;
> Node startingNode = null;
> while (startingNode == null) {
> if (startingNodePath.equals("/")) {
> startingNode = session.getRootNode();
> } else if (session.itemExists(startingNodePath)) {
> startingNode = (Node) session.getItem(startingNodePath);
> updateNodeType(session, startingNodePath, reqProperties,
> changes, versioningConfiguration);
> updateMixins(session, startingNodePath, reqProperties,
> changes, versioningConfiguration);
> } else {
> int pos = startingNodePath.lastIndexOf('/');
> if (pos > 0) {
> startingNodePath = startingNodePath.substring(0, pos);
> } else {
> startingNodePath = "/";
> }
> }
> }
> {code}
> while the updated is
> {code}
> protected Resource deepGetOrCreateNode(final ResourceResolver resolver,
> final String path,
> final Map<String, RequestProperty> reqProperties,
> final List<Modification> changes,
> final VersioningConfiguration versioningConfiguration)
> throws PersistenceException, RepositoryException {
> if (log.isDebugEnabled()) {
> log.debug("Deep-creating resource '{}'", path);
> }
> if (path == null || !path.startsWith("/")) {
> throw new IllegalArgumentException("path must be an absolute
> path.");
> }
> // get the starting resource
> String startingResourcePath = path;
> Resource startingResource = null;
> while (startingResource == null) {
> if (startingResourcePath.equals("/")) {
> startingResource = resolver.getResource("/");
> } else if (resolver.getResource(startingResourcePath) != null) {
> startingResource = resolver.getResource(startingResourcePath);
> updateNodeType(resolver, startingResourcePath, reqProperties,
> changes, versioningConfiguration);
> updateMixins(resolver, startingResourcePath, reqProperties,
> changes, versioningConfiguration);
> } else {
> int pos = startingResourcePath.lastIndexOf('/');
> if (pos > 0) {
> startingResourcePath = startingResourcePath.substring(0,
> pos);
> } else {
> startingResourcePath = "/";
> }
> }
> }
> {code}
> The main difference is in that the
> startingNode = session.getRootNode(); could throw a RepositoryException e.g.
> if the session did not have enough permission while startingResource =
> resolver.getResource("/"); would just return null.
> This might cause a theoretical infinite loop.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira