jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From un...@apache.org
Subject svn commit: r1446512 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/query/lucene/Util.java test/java/org/apache/jackrabbit/core/query/lucene/UtilTest.java
Date Fri, 15 Feb 2013 11:07:18 GMT
Author: unico
Date: Fri Feb 15 11:07:17 2013
New Revision: 1446512

URL: http://svn.apache.org/r1446512
Log:
JCR-3521 fix comparable contract violation which breaks search sort on Java 7: applying patch
by Chetan Mehrotra

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/UtilTest.java
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java?rev=1446512&r1=1446511&r2=1446512&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/Util.java
Fri Feb 15 11:07:17 2013
@@ -257,6 +257,9 @@ public class Util {
      * consistent
      */
     public static int compare(Comparable<?>[] c1, Comparable<?>[] c2) {
+        if(c1 == null && c2 == null){
+            return 0;
+        }
         if (c1 == null) {
             return -1;
         }
@@ -280,6 +283,9 @@ public class Util {
      * consistent
      */
     public static int compare(Value[] a, Value[] b) throws RepositoryException {
+        if(a == null && b == null){
+            return 0;
+        }
         if (a == null) {
             return -1;
         }

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/UtilTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/UtilTest.java?rev=1446512&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/UtilTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/UtilTest.java
Fri Feb 15 11:07:17 2013
@@ -0,0 +1,67 @@
+/*
+ * 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.core.query.lucene;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
+import junit.framework.TestCase;
+import org.apache.jackrabbit.value.ValueFactoryImpl;
+import org.junit.Test;
+
+public class UtilTest extends TestCase {
+
+    public void testComparableContract(){
+        //The test data needs to be greater than 32 in length to trigger TimSort
+        //The data was obtained by running multiple runs with random sequence
+        //and then reverse engineered from it :)
+        Integer[] data = {null,25,21,5,null,23,10,19,10,null,null,10,24,null,10,null,7,11,
+                null,7,null,14,26,0,6,19,null,5,null,4,28,19,5,28,18,14,12,16,14,15};
+        List<Value[]> testData = createValueArrayList(data);
+        Collections.sort(testData, new ValueArrayComparator());
+    }
+
+    private static List<Value[]> createValueArrayList(Integer[] data){
+        List<Value[]> result = new ArrayList<Value[]>(data.length);
+        for(Integer i : data){
+            Value[] r = null;
+            if(i != null){
+                r = new Value[]{ValueFactoryImpl.getInstance().createValue(i.longValue())};
+            }
+            result.add(r);
+        }
+        return result;
+    }
+
+    private static class ValueArrayComparator implements Comparator<Value[]> {
+        @Override
+        public int compare(Value[] a, Value[] b) {
+            try {
+                return Util.compare(a, b);
+            } catch (RepositoryException e) {
+                throw new RuntimeException("Unable to compare values "
+                        + Arrays.toString(a) + " and " + Arrays.toString(b), e);
+            }
+        }
+    }
+}



Mime
View raw message