Skip to content

NPE when running MapStruct from IntelliJ 2020.3EAP #2215

Closed
@bjansen

Description

@bjansen

Edit: To fix the error in IDEA 2020.3+, upgrade to 1.4.1.Final or later.
If you're stuck with an older version, as a workaround you can add -Djps.track.ap.dependencies=false in File | Settings | Build, Execution, Deployment | Compiler | User-local build process VM options (overrides Shared options)


  • Is this an issue (and hence not a question)?

I recently upgraded to IntelliJ 2020.3 EAP and the MapStruct annotation processor throws a NPE when compiling a @Mapper class.

C:\Users\bj\IdeaProjects\untitled2\src\main\java\PersistenceMapper.java:5:17
java: Internal error in the mapping processor: java.lang.NullPointerException  
	at org.mapstruct.ap.internal.processor.DefaultVersionInformation.createManifestUrl(DefaultVersionInformation.java:182)  
	at org.mapstruct.ap.internal.processor.DefaultVersionInformation.openManifest(DefaultVersionInformation.java:153)  
	at org.mapstruct.ap.internal.processor.DefaultVersionInformation.getLibraryName(DefaultVersionInformation.java:129)  
	at org.mapstruct.ap.internal.processor.DefaultVersionInformation.getCompiler(DefaultVersionInformation.java:122)  
	at org.mapstruct.ap.internal.processor.DefaultVersionInformation.fromProcessingEnvironment(DefaultVersionInformation.java:95)  
	at org.mapstruct.ap.internal.processor.DefaultModelElementProcessorContext.<init>(DefaultModelElementProcessorContext.java:54)  
	at org.mapstruct.ap.MappingProcessor.processMapperElements(MappingProcessor.java:264)  
	at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:166)  
	at org.jetbrains.jps.javac.APIWrappers$ProcessorWrapper.process(APIWrappers.java:59)  
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)  
	at org.jetbrains.jps.javac.APIWrappers$1.invoke(APIWrappers.java:162)  
	at com.sun.proxy.$Proxy18.process(Unknown Source)  
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:980)  
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:896)  
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1222)  
	at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1334)  
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1258)  
	at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:936)  
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)  
	at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:147)  
	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.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:219)  
	at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:496)  
	at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:348)  
	at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:272)  
	at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:226)  
	at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1436)  
	at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1100)  
	at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1219)  
	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:1066)  
	at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:832)  
	at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:419)  
	at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:183)  
	at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:132)  
	at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:302)  
	at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:132)  
	at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:219)  
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)  
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)  
	at java.base/java.lang.Thread.run(Thread.java:834)  

When I debug the compilation process, I can see that it's caused by the ProcessingEnvironment instance which is now a Proxy in org.mapstruct.ap.internal.processor.DefaultVersionInformation#getCompiler(javax.annotation.processing.ProcessingEnvironment).

In 2020.2, processingEnv.getClass().getName() returns com.sun.tools.javac.processing.JavacProcessingEnvironment.
In 2020.3, processingEnv.getClass().getName() returns com.sun.proxy.$Proxy19, and later on clazz.getClassLoader().getResource(classFileName) returns null.

Steps to reproduce

  • open the attached project in IDEA 2020.3 EAP
  • compile PersistenceMapper.java

Steps to debug

  • The project should be pre-configured to launch the compilation process with a debugger listening on port 5050
  • Run the debug configuration to attach the IDE to the compilation process
  • Put a breakpoint in org.mapstruct.ap.internal.processor.DefaultVersionInformation#getCompiler(javax.annotation.processing.ProcessingEnvironment)
  • Recompile PersistenceMapper.java using F9

Additional info

IntelliJ IDEA 2020.3 EAP (Ultimate Edition)
Build #IU-203.4203.26, built on September 30, 2020
IntelliJ IDEA EAP User
Expiration date: October 30, 2020
Runtime version: 11.0.8+10-b1098.1 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 12
Registry: debugger.watches.in.variables=false
Non-Bundled Plugins: PlantUML integration, Lombook Plugin, YourKit Java Profiler 2019.8-b137 Integration, org.sonarlint.idea, MavenRunHelper, com.dmarcotte.handlebars

MapStruct version 1.4.0.Final

Activity

added this to the 1.4.1 milestone on Oct 3, 2020
filiphr

filiphr commented on Oct 3, 2020

@filiphr
Member

Thanks a lot for this issue @bjansen. I was not aware about IDEA-250718. What they did there is amazing for us, means that the last missing pain points with IDEA are resolved.

In the meantime I am trying to fix the NPE that it is happening and will try to release 1.4.1 with those changes

added a commit that references this issue on Oct 3, 2020

mapstruct#2215: Avoid NPE in IntelliJ EAP 2020.3

added a commit that references this issue on Oct 3, 2020

#2215: Avoid NPE in IntelliJ EAP 2020.3

bjansen

bjansen commented on Oct 3, 2020

@bjansen
Author

The only downside is that people who are stuck with an older version of MapStruct will have to use a workaround to build their project (-Djps.track.ap.dependencies=false)

filiphr

filiphr commented on Oct 3, 2020

@filiphr
Member

Or they'll have to upgrade to a newer version 😉.

Upgrading MapStruct shouldn't be a big deal. It generates code during compilation, so you can easily compare the generated code before and after.

We will also try to fix any possible regressions asap and release 1.4.1

victordfb

victordfb commented on Dec 2, 2020

@victordfb

I'm using mapstruct-jdk8 but this bug fix isn't avaible in that artifact. Unfortunatelly I will regress to previous version of IntelliJ to keep building my project.
:(

filiphr

filiphr commented on Dec 2, 2020

@filiphr
Member

@victordfb there is no reason for you to regress to a preview version of IntelliJ. Did you read #2215 (comment)?

I would also advise using 1.4.1.Final and use mapstruct instead of mapstruct-jdk8. mapstruct-jdk8 is deprecated and identical to mapstruct since 1.3

43 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @afwlehmann@bjansen@victordfb@hospino11@ducquoc

      Issue actions

        NPE when running MapStruct from IntelliJ 2020.3EAP · Issue #2215 · mapstruct/mapstruct