You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2008/07/18 14:58:24 UTC

svn commit: r677893 - in /jackrabbit/trunk/jackrabbit-jcr-server: ./ src/main/java/org/apache/jackrabbit/webdav/jcr/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/jackrabbit/ src/test/java/org/apache/jac...

Author: angela
Date: Fri Jul 18 05:58:22 2008
New Revision: 677893

URL: http://svn.apache.org/viewvc?rev=677893&view=rev
Log:
JCR-1678: NullPointerException in constructor of JcrDavException

Added:
    jackrabbit/trunk/jackrabbit-jcr-server/src/test/
    jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/
    jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/
    jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/
    jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/
    jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/
    jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/
    jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/JcrDavExceptionTest.java   (with props)
    jackrabbit/trunk/jackrabbit-jcr-server/src/test/resources/
    jackrabbit/trunk/jackrabbit-jcr-server/src/test/resources/log4j.properties   (with props)
Modified:
    jackrabbit/trunk/jackrabbit-jcr-server/pom.xml
    jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/JcrDavException.java

Modified: jackrabbit/trunk/jackrabbit-jcr-server/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/pom.xml?rev=677893&r1=677892&r2=677893&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/pom.xml Fri Jul 18 05:58:22 2008
@@ -45,6 +45,21 @@
     <url>http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server</url>
   </scm>
 
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/*Test.java</include>
+          </includes>
+          <forkMode>once</forkMode>
+          <argLine>-Xmx128m -enableassertions</argLine>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
   <dependencies>
     <dependency>
       <groupId>javax.jcr</groupId>

Modified: jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/JcrDavException.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/JcrDavException.java?rev=677893&r1=677892&r2=677893&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/JcrDavException.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/main/java/org/apache/jackrabbit/webdav/jcr/JcrDavException.java Fri Jul 18 05:58:22 2008
@@ -44,7 +44,10 @@
 import javax.jcr.nodetype.NoSuchNodeTypeException;
 import javax.jcr.query.InvalidQueryException;
 import javax.jcr.version.VersionException;
-import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.LinkedHashMap;
+
 
 /**
  * <code>JcrDavException</code> extends the {@link DavException} in order to
@@ -54,8 +57,8 @@
 
     private static Logger log = LoggerFactory.getLogger(JcrDavException.class);
 
-    // mapping of Jcr exceptions to error codes.
-    private static HashMap codeMap = new HashMap();
+    // ordered mapping of Jcr exceptions to error codes.
+    private static Map codeMap = new LinkedHashMap(20);
     static {
         codeMap.put(AccessDeniedException.class, new Integer(DavServletResponse.SC_FORBIDDEN));
         codeMap.put(ConstraintViolationException.class, new Integer(DavServletResponse.SC_CONFLICT));
@@ -71,13 +74,30 @@
         codeMap.put(NoSuchWorkspaceException.class, new Integer(DavServletResponse.SC_CONFLICT));
         codeMap.put(PathNotFoundException.class, new Integer(DavServletResponse.SC_CONFLICT));
         codeMap.put(ReferentialIntegrityException.class, new Integer(DavServletResponse.SC_CONFLICT));
-        codeMap.put(RepositoryException.class, new Integer(DavServletResponse.SC_FORBIDDEN));
         codeMap.put(LoginException.class, new Integer(DavServletResponse.SC_UNAUTHORIZED));
         codeMap.put(UnsupportedRepositoryOperationException.class, new Integer(DavServletResponse.SC_NOT_IMPLEMENTED));
         codeMap.put(ValueFormatException.class, new Integer(DavServletResponse.SC_CONFLICT));
         codeMap.put(VersionException.class, new Integer(DavServletResponse.SC_CONFLICT));
+        codeMap.put(RepositoryException.class, new Integer(DavServletResponse.SC_FORBIDDEN));
     }
 
+    private static int lookupErrorCode(Class exceptionClass) {
+        Integer code = (Integer) codeMap.get(exceptionClass);
+        if (code == null) {
+            for (Iterator it = codeMap.keySet().iterator(); it.hasNext();) {
+                Class jcrExceptionClass = (Class) it.next();
+                if (jcrExceptionClass.isAssignableFrom(exceptionClass)) {
+                    code = (Integer) codeMap.get(jcrExceptionClass);
+                    break;
+                }
+            }
+            if (code == null) {
+                code = new Integer(DavServletResponse.SC_FORBIDDEN); // fallback
+            }
+        }
+        return code.intValue();
+    }
+    
     private Class exceptionClass;
 
     /**
@@ -108,7 +128,7 @@
      * @see JcrDavException#JcrDavException(Throwable, int)
      */
     public JcrDavException(RepositoryException cause) {
-        this(cause, ((Integer)codeMap.get(cause.getClass())).intValue());
+        this(cause, lookupErrorCode(cause.getClass()));
     }
 
     /**
@@ -136,4 +156,4 @@
         error.appendChild(excep);
         return error;
     }
-}
\ No newline at end of file
+}

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/JcrDavExceptionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/JcrDavExceptionTest.java?rev=677893&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/JcrDavExceptionTest.java (added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/JcrDavExceptionTest.java Fri Jul 18 05:58:22 2008
@@ -0,0 +1,54 @@
+/*
+ * 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.jackrabbit.webdav.jcr;
+
+import junit.framework.TestCase;
+
+import javax.jcr.lock.LockException;
+import javax.jcr.RepositoryException;
+
+/** <code>JcrDavExceptionTest</code>... */
+public class JcrDavExceptionTest extends TestCase {
+
+    public void testDerivedException() {
+        RepositoryException re = new DerievedRepositoryException();
+
+        // creating JcrDavException from the derived exception must not throw
+        // NPE (see issue https://issues.apache.org/jira/browse/JCR-1678)
+        JcrDavException jde = new JcrDavException(re);
+
+        // error code must be the same as for LockException
+        assertEquals(new JcrDavException(new LockException()).getErrorCode(),
+                     jde.getErrorCode());
+    }
+
+    public void testNullException() {
+        try {
+            new JcrDavException(null);
+            fail("Should throw NPE");
+        } catch (NullPointerException e) {
+            // as documented in the javadoc
+        }
+    }
+
+    /**
+     * Derived exception that does not extend from RepositoryException, which
+     * returns the 'default' error code.
+     */
+    private static final class DerievedRepositoryException extends LockException {
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/JcrDavExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/test/java/org/apache/jackrabbit/webdav/jcr/JcrDavExceptionTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Added: jackrabbit/trunk/jackrabbit-jcr-server/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-server/src/test/resources/log4j.properties?rev=677893&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-server/src/test/resources/log4j.properties (added)
+++ jackrabbit/trunk/jackrabbit-jcr-server/src/test/resources/log4j.properties Fri Jul 18 05:58:22 2008
@@ -0,0 +1,34 @@
+#  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.
+
+# Set root logger level to INFO and its only appender to file.
+log4j.rootLogger=INFO, file
+#log4j.rootLogger=DEBUG, stdout, file
+#log4j.rootLogger=ERROR, stdout, file
+
+# 'stdout' is set to be a ConsoleAppender.
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+
+# 'stdout' uses PatternLayout
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m (%F, line %L)\n
+
+# 'file' is set to be a FileAppender.
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.File=target/jcr.log
+
+# 'file' uses PatternLayout.
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{dd.MM.yyyy HH:mm:ss} *%-5p* [%t] %c{1}: %m (%F, line %L)\n

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn = 

Propchange: jackrabbit/trunk/jackrabbit-jcr-server/src/test/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native