Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud Storage: getStorageClass in SetStorageClassLifecycleAction is not visible #21

Closed
rmunna opened this issue Dec 17, 2019 · 5 comments · Fixed by #22
Closed

Cloud Storage: getStorageClass in SetStorageClassLifecycleAction is not visible #21

rmunna opened this issue Dec 17, 2019 · 5 comments · Fixed by #22
Assignees
Labels
api: storage Issues related to the googleapis/java-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@rmunna
Copy link

rmunna commented Dec 17, 2019

getStorageClass() method in SetStorageClassLifecycleAction class is only visible inside the package. Its not accessible outside the package.

I am trying to read storage class set by the lifecycle rule through SDK in the following way. looks like its not possible. Can you suggest any other alternative to access if this is not possible.

f (lifecycleAction.getActionType().equals(SetStorageClassLifecycleAction.TYPE)) {
     return ((SetStorageClassLifecycleAction)lifeCycleRule.getAction()).getStorageClass(); 
}

// Compiler error : The method getStorageClass() from the type BucketInfo.LifecycleRule.SetStorageClassLifecycleAction is not visible

Environment details

OS type and version: Windows 10
Java version: JDK 11
sdk version: google-cloud-storage-1.7.8.0.jar

@dmitry-fa
Copy link
Contributor

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));
        }

    }
}

@rmunna
Copy link
Author

rmunna commented Dec 20, 2019

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?

@dmitry-fa
Copy link
Contributor

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.

@rmunna
Copy link
Author

rmunna commented Dec 25, 2019

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);
    }
  }

@dmitry-fa
Copy link
Contributor

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.

@athakor athakor transferred this issue from googleapis/google-cloud-java Dec 27, 2019
@athakor athakor added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Dec 27, 2019
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. triage me I really want to be triaged. labels Dec 27, 2019
@athakor athakor removed triage me I really want to be triaged. 🚨 This issue needs some love. labels Dec 27, 2019
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Dec 27, 2019
@google-cloud-label-sync google-cloud-label-sync bot added the api: storage Issues related to the googleapis/java-storage API. label Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/java-storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants