Giter Club home page Giter Club logo

Comments (5)

dmitry-fa avatar dmitry-fa commented on July 28, 2024

Looks like a bug: getStorageClass() of BucketInfo.LifecycleRule.SetStorageClassLifecycleAction class should be declared as public.

To workaround this issue you can create a class in the same package:

package com.google.cloud.storage;

public class StorageClassExtractor {
    public static StorageClass extract(BucketInfo.LifecycleRule.LifecycleAction lifecycleAction) {
        return ((BucketInfo.LifecycleRule.SetStorageClassLifecycleAction)lifecycleAction).getStorageClass();
    }
}

Then you can use your helper class to access this method:

package storage;

import com.google.cloud.storage.BucketInfo;
import com.google.cloud.storage.StorageClass;
import com.google.cloud.storage.StorageClassExtractor;

public class LifecycleActionTest {
    public static void main(String... args) {
        BucketInfo.LifecycleRule.LifecycleAction lifecycleAction =
                BucketInfo.LifecycleRule.LifecycleAction.newSetStorageClassAction(StorageClass.MULTI_REGIONAL);
        if (lifecycleAction.getActionType().equals(BucketInfo.LifecycleRule.SetStorageClassLifecycleAction.TYPE)) {
            System.out.println(StorageClassExtractor.extract(lifecycleAction));
        }

    }
}

from java-storage.

rmunna avatar rmunna commented on July 28, 2024

To workaround this issue you can create a class in the same package:

I don't get it.. Could you please elaborate.

when can I expect the bug fix on google-cloud-storage-1.7.8.0.jar?

from java-storage.

dmitry-fa avatar dmitry-fa commented on July 28, 2024

To workaround this issue you can create a class in the same package:

I don't get it.. Could you please elaborate.
You can create StorageClassExtractor.java file in your project, it will have an access to the method your need. In your app you can use StorageClassExtractor to get StorageClass.

when can I expect the bug fix on google-cloud-storage-1.7.8.0.jar?

I will work on it, but I can't promise any date.

from java-storage.

rmunna avatar rmunna commented on July 28, 2024

workaround:

public StorageClass extractStorageClass(LifecycleAction lifecycleAction) {
    try {
      Method method = SetStorageClassLifecycleAction.class.getDeclaredMethod("getStorageClass");
      method.setAccessible(true);
      return (StorageClass)method.invoke(lifecycleAction);
    } catch (ReflectiveOperationException e) {
      throw new RuntimeException("Exception while reading storage class from lifecycle rules", e);
    }
  }

from java-storage.

dmitry-fa avatar dmitry-fa commented on July 28, 2024

Yes, this is another workaround. But it will not work if you have security restrictions preventing you from invoking private methods. If you don't have such restrictions this will work fine.

from java-storage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.