Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK-11486: Add failing test case for session-mapped non-registered #2081

Draft
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,13 @@ public synchronized String getJcrName(@NotNull String oakName) {
checkArgument(!oakName.startsWith(":"), oakName); // hidden name
checkArgument(!isExpandedName(oakName), oakName); // expanded name

if (!local.isEmpty()) {
int colon = oakName.indexOf(':');
if (colon > 0) {
String oakPrefix = oakName.substring(0, colon);
String uri = getNamespacesProperty(oakPrefix);
if (uri == null) {
throw new IllegalStateException(
"No namespace mapping found for " + oakName);
}
int colon = oakName.indexOf(':');
if (colon > 0) {
String oakPrefix = oakName.substring(0, colon);
String uri = getNamespacesProperty(oakPrefix);

if (local.containsValue(uri)) {
//local prefix replaces global prefix
for (Map.Entry<String, String> entry : local.entrySet()) {
if (uri.equals(entry.getValue())) {
String jcrPrefix = entry.getKey();
Expand All @@ -78,22 +75,15 @@ public synchronized String getJcrName(@NotNull String oakName) {
}
}
}

// local mapping not found for this URI, make sure there
// is no conflicting local mapping for the prefix
if (local.containsKey(oakPrefix)) {
for (int i = 2; true; i++) {
String jcrPrefix = oakPrefix + i;
if (!local.containsKey(jcrPrefix)) {
log.warn("no prefix found for namespace name '" + uri + "', using unmapped temporary prefix '"
+ jcrPrefix + "' for now (see OAK-10544)");
return jcrPrefix + oakName.substring(colon);
}
}
}
} else if (uri == null && !local.containsKey(oakPrefix)) {
//completely unknown prefix
throw new IllegalStateException("No namespace mapping found for " + oakName);
Copy link
Member Author

Choose a reason for hiding this comment

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

With that we are back at the same exception as before :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

actually we are now throwing an exception even earlier (i.e. for the first getName() without any mapping)

Copy link
Contributor

Choose a reason for hiding this comment

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

That was an intermediate version. This current one should hopefully do, except for the problem I mentioned on Jira, which probably is something completely different.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wouldn't understand why Session.addNode("foo:bar").getName() wouldn't end up here, because

a) uri is null (there is no namespace URI registered for "foo" neither globally nor locally
b) there is no local namespace mapping for "foo"

This previously didn't lead to an exception. Now it does.

}
}

//locally registered, but not yet globally known
//or globally known, but not locally overridden
//or empty namespace
return oakName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@
import java.util.List;
import java.util.concurrent.CountDownLatch;

import javax.jcr.ItemExistsException;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.observation.Event;
import javax.jcr.observation.EventIterator;
import javax.jcr.observation.EventListener;
import javax.jcr.observation.ObservationManager;
import javax.jcr.version.VersionException;

import org.apache.jackrabbit.JcrConstants;
import org.apache.jackrabbit.api.JackrabbitNode;
Expand Down Expand Up @@ -336,4 +341,11 @@ public void testGetPropertyOrNull() throws Exception {
assertNotNull(jn.getPropertyOrNull(JcrConstants.JCR_PRIMARYTYPE));
assertNotNull(jn.getPropertyOrNull("a/aa/p"));
}

public void testSessionMappedPrefixWithUnregisteredNamespace() throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, RepositoryException {
Node n = testRootNode.addNode("foo:bar");
assertEquals("foo:bar", n.getName());
n.getSession().setNamespacePrefix("foo", "http://foo.com");
assertEquals("foo:bar", n.getName()); // this must not fail, but throws a ISE
}
}
Loading