{"record":{"id":"56053b744ed90bd3","repo":"spring-projects/spring-ai","slug":"java-io-ioexception-56053b","errorCode":null,"errorMessage":"java.io.IOException","messagePattern":"java\\.io\\.IOException","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/text/VertexAiTextEmbeddingModel.java","lineNumber":242,"sourceCode":"\t\tfor (int i = 0; i < request.getInstructions().size(); i++) {\n\n\t\t\tTextInstanceBuilder instanceBuilder = TextInstanceBuilder.of(request.getInstructions().get(i))\n\t\t\t\t.taskType(taskType.name());\n\t\t\tif (StringUtils.hasText(finalOptions.getTitle())) {\n\t\t\t\tinstanceBuilder.title(finalOptions.getTitle());\n\t\t\t}\n\t\t\tpredictRequestBuilder.addInstances(VertexAiEmbeddingUtils.valueOf(instanceBuilder.build()));\n\t\t}\n\t\treturn predictRequestBuilder;\n\t}\n\n\t// for testing\n\tPredictionServiceClient createPredictionServiceClient() {\n\t\ttry {\n\t\t\treturn PredictionServiceClient.create(this.connectionDetails.getPredictionServiceSettings());\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\t// for testing\n\tPredictResponse getPredictResponse(PredictionServiceClient client, PredictRequest.Builder predictRequestBuilder) {\n\t\tPredictResponse embeddingResponse = client.predict(predictRequestBuilder.build());\n\t\treturn embeddingResponse;\n\t}\n\n\tprivate EmbeddingResponseMetadata generateResponseMetadata(String model, Integer totalTokens) {\n\t\tEmbeddingResponseMetadata metadata = new EmbeddingResponseMetadata();\n\t\tmetadata.setModel(model);\n\t\tUsage usage = getDefaultUsage(totalTokens);\n\t\tmetadata.setUsage(usage);\n\t\treturn metadata;\n\t}\n\n\tprivate DefaultUsage getDefaultUsage(Integer totalTokens) {","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/text/VertexAiTextEmbeddingModel.java#L224-L260","documentation":"createPredictionServiceClient wraps the IOException thrown by PredictionServiceClient.create() in an unchecked RuntimeException. The Google gRPC client throws IOException when it cannot construct the service (invalid settings, credential loading failure), and the library converts it so callers do not need to handle checked exceptions.","triggerScenarios":"Instantiating/calling VertexAiTextEmbeddingModel (via call -> createPredictionServiceClient) when PredictionServiceSettings cannot be created: malformed credentials file, missing scopes, bad transport, or underlying IO error reading the service account key.","commonSituations":"GOOGLE_APPLICATION_CREDENTIALS pointing to a missing/corrupt JSON key; wrong spring.ai.vertex.ai.* properties producing invalid settings; environment without network or quota project misconfig.","solutions":["Inspect getCause() for the detailed IOException message","Fix the credentials path/contents referenced by the connection details","Verify VertexAiEmbeddingConnectionDetails settings (projectId, location, API key) are valid","Run `gcloud auth application-default login` for local development"],"exampleFix":"// before\nvar model = new VertexAiTextEmbeddingModel(factory, MyOptions.DEFAULT); // may throw RuntimeException(IOException)\n// after\ntry {\n    var model = new VertexAiTextEmbeddingModel(factory, MyOptions.DEFAULT);\n} catch (RuntimeException e) {\n    if (e.getCause() instanceof IOException io) {\n        throw new IllegalStateException(\"Cannot create Vertex AI client: \" + io.getMessage(), io);\n    }\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"String credPath = System.getenv(\"GOOGLE_APPLICATION_CREDENTIALS\"); if (credPath != null && !new File(credPath).canRead()) throw new IllegalStateException(\"Cannot read credentials file: \" + credPath);","typeGuard":"static boolean canCreateClient(VertexAiEmbeddingConnectionDetails d) { return d != null && StringUtils.hasText(d.getProjectId()) && StringUtils.hasText(d.getEndpoint()); }","tryCatchPattern":"try { PredictionServiceClient c = PredictionServiceClient.create(settings); } catch (IOException e) { throw new IllegalStateException(\"Vertex AI client init failed: \" + e.getMessage(), e); }","preventionTips":["Verify GOOGLE_APPLICATION_CREDENTIALS points to a valid readable JSON key","Test client creation early at application startup (fail fast)","Run gcloud auth application-default login in dev","Validate connection detail properties before constructing the model"],"tags":["java","google-vertex-ai","io","client-initialization"],"backgroundTag":"file-open-failed","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}