Description
There is a logic error in com.google.adk.models.langchain4j.LangChain4j within the toUserOrToolResultMessage(Content content) method. When parsing text/*, application/json, or +xml mime types, the code correctly creates a TextContent object but adds it directly to the lc4jContents list while leaving the local variable lc4jContent as null.
Immediately after this if/else if block, the code checks if lc4jContent == null and throws an IllegalArgumentException, making it impossible to process these standard text and JSON/XML content types.
Environment
- ADK Version: 1.2.0
- LangChain4J Version: 1.14.0
- Class:
com.google.adk.models.langchain4j.LangChain4j
Steps to Reproduce
Pass any Content object containing an inlineData Part with a text-based mime type (e.g., text/plain, application/json) through the LangChain4J model adapter.
Root Cause Analysis
In toUserOrToolResultMessage, the if/else block handles different mime types:
dev.langchain4j.data.message.Content lc4jContent = null;
// ... [audio/video/image/pdf logic successfully assigns lc4jContent] ...
} else if (mimeType.startsWith("text/") || "application/json".equals(mimeType) || mimeType.endsWith("+json") || mimeType.endsWith("+xml")) {
// ❌ BUG: Adds directly to the list, leaving lc4jContent as null
lc4jContents.add(TextContent.from(new String(bytes, StandardCharsets.UTF_8)));
}
// ❌ Throws exception because lc4jContent is still null for text/json/xml
if (lc4jContent == null) {
throw new IllegalArgumentException("Unknown or unhandled mime type: " + mimeType);
}
// (For other types, it gets added here)
lc4jContents.add(lc4jContent);
Expected Behavior
Text-based content should be parsed into a TextContent object and successfully added to the message list without throwing an IllegalArgumentException.
Suggested Fix
Update the else if branch for text/JSON types to assign the value to lc4jContent instead of adding it directly to the list, maintaining consistency with the other mime type branches:
} else if (mimeType.startsWith("text/") || "application/json".equals(mimeType) || mimeType.endsWith("+json") || mimeType.endsWith("+xml")) {
// ✅ FIX: Assign to the local variable instead
lc4jContent = TextContent.from(new String(bytes, StandardCharsets.UTF_8));
}
if (lc4jContent == null) {
throw new IllegalArgumentException("Unknown or unhandled mime type: " + mimeType);
}
lc4jContents.add(lc4jContent);
Description
There is a logic error in
com.google.adk.models.langchain4j.LangChain4jwithin thetoUserOrToolResultMessage(Content content)method. When parsingtext/*,application/json, or+xmlmime types, the code correctly creates aTextContentobject but adds it directly to thelc4jContentslist while leaving the local variablelc4jContentasnull.Immediately after this
if/else ifblock, the code checks iflc4jContent == nulland throws anIllegalArgumentException, making it impossible to process these standard text and JSON/XML content types.Environment
com.google.adk.models.langchain4j.LangChain4jSteps to Reproduce
Pass any
Contentobject containing aninlineDataPart with a text-based mime type (e.g.,text/plain,application/json) through the LangChain4J model adapter.Root Cause Analysis
In
toUserOrToolResultMessage, theif/elseblock handles different mime types:Expected Behavior
Text-based content should be parsed into a
TextContentobject and successfully added to the message list without throwing anIllegalArgumentException.Suggested Fix
Update the
else ifbranch for text/JSON types to assign the value tolc4jContentinstead of adding it directly to the list, maintaining consistency with the other mime type branches: