code: public Bucket getBucketPolicyOnly(String bucketName) throws StorageException {
      // [START storage_get_bucket_policy_only]
      // Instantiate a Google Cloud Storage client
      Storage storage = StorageOptions.getDefaultInstance().getService();
  
      // The name of a bucket, e.g. "my-bucket"
      // String bucketName = "my-bucket";
  
      Bucket bucket = storage.get(bucketName, BucketGetOption.fields(BucketField.IAMCONFIGURATION));
      BucketInfo.IamConfiguration iamConfiguration = bucket.getIamConfiguration();
  
      Boolean enabled = iamConfiguration.isBucketPolicyOnlyEnabled();
      Date lockedTime = new Date(iamConfiguration.getBucketPolicyOnlyLockedTime());
  
      if (enabled != null && enabled) {
        System.out.println("Bucket Policy Only is enabled for " + bucketName);
        System.out.println("Bucket will be locked on " + lockedTime);
      } else {
        System.out.println("Bucket Policy Only is disabled for " + bucketName);
      }
      // [END storage_get_bucket_policy_only]
      return bucket;
    }
docs: Example of how to get Bucket Policy Only metadata for a bucket