0

I'm storing objects in the Google Cloud in the following format

bucketname/UUID/object

For instance, I have an object in Google cloud, stored as

roshanbucket/1fa0e7b4-b551-4e5c-a491-8d86f06a1eef/test.txt

This is the method that I'm using to return the object name

public String getFileName(String bucketName, String uuid) {
    final String[] fileName = {null};
    Page<Blob> blobs = storage.list(bucketName, BlobListOption.prefix(uuid));
    blobs.iterateAll().forEach(
        blob -> fileName[0] = blob.getName()//.substring(blob.getName().lastIndexOf('/') + 1)
    );
    return fileName[0];
  }

This is the test method

@Test
  public void testGetFileName(){
    String fileName = googleCloudStorage.getFileName("roshanbucket", "1fa0e7b4-b551-4e5c-a491-8d86f06a1eef");
    System.out.println(fileName);
  }

When I run the test, it gives me the following error

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V

at com.google.cloud.storage.StorageImpl.optionMap(StorageImpl.java:1279)
at com.google.cloud.storage.StorageImpl.optionMap(StorageImpl.java:1268)
at com.google.cloud.storage.StorageImpl.optionMap(StorageImpl.java:1301)
at com.google.cloud.storage.StorageImpl.list(StorageImpl.java:306)
at services.fileserver.GoogleCloudStorage.getFileName(GoogleCloudStorage.java:76)
at services.fileserver.GoogleCloudStorageTest.testDownloadLink(GoogleCloudStorageTest.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

How do I fix this issue?

Roshan Upreti
  • 1,782
  • 3
  • 21
  • 34
  • 1
    Maybe you missing a dependency. [See also here](https://stackoverflow.com/questions/42206440/java-lang-nosuchmethoderror-com-google-common-base-preconditions-checkargument) – Vall0n Apr 01 '19 at 08:52

3 Answers3

1

It seems that your jar's version google provided is wrong. Checkout the version of jar file that contains Precondition.class

Sean Lee
  • 46
  • 3
1

Adding this dependency fixed the issue

<dependency>
 <groupId>com.google.guava</groupId>
 <artifactId>guava</artifactId>
 <version>27.1-jre</version>
</dependency>
Roshan Upreti
  • 1,782
  • 3
  • 21
  • 34
0

I recommend following the steps in the documentation to get the right client library for Java. The pom.xml dependency currently specified there is as follows

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-storage</artifactId>
  <version>1.66.0</version>
</dependency>
Christopher P
  • 1,108
  • 7
  • 8