SLING-1490 - use DEBUG log level for RepositoryException that indicates builtin nodetype being re-registered
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@934712 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index fbb0dcc..272bff3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -127,6 +127,16 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/src/main/java/org/apache/sling/jcr/base/NodeTypeLoader.java b/src/main/java/org/apache/sling/jcr/base/NodeTypeLoader.java
index c4b05f8..fe1b8b3 100644
--- a/src/main/java/org/apache/sling/jcr/base/NodeTypeLoader.java
+++ b/src/main/java/org/apache/sling/jcr/base/NodeTypeLoader.java
@@ -76,7 +76,11 @@
} catch (IOException ioe) {
log.error("Cannot register node types from " + source, ioe);
} catch (RepositoryException re) {
- log.error("Cannot register node types from " + source, re);
+ if(isReRegisterBuiltinNodeType(re)) {
+ log.debug("Attempt to re-register built-in node type from " + source, re);
+ } else {
+ log.error("Cannot register node types from " + source, re);
+ }
} finally {
if (ins != null) {
try {
@@ -118,9 +122,22 @@
try {
Workspace wsp = session.getWorkspace();
CndImporter.registerNodeTypes(reader, systemId, wsp.getNodeTypeManager(), wsp.getNamespaceRegistry(), session.getValueFactory(), reregisterExisting);
+ } catch(RepositoryException re) {
+ if(isReRegisterBuiltinNodeType(re)) {
+ log.debug("Attempt to re-register built-in node type, RepositoryException ignored", re);
+ } else {
+ throw re;
+ }
} catch (ParseException e) {
throw new IOException("Unable to parse CND Input: " + e.getMessage());
}
return true;
}
+
+ /** True if we think e was caused by an attempt to reregister a built-in node type */
+ static boolean isReRegisterBuiltinNodeType(Exception e) {
+ return
+ (e instanceof RepositoryException)
+ & (e.getMessage() != null && e.getMessage().contains("reregister built-in node type"));
+ }
}
diff --git a/src/test/java/org/apache/sling/jcr/base/NodeTypeLoaderTest.java b/src/test/java/org/apache/sling/jcr/base/NodeTypeLoaderTest.java
new file mode 100644
index 0000000..a71a67d
--- /dev/null
+++ b/src/test/java/org/apache/sling/jcr/base/NodeTypeLoaderTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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
+ *
+ * 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.
+ */
+package org.apache.sling.jcr.base;
+
+import javax.jcr.RepositoryException;
+
+import org.junit.Test;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class NodeTypeLoaderTest {
+
+ @Test
+ public void testisReRegisterBuiltinNodeType() {
+ assertFalse("Exception does not match",
+ NodeTypeLoader.isReRegisterBuiltinNodeType(new Exception()));
+ assertFalse("Plain RepositoryException does not match",
+ NodeTypeLoader.isReRegisterBuiltinNodeType(new RepositoryException()));
+ assertFalse("Non-reregister RepositoryException does not match",
+ NodeTypeLoader.isReRegisterBuiltinNodeType(new RepositoryException("builtin that's it")));
+ assertTrue("Reregister RepositoryException matches",
+ NodeTypeLoader.isReRegisterBuiltinNodeType(
+ new RepositoryException("{http://www.jcp.org/jcr/mix/1.0}language: can't reregister built-in node type")));
+ }
+}