HHH-10419 Factor converter instantiation exception error logic

This commit is contained in:
Emmanuel Bernard 2016-01-06 14:55:43 +01:00
parent e65a883761
commit bb7cb7636b
2 changed files with 10 additions and 12 deletions

View File

@ -81,10 +81,7 @@ public abstract class AbstractPropertyHolder implements PropertyHolder {
return makeAttributeConverterDescriptor( info );
}
catch (Exception e) {
throw new IllegalStateException(
String.format( "Unable to instantiate AttributeConverter [%s", info.getConverterClass().getName() ),
e
);
throw buildExceptionFromInstantiationError( info, e );
}
}
}
@ -96,6 +93,13 @@ public abstract class AbstractPropertyHolder implements PropertyHolder {
.findAutoApplyConverterForAttribute( property, context );
}
protected IllegalStateException buildExceptionFromInstantiationError(AttributeConversionInfo info, Exception e) {
return new IllegalStateException(
String.format( "Unable to instantiate AttributeConverter [%s]", info.getConverterClass().getName() ),
e
);
}
protected AttributeConverterDescriptor makeAttributeConverterDescriptor(AttributeConversionInfo conversion) {
try {
AttributeConverterDefinition definition = new AttributeConverterDefinition( conversion.getConverterClass().newInstance(), false );

View File

@ -356,10 +356,7 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder {
return makeAttributeConverterDescriptor( info );
}
catch (Exception e) {
throw new IllegalStateException(
String.format( "Unable to instantiate AttributeConverter [%s", info.getConverterClass().getName() ),
e
);
throw buildExceptionFromInstantiationError( info, e );
}
}
}
@ -416,10 +413,7 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder {
return makeAttributeConverterDescriptor( info );
}
catch (Exception e) {
throw new IllegalStateException(
String.format( "Unable to instantiate AttributeConverter [%s", info.getConverterClass().getName() ),
e
);
throw buildExceptionFromInstantiationError( info, e );
}
}
}