mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#108 Simplify error analysis in case null is passed via model include
This commit is contained in:
parent
0b9ca3548d
commit
44509a158e
@ -56,7 +56,9 @@ public class ModelIncludeDirective implements TemplateDirectiveModel {
|
||||
DefaultModelElementWriterContext context = createContext( params );
|
||||
|
||||
try {
|
||||
modelElement.write( context, env.getOut() );
|
||||
if ( modelElement != null ) {
|
||||
modelElement.write( context, env.getOut() );
|
||||
}
|
||||
}
|
||||
catch ( TemplateException te ) {
|
||||
throw te;
|
||||
@ -83,13 +85,11 @@ public class ModelIncludeDirective implements TemplateDirectiveModel {
|
||||
BeanModel objectModel = (BeanModel) params.get( "object" );
|
||||
|
||||
if ( objectModel == null ) {
|
||||
throw new IllegalArgumentException(
|
||||
"Object passed to this directive via the 'object' parameter must not be null"
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( !( objectModel.getWrappedObject() instanceof Writable ) ) {
|
||||
throw new IllegalArgumentException( "Given object isn't a ModelElement:" + objectModel.getWrappedObject() );
|
||||
throw new IllegalArgumentException( "Given object isn't a Writable:" + objectModel.getWrappedObject() );
|
||||
}
|
||||
|
||||
return (Writable) objectModel.getWrappedObject();
|
||||
|
Loading…
x
Reference in New Issue
Block a user