Closed dakotahNorth closed 5 months ago
7ddca0db20
)[!TIP] I can email you next time I complete a pull request if you set up your email here!
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
src/main/java/com/example/helloworld/ManifoldJsonMessageConverter.java
✓ https://github.com/dakotahNorth/HelloWorldSpringCloudStream/commit/25d5d6c779397e7bbb2508a614ccf0c6d10055f3 Edit
Modify src/main/java/com/example/helloworld/ManifoldJsonMessageConverter.java with contents: In the convertFromInternal method, make the following changes:
Wrap the existing JSON conversion logic inside a try block:
try {
String jsonString = new String((byte[]) payload);
Object jsonObj = Json.fromJson(jsonString);
return RuntimeMethods.coerce(jsonObj, targetClass);
}
After the try block, add a catch block to catch any exceptions:
catch (Exception e) {
// Log the exception for debugging purposes
// Return null to allow other converters to be tried
return null;
}
The updated method should look like:
@Override
protected Object convertFromInternal(Message<?> message, @NotNull Class<?> targetClass, Object conversionHint) {
Object payload = message.getPayload();
if (payload instanceof byte[]) {
try {
String jsonString = new String((byte[]) payload);
Object jsonObj = Json.fromJson(jsonString);
return RuntimeMethods.coerce(jsonObj, targetClass);
}
catch (Exception e) {
// Log the exception for debugging purposes
// Return null to allow other converters to be tried
return null;
}
}
return null;
}
I have finished reviewing the code for completeness. I did not find errors for sweep/return_null_if_exception_is_thrown_conve
.
💡 To recreate the pull request edit the issue title or description. Something wrong? Let us know.
This is an automated message generated by Sweep AI.
When an exception is thrown from convertFromInternal in ManifoldJsonMessageConverter other converters are tried and an endless loop happens. If an exception is thrown, capture the exception and return null.
Checklist
- [X] Modify `src/main/java/com/example/helloworld/ManifoldJsonMessageConverter.java` ✓ https://github.com/dakotahNorth/HelloWorldSpringCloudStream/commit/25d5d6c779397e7bbb2508a614ccf0c6d10055f3 [Edit](https://github.com/dakotahNorth/HelloWorldSpringCloudStream/edit/sweep/return_null_if_exception_is_thrown_conve/src/main/java/com/example/helloworld/ManifoldJsonMessageConverter.java)