Visitar URL original
java.lang.IllegalAccessError: class com.google.iam.v1.TestIamPermissionsRequest tried to access method · Issue #8970 · GoogleCloudPlatform/java-docs-samples · GitHub
Skip to content

java.lang.IllegalAccessError: class com.google.iam.v1.TestIamPermissionsRequest tried to access method  #8970

Description

@rogerlzp
  1. Jar files as following:

    com.google.cloud
    google-cloud-vertexai
    0.1.0

     <dependency>
         <artifactId>libraries-bom</artifactId>
         <groupId>com.google.cloud</groupId>
         <scope>import</scope>
         <type>pom</type>
         <version>26.29.0</version>
     </dependency>
    

Check the dependency:
com.google.cloud:google-cloud-vertexai:0.1.0:
com.google.api.grpc:proto-google-iam-v1:1.24.0

  1. Code segment:
    @RestController
    @RequestMapping("/api/gemini")
    @slf4j
    public class GeminiChatController {

    @value("${google.credentials}")
    private Resource gcpKeyFile;

    @GetMapping("/chat")
    public void test() {
    String projectId = "gptdemo-408313";
    String location = "us-west2";
    String modelName = "gemini-pro-vision";
    try {
    String output = this.simpleQuestion(projectId, location, modelName);
    log.info("output: {}", output);
    System.out.println(output);
    }catch (Exception e) {
    System.out.println(e);}
    }

    public String simpleQuestion(String projectId, String location, String modelName)
    throws Exception {
    // Initialize client that will be used to send requests.
    // This client only needs to be created once, and can be reused for multiple requests.
    GoogleCredentials credentials = GoogleCredentials.fromStream(gcpKeyFile.getInputStream());

     try (VertexAI vertexAI = new VertexAI(projectId, location, credentials)) {
         String output;
         GenerativeModel model = new GenerativeModel(modelName, vertexAI);
    
         GenerateContentResponse response = model.generateContent("Why is the sky blue?");
         output = ResponseHandler.getText(response);
         return output;
     } catch (Exception e) {
         throw new Exception("Failed to make request", e);
     }
    

    }
    }

  2. It failed with the error:
    java.lang.IllegalAccessError: class com.google.iam.v1.TestIamPermissionsRequest tried to access method 'com.google.protobuf.LazyStringArrayList com.google.protobuf.LazyStringArrayList.emptyList()' (com.google.iam.v1.TestIamPermissionsRequest and com.google.protobuf.LazyStringArrayList are in unnamed module of loader 'app')
    at com.google.iam.v1.TestIamPermissionsRequest.(TestIamPermissionsRequest.java:127) ~[proto-google-iam-v1-1.24.0.jar:1.24.0]
    at com.google.iam.v1.TestIamPermissionsRequest.(TestIamPermissionsRequest.java:918) ~[proto-google-iam-v1-1.24.0.jar:1.24.0]
    at com.google.cloud.vertexai.api.stub.GrpcPredictionServiceStub.(GrpcPredictionServiceStub.java:218) ~[google-cloud-vertexai-0.1.0.jar:0.1.0]
    at com.google.cloud.vertexai.api.stub.PredictionServiceStubSettings.createStub(PredictionServiceStubSettings.java:292) ~[google-cloud-vertexai-0.1.0.jar:0.1.0]
    at com.google.cloud.vertexai.api.PredictionServiceClient.(PredictionServiceClient.java:178) ~[google-cloud-vertexai-0.1.0.jar:0.1.0]
    at com.google.cloud.vertexai.api.PredictionServiceClient.create(PredictionServiceClient.java:160) ~[google-cloud-vertexai-0.1.0.jar:0.1.0]
    at com.google.cloud.vertexai.VertexAI.getPredictionServiceClient(VertexAI.java:151) ~[google-cloud-vertexai-0.1.0.jar:0.1.0]
    at com.google.cloud.vertexai.generativeai.preview.GenerativeModel.generateContentStream(GenerativeModel.java:698) ~[google-cloud-vertexai-0.1.0.jar:0.1.0]
    at com.google.cloud.vertexai.generativeai.preview.GenerativeModel.generateContent(GenerativeModel.java:396) ~[google-cloud-vertexai-0.1.0.jar:0.1.0]
    at com.google.cloud.vertexai.generativeai.preview.GenerativeModel.generateContent(GenerativeModel.java:320) ~[google-cloud-vertexai-0.1.0.jar:0.1.0]
    at com.google.cloud.vertexai.generativeai.preview.GenerativeModel.generateContent(GenerativeModel.java:269) ~[google-cloud-vertexai-0.1.0.jar:0.1.0]
    at com.md.gpt.controller.GeminiChatController.simpleQuestion(GeminiChatController.java:46) ~[classes/:na]
    at com.md.gpt.controller.GeminiChatController.test(GeminiChatController.java:29) ~[classes/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.31.jar:5.3.31]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.31.jar:5.3.31]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.31.jar:5.3.31]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.31.jar:5.3.31]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.31.jar:5.3.31]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.31.jar:5.3.31]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1072) ~[spring-webmvc-5.3.31.jar:5.3.31]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:965) ~[spring-webmvc-5.3.31.jar:5.3.31]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.31.jar:5.3.31]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.3.31.jar:5.3.31]

Could you please have a look, thanks?

Activity

  1. added
    priority: p3Desirable enhancement or fix. May not be included in next release.
    triage meI really want to be triaged.
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    on Jan 7, 2024
  2. minherz commented on Jan 17, 2024

    @minherz
    Contributor

    Hello @rogerlzp, thank you for reaching out. I apologies for the delayed response. We will need some additional information from you in order to review your report. Can you please provide the following information:

    • What is the path to the code sample that you have a problem with?
    • Did you modify any file of the code sample in your steps to reproduce the problem?
    • Given the reported exception is com.google.iam.v1.TestIamPermissionsRequest what are permissions of the identity you used to run the code sample?

    I am temporary assigning this issue to you to reflect the status. Please, assign it to @minherz or @Sita04 once you provide this information.

    Thank you

  3. assigned and unassigned on Jan 17, 2024
  4. added
    type: questionRequest for information or clarification. Not an issue.
    and removed
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    triage meI really want to be triaged.
    on Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority: p3Desirable enhancement or fix. May not be included in next release.samplesIssues that are directly related to samples.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions