Merge "Allow GenericDocument accept a String property longer than 20_000." into sc-dev am: 2873eb7d83
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15306276 Change-Id: I48bc72375d71cd2ba7b050e406cb5ef6e8d9b6a5
This commit is contained in:
@@ -51,9 +51,6 @@ import java.util.Set;
|
|||||||
public class GenericDocument {
|
public class GenericDocument {
|
||||||
private static final String TAG = "AppSearchGenericDocumen";
|
private static final String TAG = "AppSearchGenericDocumen";
|
||||||
|
|
||||||
/** The maximum {@link String#length} of a {@link String} field. */
|
|
||||||
private static final int MAX_STRING_LENGTH = 20_000;
|
|
||||||
|
|
||||||
/** The maximum number of indexed properties a document can have. */
|
/** The maximum number of indexed properties a document can have. */
|
||||||
private static final int MAX_INDEXED_PROPERTIES = 16;
|
private static final int MAX_INDEXED_PROPERTIES = 16;
|
||||||
|
|
||||||
@@ -1286,15 +1283,6 @@ public class GenericDocument {
|
|||||||
for (int i = 0; i < values.length; i++) {
|
for (int i = 0; i < values.length; i++) {
|
||||||
if (values[i] == null) {
|
if (values[i] == null) {
|
||||||
throw new IllegalArgumentException("The String at " + i + " is null.");
|
throw new IllegalArgumentException("The String at " + i + " is null.");
|
||||||
} else if (values[i].length() > MAX_STRING_LENGTH) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"The String at "
|
|
||||||
+ i
|
|
||||||
+ " length is: "
|
|
||||||
+ values[i].length()
|
|
||||||
+ ", which exceeds length limit: "
|
|
||||||
+ MAX_STRING_LENGTH
|
|
||||||
+ ".");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mProperties.putStringArray(name, values);
|
mProperties.putStringArray(name, values);
|
||||||
|
|||||||
@@ -62,4 +62,18 @@ public class GenericDocumentTest {
|
|||||||
assertThat(outDoc.getPropertyDocument("propDocument").getPropertyBytesArray("propBytes"))
|
assertThat(outDoc.getPropertyDocument("propDocument").getPropertyBytesArray("propBytes"))
|
||||||
.isEqualTo(new byte[][] {{3, 4}});
|
.isEqualTo(new byte[][] {{3, 4}});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPutLargeDocument_exceedLimit() throws Exception {
|
||||||
|
// Create a String property that has a very large property.
|
||||||
|
char[] chars = new char[10_000_000];
|
||||||
|
String property = new StringBuilder().append(chars).append("the end.").toString();
|
||||||
|
|
||||||
|
GenericDocument doc =
|
||||||
|
new GenericDocument.Builder<>("namespace", "id1", "schema1")
|
||||||
|
.setPropertyString("propString", property)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertThat(doc.getPropertyString("propString")).isEqualTo(property);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user