question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullPointerException when MappingFactory.Factory is used to create MappingContext

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Comments:9

github_iconTop GitHub Comments

5reactions
thermechcommented, Mar 19, 2017

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:

COMPILER_STRATEGY
CAPTURE_FIELD_CONTEXT
PROPERTY_RESOLVER_STRATEGY
FILTERS
CODE_GENERATION_STRATEGY
MAPPER_FACTORY
UNENHANCE_STRATEGY
SHOULD_MAP_NULLS

Now (in 1.5.0) the globalProperties are empty. Why ?

We have no choice but to rollback for now

4reactions
brabenetzcommented, Dec 20, 2016

The MappingContext.Factory is normally initialized by the DefaultMapperFactory constructor.

I think a clean usage would be:

MappingContext.Factory mappingContextFactory = new MappingContext.Factory();
MapperFactory mapperFactory= new DefaultMapperFactory.Builder()
    .mappingContextFactory(mappingContextFactory)
    .build();
MappingContext context = mappingContextFactory.getContext();

try {
    B result = mapperFactory.getMapperFacade().map(source, B.class, context);
} finally {
    mappingContextFactory.release(context);
}

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Null pointer exception occurred after upgrading orika-mapper ...
Null pointer exception occurred after upgrading orika-mapper to latest [1.5.4] while mapping list of object by passing mappingContext.
Read more >
The Grails Framework 5.2.5
The Grails Gradle Publish plugin used the Bintray API to publish artifacts. ... MappingContext and org.grails.datastore.mapping.model.MappingFactory APIs ...
Read more >
Advanced Mapping Configurations - Orika User Guide
The global default behavior can be controlled using the mapNulls(false) method on DefaultMapperFactory.Builder; use this to ensure that a null value in a...
Read more >
[JDK-8073386] Fatal error while running a webapp
A DESCRIPTION OF THE PROBLEM : I have reported this once before and got requested additional information. When trying to mail the additional...
Read more >
The Grails Framework
Use the and org.grails.datastore.mapping.model.MappingContext. APIs instead org.grails.datastore.mapping.model.MappingFactory.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found