GLBB commented on issue #9527:
URL: https://github.com/apache/shardingsphere/issues/9527#issuecomment-789031303
hi, I have saw code.
in situation 1, cause by `setterMethod.get().invoke(result,
entry.getValue());`, password type expect string type, I give integer type, my
solution is when occur IllegalArgumentException, exception message contains
yaml properties name.
occur exception code as follow:
```
/**
* Create data source.
*
* @return data source
*/
@SuppressWarnings({"unchecked", "rawtypes"})
@SneakyThrows(ReflectiveOperationException.class)
public DataSource createDataSource() {
DataSource result = (DataSource)
Class.forName(dataSourceClassName).getConstructor().newInstance();
Method[] methods = result.getClass().getMethods();
for (Entry<String, Object> entry : props.entrySet()) {
if (SKIPPED_PROPERTY_NAMES.contains(entry.getKey())) {
continue;
}
Optional<Method> setterMethod = findSetterMethod(methods,
entry.getKey());
if (setterMethod.isPresent()) {
setterMethod.get().invoke(result, entry.getValue());
}
}
Optional<JDBCParameterDecorator> decorator =
findJDBCParameterDecorator(result);
return decorator.isPresent() ? decorator.get().decorate(result) :
result;
}
```
I want modify to:
```
@SuppressWarnings({"unchecked", "rawtypes"})
@SneakyThrows(ReflectiveOperationException.class)
public DataSource createDataSource() {
DataSource result = (DataSource)
Class.forName(dataSourceClassName).getConstructor().newInstance();
Method[] methods = result.getClass().getMethods();
for (Entry<String, Object> entry : props.entrySet()) {
if (SKIPPED_PROPERTY_NAMES.contains(entry.getKey())) {
continue;
}
Optional<Method> setterMethodOpt = findSetterMethod(methods,
entry.getKey());
setterMethodOpt.map(method -> setDataSourceProperty(result,
method, entry.getValue(), entry.getKey()));
}
Optional<JDBCParameterDecorator> decorator =
findJDBCParameterDecorator(result);
return decorator.isPresent() ? decorator.get().decorate(result) :
result;
}
@SneakyThrows(ReflectiveOperationException.class)
private Void setDataSourceProperty(DataSource result, Method method,
Object value, String propertyName) {
try {
method.invoke(result, value);
return null;
} catch (IllegalArgumentException ex) {
throw new ShardingSphereConfigurationException(ex,
String.format("property %s configure error", propertyName));
}
}
public ShardingSphereConfigurationException(final Exception cause, final
String errorMessage) {
super(errorMessage, cause);
}
```
situation 2, I want to set origin cause exception look like more clear.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]