简体   繁体   English

当我将 Java 版本升级到 openJDK 11 时,加载模型映射器配置时出现 nullpointerException

[英]When i upgraded java version to openJDK 11, I am getting nullpointerException while loading modelmapper configurations

After upgrading Java version to openJDK 11, modelMapper configurations are not getting loaded, getting NullPointerException.将 Java 版本升级到 openJDK 11 后,modelMapper 配置未加载,出现 NullPointerException。

NullPointerException issue is not resolved even after upgrading modelMapper version to 2.3.2

Error Log:错误日志:

1) Failed to configure mappings 1) 配置映射失败

Stack trace:堆栈跟踪:

at org.modelmapper.internal.Errors.throwConfigurationExceptionIfErrorsExist(Errors.java:241)
    at org.modelmapper.internal.ExplicitMappingBuilder.build(ExplicitMappingBuilder.java:244)
    at org.modelmapper.internal.ExplicitMappingBuilder.build(ExplicitMappingBuilder.java:96)
    at org.modelmapper.internal.TypeMapImpl.addMappings(TypeMapImpl.java:92)
    at org.modelmapper.internal.TypeMapStore.getOrCreate(TypeMapStore.java:124)
    at org.modelmapper.ModelMapper.addMappings(ModelMapper.java:113)
    ...
Caused by: java.lang.NullPointerException
    at org.modelmapper.internal.ExplicitMappingBuilder$ExplicitMappingInterceptor.access$000(ExplicitMappingBuilder.java:304)
    at org.modelmapper.internal.ExplicitMappingBuilder.createAccessorProxies(ExplicitMappingBuilder.java:287)
    at org.modelmapper.internal.ExplicitMappingBuilder.createProxies(ExplicitMappingBuilder.java:277)
    at org.modelmapper.internal.ExplicitMappingBuilder.visitPropertyMap(ExplicitMappingBuilder.java:266)
    at org.modelmapper.PropertyMap.configure(PropertyMap.java:386)
    at jdk.internal.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.modelmapper.internal.ExplicitMappingBuilder.build(ExplicitMappingBuilder.java:227)
    ... 6 more

Internally ByteBuddy is throwing an exception which causes the issue, I will look into it a bit more to see if is perhaps a bug in ModelMapper.在内部,ByteBuddy 正在抛出导致问题的异常,我将进一步研究它,看看是否可能是 ModelMapper 中的错误。

Anyway check out the Java 8 tab at http://modelmapper.org/user-manual/property-mapping/ , your current code seems to be using the older documentation.无论如何,请查看http://modelmapper.org/user-manual/property-mapping/ 上的 Java 8 选项卡,您当前的代码似乎正在使用旧文档。

ModelMapper mm = new ModelMapper();

TypeMap<A, B> typeMap = mm.createTypeMap(A.class, B.class);
typeMap.addMappings(mapper -> {
    mapper.map(A::getDate, B::setTest);
    ... // Other mappings
});

This can convert Date -> Long out of the box without any other configuration.这可以转换Date -> Long开箱即用,无需任何其他配置。 If you wish to configure it further you can always create custom Converters like so:如果您想进一步配置它,您可以随时创建自定义转换器,如下所示:

Converter<Date, Long> dateToLong = new AbstractConverter<Date, Long>() {
    @Override
    protected Long convert(Date source) {
        System.out.println("converting: " + source + " to " + source.getTime());
        return source.getTime();
    }
};

typeMap.addMappings(mapper -> mapper.using(dateToLong).map(A::getDate, B::setTest));

I had the same issue with modelmapper 2.3.0.我在使用 modelmapper 2.3.0 时遇到了同样的问题。 Updated to latest 2.3.9 and issue was resolved更新到最新的 2.3.9 并解决了问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java 为什么我在实例化我的数组时得到 NullPointerException - Java Why am I getting a NullPointerException while instantiating my array 在 Java 中,为什么我在尝试显示 FileNotFoundException 时会收到 NullPointerException? - In Java, why am I getting a NullPointerException when trying to display a FileNotFoundException? 我正在获取java.lang.NullPointerException - I am getting java.lang.NullPointerException 为什么在Java中使用数组获取NullPointerException? - Why am I getting a NullPointerException with arrays in Java? 从 groovy 脚本调用方法时,我在 Jenkisn 上收到 java.lang.NullPointerException - I am getting java.lang.NullPointerException on Jenkisn while calling method from groovy script 我在执行 testng 脚本时收到 java.lang.NullPointerException - i am getting a java.lang.NullPointerException while executing the testng script 当我尝试在Studio中切换活动时,为什么会收到java.lang.NullPointerException错误? - Why am I getting a java.lang.NullPointerException error when I try to switch activities in studio? 当我安装Java 8时,如何得到版本6的Java错误? - How am I getting this Java error for version 6 when I am installing Java 8? 为什么我得到nullPointerException - why am I getting nullPointerException 为什么我没有收到NullPointerException - Why am I NOT getting a NullPointerException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM