mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
Merge pull request #1448 from Alfresco/fix/MNT-23094_prevent-error-when-sorting-by-empty-field
[MNT-23094] Prevent ArrayIndexOutOfBoundsException when sorting by empty field (cherry picked from commit b113a05f6f1e9245a6bb01e4af1a258668aa46ea)
This commit is contained in:
committed by
Tiago Salvado
parent
e8e9799035
commit
7a67c6ac41
+23
-13
@@ -162,29 +162,39 @@ public class AlfrescoCollatableTextFieldType extends StrField
|
||||
return values[slot];
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the term string value for supplied doc
|
||||
*
|
||||
* @param doc
|
||||
* the document id that was hit
|
||||
* @param term
|
||||
* a {@link BytesRef} object representing an UTF8 encoded term in the index
|
||||
*
|
||||
* @return the term value in string format
|
||||
*/
|
||||
private String findBestValue(int doc, BytesRef term)
|
||||
{
|
||||
if (term.length == 0 && docsWithField != null && docsWithField.get(doc) == false)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// Converts the stored bytes (as UTF8) to string
|
||||
String withLocale = term.utf8ToString();
|
||||
|
||||
// split strin into MLText object
|
||||
if (withLocale == null)
|
||||
{
|
||||
return withLocale;
|
||||
}
|
||||
else if (withLocale.startsWith("\u0000"))
|
||||
|
||||
if (withLocale != null && withLocale.startsWith("\u0000"))
|
||||
{
|
||||
// the array can either be [, locale, term value] or just [, locale] depending whether the term value used
|
||||
// to perform the sort is empty or not
|
||||
String[] parts = withLocale.split("\u0000");
|
||||
return parts[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
return withLocale;
|
||||
|
||||
if (parts != null && parts.length == 3)
|
||||
{
|
||||
return parts[2];
|
||||
}
|
||||
}
|
||||
|
||||
return withLocale;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
+13
@@ -173,4 +173,17 @@ public class AlfrescoCollatableTextFieldTypeTest
|
||||
verify(mockCollator).compare("NotNull1", "NotNull2");
|
||||
assertEquals("Expected result to be obtained from collator.", comparisonResult, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMNT23094()
|
||||
{
|
||||
// Set up the document to have an encoded value for the field.
|
||||
when(mockDocTerms.get(DOC)).thenReturn(new BytesRef("\u0000"));
|
||||
when(mockDocsWithField.get(DOC)).thenReturn(false);
|
||||
|
||||
// Call the method under test.
|
||||
textSortFieldComparator.compareBottom(DOC);
|
||||
|
||||
verify(mockCollator).compare(BOTTOM_STRING, "\u0000");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user