HHH-7098 - Have JandexHelper handle "undefined" values as null

This commit is contained in:
Steve Ebersole 2012-02-21 11:21:45 -06:00
parent 315b06ebda
commit b6902ad211
2 changed files with 27 additions and 4 deletions

View File

@ -335,7 +335,7 @@ public class JandexHelper {
if ( defaultValue.getClass().isArray() && defaultValue.getClass().getComponentType().isAnnotation() ) {
returnValue = new AnnotationInstance[0];
}
return type.cast( returnValue );
return type.cast( nullIfUndefined( returnValue, type ) );
}
private static <T> T explicitAnnotationParameter(AnnotationValue annotationValue, Class<T> type) {
@ -358,6 +358,30 @@ public class JandexHelper {
returnValue = arr;
}
return type.cast( returnValue );
return type.cast( nullIfUndefined( returnValue, type ) );
}
/**
* Swaps type-specific undefined values with {@code null}.
*
* @param value The value
* @param type The target type
*
* @return {@code null} if value is deemed to UNDEFINED; value itself otherwise.
*/
private static Object nullIfUndefined(Object value, Class type) {
if ( value instanceof Type ) {
value = ( (Type) value ).name().toString();
if ( void.class.getName().equals( value ) ) {
value = null;
}
}
if ( String.class.equals( type ) ) {
if ( "".equals( type.cast( value ) ) ) {
value = null;
}
}
return value;
}
}

View File

@ -33,8 +33,7 @@ class TableSourceImpl implements TableSource {
TableSourceImpl(String schema, String catalog, String tableName) {
this.schema = schema;
this.catalog = catalog;
// for some reason annotations passing in "" sometimes :(
this.tableName = "".equals( tableName ) ? null : tableName;
this.tableName = tableName;
}
@Override