-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: IllegalArgument Exception in String converter #3172
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,17 @@ | |
|
||
package org.opensearch.dataprepper.typeconverter; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Objects; | ||
|
||
import static org.opensearch.dataprepper.logging.DataPrepperMarkers.EVENT; | ||
|
||
public class StringConverter implements TypeConverter<String> { | ||
public String convert(Object source) throws IllegalArgumentException { | ||
private static final Logger LOG = LoggerFactory.getLogger(StringConverter.class); | ||
|
||
public String convert(final Object source) { | ||
if (source instanceof Long) { | ||
return Long.toString(((Number)source).longValue()); | ||
} | ||
|
@@ -25,6 +34,11 @@ public String convert(Object source) throws IllegalArgumentException { | |
if (source instanceof String) { | ||
return (String)source; | ||
} | ||
throw new IllegalArgumentException("Unsupported type conversion"); | ||
LOG.error(EVENT, "Unable to convert {} to String", source); | ||
if (Objects.nonNull(source)) { | ||
return source.toString(); | ||
} else { | ||
return ""; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case of Also, it should not be an empty string. It should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can return |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is really a good behavior. It could result in strange output. Say a list is provided. The user will get a string that looks like
ListString@89879
or something like that.I think this should continue to throw the exception.
We can handle the exception in the
ConvertEntryTypeProcessor
class to make it consistent across all types.Perhaps by dropping the data?