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

Google Cloud Storage: NoSuchMethodError for method setReturnRawInputStream() #6435

Closed
Brett-Wood opened this issue Oct 3, 2019 · 4 comments
Assignees
Labels
api: storage Issues related to the Cloud Storage API. type: question Request for information or clarification. Not an issue.

Comments

@Brett-Wood
Copy link

Environment details

OS type and version: MacOS Mojave 10.14.6
Java version: 1.8.0_161
google-cloud-java version(s): Maven dependency

		<dependency>
			<groupId>com.google.cloud</groupId>
			<artifactId>google-cloud-storage</artifactId>
			<version>1.79.0</version>
		</dependency>

Code example

  public void readerFromStrings(String bucketName, String blobName) throws IOException {
    // [START readerFromStrings]
    try (ReadChannel reader = storage.reader(bucketName, blobName)) {
      ByteBuffer bytes = ByteBuffer.allocate(64 * 1024);

// Value in condition always returns 0 due to NoSuchMethodError from stack trace
      while (reader.read(bytes) > 0) { 
        bytes.flip();
        // do something with bytes
        bytes.clear();
      }
    }

Stack trace

Exception in thread "pool-1-thread-1" java.lang.NoSuchMethodError: com.google.api.services.storage.Storage$Objects$Get.setReturnRawInputStream(Z)Lcom/google/api/client/googleapis/services/AbstractGoogleClientRequest;
	at com.google.cloud.storage.spi.v1.HttpStorageRpc.read(HttpStorageRpc.java:666)
	at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:127)
	at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:124)
	at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105)
	at com.google.cloud.RetryHelper.run(RetryHelper.java:74)
	at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:51)
	at com.google.cloud.storage.BlobReadChannel.read(BlobReadChannel.java:123)

Any additional information below

I have a working version that uses blob.getContent in order to retrieve the file from storage, but due to some limitations on my end I need to stream the file in chunks. When I refactored my code to use the ReadChannel I started running into this issue. I really appreciate any and all help I can get with this. From my understanding it could be an issue with my google-cloud-java version, but I tried updating to 1.93 and I still ran into this issue. Thank you in advance!

@athakor athakor added api: storage Issues related to the Cloud Storage API. type: question Request for information or clarification. Not an issue. labels Oct 4, 2019
@athakor athakor self-assigned this Oct 4, 2019
@athakor
Copy link
Contributor

athakor commented Oct 4, 2019

@Brett-Wood I'm not able to reproduce this issue below are the code snippets and output.

Code :

public static void main(String[] args) throws IOException {
    String bucket = "bucketName";
    String blob = "test-blob";
    Storage storage = StorageOptions.getDefaultInstance().getService();
    createBlob(storage, bucket, blob);
    readerFromStrings(storage, bucket, blob);
  }

  public static void createBlob(Storage storage, String bucketName, String blobName) {
    BlobId blobId = BlobId.of(bucketName, blobName);
    BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
    Blob blob = storage.create(blobInfo, "a simple blob has been created".getBytes());
    System.out.println("Blob : " + blob.getName() + " created successfully");
  }

  public static void readerFromStrings(Storage storage, String bucketName, String blobName)
      throws IOException {
    // [START readerFromStrings]
    try (ReadChannel reader = storage.reader(bucketName, blobName)) {
      ByteBuffer bytes = ByteBuffer.allocate(64 * 1024);
      // Value in condition always returns 0 due to NoSuchMethodError from stack trace
      while (reader.read(bytes) > 0) {
        System.out.println("Everything works fine without error");
        bytes.flip();
        bytes.clear();
      }
    }
  }

Output :

Blob : test-blob created successfully
Everything works fine without error

@Brett-Wood
Copy link
Author

Brett-Wood commented Oct 4, 2019

Thank you for your help and trying to reproduce the issue. I was able to reproduce it again this morning
Here is my exact code snippet that is causing the issue:

	public static String readBlobContent(Storage storage, String bucketName, String blobName, Connection con, String email, String fileName) throws Exception {
		PreparedStatement update_pstmt = null;
		String document_key = String.valueOf(System.currentTimeMillis());
		try{
			try(ReadChannel reader = storage.reader(bucketName, blobName)) {
				ByteBuffer bytes = ByteBuffer.allocate(64*1024);
				while(reader.read(bytes) > 0) {
					byte buffer[] = new byte[64*1024];
					bytes.flip();
					bytes.get(buffer);
					update_pstmt = con.prepareStatement("UPDATE table SET DOCUMENT=DOCUMENT+? WHERE DOCUMENT_KEY=?");
					update_pstmt.setBytes(1, buffer);
					update_pstmt.setString(2, document_key);
					update_pstmt.executeUpdate();
					bytes.clear();
				}
				reader.close();
			}
			return document_key;
		} catch(Exception e) {
			throw e;
		} finally {
			DBUtil.closeConnections(null, update_pstmt, null, null);
		}
	}

Here is the full stack trace from the replicated issue:

Exception in thread "pool-1-thread-1" java.lang.NoSuchMethodError: com.google.api.services.storage.Storage$Objects$Get.setReturnRawInputStream(Z)Lcom/google/api/client/googleapis/services/AbstractGoogleClientRequest;
	at com.google.cloud.storage.spi.v1.HttpStorageRpc.createReadRequest(HttpStorageRpc.java:658)
	at com.google.cloud.storage.spi.v1.HttpStorageRpc.read(HttpStorageRpc.java:693)
	at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:127)
	at com.google.cloud.storage.BlobReadChannel$1.call(BlobReadChannel.java:124)
	at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105)
	at com.google.cloud.RetryHelper.run(RetryHelper.java:74)
	at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:51)
	at com.google.cloud.storage.BlobReadChannel.read(BlobReadChannel.java:123)
	at com.project.util.GoogleBucketUtil.readBlobContent(GoogleBucketUtil.java:158)
	at com.project.util.executors.GoogleBucketSelectExecutor.run(GoogleBucketSelectExecutor.java:48)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Do you think that there is a chance it could be conflicting maven dependencies in my project? I only have one goolge-cloud-storage dependency listed in my project, but I do have other google API dependencies as well such as google-cloud-bigquery (version 1.53). Thanks again for your help.

@ajaaym
Copy link
Contributor

ajaaym commented Oct 4, 2019

@Brett-Wood can you please post project dependency tree?

@Brett-Wood
Copy link
Author

This can be closed. I realized that I never updated my google-api-client dependency, so I updated that and it resolved my issue. Thank you for your help!

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 Cloud Storage API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants