Sitelet https://github.com/googleapis/java-storage/issues/850
Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Storage#update always removes all lifecycle rules if they are not specified #850

Description

@sisidra

Issue with com.google.cloud.storage.Storage#update(com.google.cloud.storage.BucketInfo, com.google.cloud.storage.Storage.BucketTargetOption...)

Expected behaviour:

update only fields that are specified in BucketInfo parameter.

Actual behaviour:

along the updated fields, removes lifecycle rules if they are not specified.

Example code:

    val bucketId = "[...]"

    val client = StorageOptions.getDefaultInstance.getService
    val before = client.get(bucketId)
    println(s"Before: ${before.getLifecycleRules.size()}")

    val updateRequest = BucketInfo
      .newBuilder(bucketId)
      .setLabels(singletonMap("test", "test"))
      .build
    client.update(updateRequest)

    val after = client.get(bucketId)
    println(s"After: ${after.getLifecycleRules.size()}")

Actual output (for bucket with 1 lifecycle rule):

Before: 1
After: 0

I suspect that issue is located here:

Set<Rule> rules = new HashSet<>();
if (deleteRules != null) {
rules.addAll(
transform(
deleteRules,
new Function<DeleteRule, Rule>() {
@Override
public Rule apply(DeleteRule deleteRule) {
return deleteRule.toPb();
}
}));
}
if (lifecycleRules != null) {
rules.addAll(
transform(
lifecycleRules,
new Function<LifecycleRule, Rule>() {
@Override
public Rule apply(LifecycleRule lifecycleRule) {
return lifecycleRule.toPb();
}
}));
}
if (rules != null) {
Lifecycle lifecycle = new Lifecycle();
lifecycle.setRule(ImmutableList.copyOf(rules));
bucketPb.setLifecycle(lifecycle);
}

Activity

  1. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on May 27, 2021
  2. BenWhitehead commented on May 27, 2021

    @BenWhitehead
    Collaborator

    Thanks for reporting this, the fix is included in #852 and will go out in the next release.

  3. self-assigned this
    on May 27, 2021
  4. added
    priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.
    on May 27, 2021
  5. added a commit that references this issue on Jun 1, 2021
    3b1df1d
  6. added a commit that references this issue on Jun 1, 2021
  7. added a commit that references this issue on Sep 28, 2021
    447d35d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/java-storage API.priority: p1Important issue which blocks shipping the next release. Will be fixed prior to next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions