NullPointerException when MappingFactory.Factory is used to create MappingContext
See original GitHub issueThe following error occurred when MapperFacade.map(…) method was invoked with MappingContext object created by MappingContext.Factory().getContext() method:
java.lang.NullPointerException at ma.glasnost.orika.impl.generator.MapperGenerator.build(MapperGenerator.java:104) at ma.glasnost.orika.impl.DefaultMapperFactory.buildMapper(DefaultMapperFactory.java:1333) at ma.glasnost.orika.impl.DefaultMapperFactory.lookupMapper(DefaultMapperFactory.java:718) at ma.glasnost.orika.impl.MapperFacadeImpl.resolveMapper(MapperFacadeImpl.java:572) at ma.glasnost.orika.impl.MapperFacadeImpl.resolveMappingStrategy(MapperFacadeImpl.java:179) at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:675)
The problem is because MappingContext.Factory creates Context with empty globalProperties elements. When there is no CAPTURE_FIELD_CONTEXT property following line in SourceCodeContext.java class constructor causes NullPointerException:
this.shouldCaptureFieldContext = (Boolean) mappingContext.getProperty(Properties.CAPTURE_FIELD_CONTEXT);
The shouldCaptureFieldContext variable is a boolean type and cannot be set as a null.
This issue occurred when orika-core was upgrade from 1.4.5 version to 1.5.0 version. Do You know some workaround for this problem? Can we expect fix for this issue in next release?
Thanks & Regards, Piotr
Issue Analytics
- State:
- Created 7 years ago
- Comments:9
Top GitHub Comments
I’m using version 1.4.6 and when I tried to upgrade to 1.5.0 I got the same error. The problem seem to be that all globals properties are empty but was filled with default values in older version.
I create the context like this:
MappingContext context = new MappingContext.Factory().getContext();
I’m talking about those properties:
Now (in 1.5.0) the globalProperties are empty. Why ?
We have no choice but to rollback for now
The MappingContext.Factory is normally initialized by the DefaultMapperFactory constructor.
I think a clean usage would be:
I think fixing the NullPointerException in SourceCodeContext.java will not fix the Problem. The best way could be, to throw a “nice” Error Message which describes the proper use of the MappingContext.Factory with the DefaultMapperFactory.Builder?
Please let me know what you think?
I also didn’t found Example-Code in the Documentation. How can I contribute to the documentation?