spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

Bug in ParameterBindingJsonReader - visitUUIDConstructor - UUID subtype 04

Open arn-cpu opened this issue 3 years ago • 1 comments

Hi, there is a bug in private method BsonBinary visitUUIDConstructor(String uuidConstructorName) in ParameterBindingJsonReader class:

private BsonBinary visitUUIDConstructor(String uuidConstructorName) {
        this.verifyToken(JsonTokenType.LEFT_PAREN);
        String hexString = this.readStringFromExtendedJson().replaceAll("\\{", "").replaceAll("}", "").replaceAll("-", "");
        this.verifyToken(JsonTokenType.RIGHT_PAREN);
        byte[] bytes = decodeHex(hexString);
        BsonBinarySubType subType = BsonBinarySubType.UUID_STANDARD;
        if (!"UUID".equals(uuidConstructorName) || !"GUID".equals(uuidConstructorName)) {
            subType = BsonBinarySubType.UUID_LEGACY;
        }

        return new BsonBinary(subType, bytes);
    }

It should be following, because if not UUID and not GUID then use legacy UUID:

if (!"UUID".equals(uuidConstructorName) && !"GUID".equals(uuidConstructorName)) {
            subType = BsonBinarySubType.UUID_LEGACY;
        }

Now when I use UUID I get subtype 03 instead of 04 which I use on database so I can't perform my query correctly. I am trying to use @Query annotation with UUID('id') and I can't get any records, because query is wrongly encoded. I have to make some workaround with mongoTemplate or something else.

arn-cpu avatar Jul 26 '21 09:07 arn-cpu

Seems we missed a series of upstream changes:

  • https://github.com/mongodb/mongo-java-driver/commit/01019c72e4114c735f3b8aff001469f63a93bac7#diff-f6bf6fedf45851bd80b6bee279186d6832b41e5a2cf241a5eb366e46650be705
  • https://github.com/mongodb/mongo-java-driver/commit/f16761c3ec1deeb1f695c7c88d82823ae8bb1549#diff-f6bf6fedf45851bd80b6bee279186d6832b41e5a2cf241a5eb366e46650be705
  • https://github.com/mongodb/mongo-java-driver/commit/f0439b5fe9c3bfa7ca2bb1f31e8d3c5b73be10b0#diff-f6bf6fedf45851bd80b6bee279186d6832b41e5a2cf241a5eb366e46650be705

mp911de avatar Jul 26 '21 11:07 mp911de