Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map record from another maven module throw an NPE #2583

Closed
YannPerthuis opened this issue Sep 15, 2021 · 2 comments
Closed

Map record from another maven module throw an NPE #2583

YannPerthuis opened this issue Sep 15, 2021 · 2 comments

Comments

@YannPerthuis
Copy link

  • Context:

I have a domain maven module that holds all my business logic (entities are defined by records) and another maven module for all stuff about infrastructure where I use mapstruct to map record to DTO classes.

  • Problem:

When I clean compile mapstruct processor throw an NPE (cf. the full stacktrace). After some investigations I found the problem location. It's due to RECORD_COMPONENT_ACCESSOR_METHOD.invoke statement above that returns a null value. This method is supposed to return the related accessor of the given record field.

After some tests, mappers compilation succeed (no problem to retrieve accessor for record field) when records belong to the same maven module but, when they belong to another installed maven module in my local repo it's failed as I described.

  • Environment:

OS: macOs v11.2.3

Java: openjdk version "16.0.1" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-16.0.1+9 (build 16.0.1+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-16.0.1+9 (build 16.0.1+9, mixed mode, sharing)

Mapstruct: tested for v1.5.0.Beta1 & v1.4.2.Final

  • Full stacktrace:
java.lang.NullPointerException: Cannot invoke "com.sun.tools.javac.code.Symbol.getEnclosingElement()" because "sym" is null
	at jdk.compiler/com.sun.tools.javac.model.JavacTypes.asMemberOf(JavacTypes.java:298)
	at org.mapstruct.ap.internal.util.AbstractTypeUtilsDecorator.asMemberOf(AbstractTypeUtilsDecorator.java:129)
	at org.mapstruct.ap.internal.util.Filters.getWithinContext(Filters.java:147)
	at org.mapstruct.ap.internal.util.Filters.getReturnType(Filters.java:118)
	at org.mapstruct.ap.internal.util.Filters.recordAccessorsIn(Filters.java:104)
	at org.mapstruct.ap.internal.model.common.Type.getPropertyReadAccessors(Type.java:593)
	at org.mapstruct.ap.internal.model.BeanMappingMethod$Builder.build(BeanMappingMethod.java:246)
	at org.mapstruct.ap.internal.processor.MapperCreationProcessor.getMappingMethods(MapperCreationProcessor.java:416)
	at org.mapstruct.ap.internal.processor.MapperCreationProcessor.getMapper(MapperCreationProcessor.java:179)
	at org.mapstruct.ap.internal.processor.MapperCreationProcessor.process(MapperCreationProcessor.java:133)
	at org.mapstruct.ap.internal.processor.MapperCreationProcessor.process(MapperCreationProcessor.java:81)
	at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:338)
	at org.mapstruct.ap.MappingProcessor.processMapperTypeElement(MappingProcessor.java:318)
	at org.mapstruct.ap.MappingProcessor.processMapperElements(MappingProcessor.java:267)
	at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:166)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:1025)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:940)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1269)
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1384)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1261)
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:935)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.invocationHelper(JavacTaskImpl.java:152)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
	at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess(JavaxToolsCompiler.java:126)
	at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile(JavacCompiler.java:174)
	at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1129)
	at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:188)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
	at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
@filiphr
Copy link
Member

filiphr commented Sep 15, 2021

Please have a look at #2375 and #2374. This was caused due to a bug in Java 15 and 16. This bug has been fixed in Java 17. Please use Java 17 if you want to use records cross modules.

@YannPerthuis
Copy link
Author

Thank you @filiphr, it works fine with the java upgrade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants