diff options
Diffstat (limited to 'document')
4 files changed, 20 insertions, 15 deletions
diff --git a/document/abi-spec.json b/document/abi-spec.json index 03a336ad36e..df1fb840cbc 100644 --- a/document/abi-spec.json +++ b/document/abi-spec.json @@ -3522,6 +3522,7 @@ "public long getNumber()", "public java.lang.String getGroup()", "public static com.yahoo.document.idstring.IdString createIdString(java.lang.String)", + "public static com.yahoo.document.idstring.IdString createIdStringLessStrict(java.lang.String)", "public static com.yahoo.document.idstring.IdString createFromSerialized(java.lang.String)", "protected void <init>(com.yahoo.document.idstring.IdString$Scheme, java.lang.String, java.lang.String)", "public com.yahoo.document.idstring.IdString$Scheme getType()", @@ -3535,7 +3536,9 @@ "public java.lang.String toString()", "public com.yahoo.text.Utf8String toUtf8()" ], - "fields": [] + "fields": [ + "public static final int MAX_LENGTH" + ] }, "com.yahoo.document.serialization.AnnotationReader": { "superClass": "java.lang.Object", diff --git a/document/src/main/java/com/yahoo/document/DocumentId.java b/document/src/main/java/com/yahoo/document/DocumentId.java index 30ca9be8231..26adb0b6dc5 100644 --- a/document/src/main/java/com/yahoo/document/DocumentId.java +++ b/document/src/main/java/com/yahoo/document/DocumentId.java @@ -2,7 +2,10 @@ package com.yahoo.document; import com.yahoo.document.idstring.IdString; -import com.yahoo.document.serialization.*; +import com.yahoo.document.serialization.DeserializationException; +import com.yahoo.document.serialization.DocumentReader; +import com.yahoo.document.serialization.DocumentWriter; +import com.yahoo.document.serialization.SerializationException; import com.yahoo.vespa.objects.Deserializer; import com.yahoo.vespa.objects.Identifiable; import com.yahoo.vespa.objects.Serializer; @@ -34,7 +37,7 @@ public class DocumentId extends Identifiable implements Serializable { throw new IllegalArgumentException("Cannot create DocumentId from null id."); } if (id.length() > IdString.MAX_LENGTH) { - throw new IllegalArgumentException("The document id(" + id.length() + ") is too long(65536). " + + throw new IllegalArgumentException("The document id(" + id.length() + ") is too long(" + IdString.MAX_LENGTH + "). " + "However if you have already fed a document earlier on and want to remove it, you can do so by " + "calling new DocumentId(IdString.createIdStringLessStrict()) that will bypass this restriction."); } diff --git a/document/src/main/java/com/yahoo/document/idstring/IdString.java b/document/src/main/java/com/yahoo/document/idstring/IdString.java index 404db928f30..c5f5a088bf9 100644 --- a/document/src/main/java/com/yahoo/document/idstring/IdString.java +++ b/document/src/main/java/com/yahoo/document/idstring/IdString.java @@ -53,7 +53,7 @@ public abstract class IdString { * The document id string can only contain text characters. */ public static IdString createIdString(String id) { - if (id.length() >= MAX_LENGTH) { + if (id.length() > MAX_LENGTH) { throw new IllegalArgumentException("Document id length " + id.length() + " is longer than max length of " + MAX_LENGTH); } validateTextString(id); diff --git a/document/src/test/java/com/yahoo/document/IdIdStringTest.java b/document/src/test/java/com/yahoo/document/IdIdStringTest.java index a94c3445d27..493fb35c97d 100644 --- a/document/src/test/java/com/yahoo/document/IdIdStringTest.java +++ b/document/src/test/java/com/yahoo/document/IdIdStringTest.java @@ -6,7 +6,6 @@ import com.yahoo.document.idstring.IdString; import org.junit.Test; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** @@ -17,19 +16,19 @@ import static org.junit.Assert.fail; */ public class IdIdStringTest { @Test - public void requireThatIdIdStringGeneratesProperString() throws Exception { + public void requireThatIdIdStringGeneratesProperString() { DocumentId docId = new DocumentId(new IdIdString("namespace", "type", "g=group", "foobar")); assertEquals("id:namespace:type:g=group:foobar", docId.toString()); } @Test - public void requireThatEmptyKeyValuesAreOk() throws Exception { + public void requireThatEmptyKeyValuesAreOk() { DocumentId docId = new DocumentId(new IdIdString("namespace", "type", "", "foobar")); assertEquals("id:namespace:type::foobar", docId.toString()); } @Test - public void requireThatIdIdStringCanBehaveLikeGroupDoc() throws Exception { + public void requireThatIdIdStringCanBehaveLikeGroupDoc() { DocumentId docId1 = new DocumentId(new IdIdString("namespace", "type", "g=foo", "foo")); DocumentId docId2 = new DocumentId(new IdIdString("namespace", "type", "g=foo", "bar")); DocumentId docId3 = new DocumentId(new IdIdString("namespace", "type", "g=bar", "baz")); @@ -38,7 +37,7 @@ public class IdIdStringTest { } @Test - public void requireThatIdIdStringCanBehaveLikeUserDoc() throws Exception { + public void requireThatIdIdStringCanBehaveLikeUserDoc() { DocumentId docId1 = new DocumentId(new IdIdString("namespace", "type", "n=10", "foo")); DocumentId docId2 = new DocumentId(new IdIdString("namespace", "type", "n=10", "bar")); DocumentId docId3 = new DocumentId(new IdIdString("namespace", "type", "n=20", "baz")); @@ -47,7 +46,7 @@ public class IdIdStringTest { } @Test - public void requireThatIllegalKeyValuesThrow() throws Exception { + public void requireThatIllegalKeyValuesThrow() { try { new IdIdString("namespace", "type", "illegal=key", "foo"); fail(); @@ -57,7 +56,7 @@ public class IdIdStringTest { } @Test - public void requireThatKeysWithoutValuesThrow() throws Exception { + public void requireThatKeysWithoutValuesThrow() { try { new IdIdString("namespace", "type", "illegal-pair", "foo"); fail(); @@ -67,7 +66,7 @@ public class IdIdStringTest { } @Test - public void requireTooLongIdThrowsWhileParsing() throws Exception { + public void requireTooLongIdThrowsWhileParsing() { StringBuilder builder = new StringBuilder("id:ns:type::namespacespecificpart_01"); for (int i = 0; i < 0x10000; i++) { builder.append('n'); @@ -78,12 +77,12 @@ public class IdIdStringTest { } catch (IllegalArgumentException e) { assertEquals("Document id length 65572 is longer than max length of 65536", e.getMessage()); } - // But there is a backdor + // But there is a backdoor assertEquals(65572, IdString.createIdStringLessStrict(builder.toString()).toString().length()); } @Test - public void requireThatTooLongPreNamespaceSpecificThrowsWhileParsing() throws Exception { + public void requireThatTooLongPreNamespaceSpecificThrowsWhileParsing() { StringBuilder builder = new StringBuilder("id:"); for (int i = 0; i < 0xff00; i++) { builder.append('n'); @@ -111,7 +110,7 @@ public class IdIdStringTest { } @Test - public void requireThatIdIdStringCanReplaceType() throws Exception { + public void requireThatIdIdStringCanReplaceType() { String type = IdIdString.replaceType("id:namespace:type::foo", "newType"); assertEquals("id:namespace:newType::foo", type); } |