GoogleCloudPlatform / java-docs-samples

Java and Kotlin Code samples used on cloud.google.com
https://cloud.google.com/java
Apache License 2.0
1.77k stars 2.83k forks source link

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

Open rogerlzp opened 10 months ago

rogerlzp commented 10 months ago
  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?

minherz commented 10 months ago

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:

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