Skip to content

setIfNotExists does not check if key exist and creates key anyway #379

Description

@pzmi

Method setIfNotExists in EtcdClient is implemented like this:
Request.request().methodPUT().key(key).value(value).prevExist(false);
which results in this uri:
/v2/keys/KEY

As you can see there's nothing about previous value, prevExist=true is missing.

prevExist is omitted due to the current uri building implementation which for prevExist looks like this:
in paramBody method:

...
if ( prevExist ) {
    if (!first) builder.append("&");
    builder.append("prevExist=true");
    first=false;
}
...

Imo it should look somewhat like this:
private Boolean prevExist;

public Request prevExist(boolean prevExist) {
    this.prevExist = prevExist;
    return this;
}

in paramBody method:

...
if ( prevExist != null ) {
    if (!first) builder.append("&");
    builder.append("prevExist=");
    builder.append(prevExist);
    first=false;
}
...

Reproduction:
use EtcdClient#setIfNotExists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions