After upgrading to the version 2020.3 of Idea i get a NullPointerException for the mapping processor. If anybody has a clue… Thank you!
asked Dec 2, 2020 at 16:44
The solution is to update MapStruct to 1.4.1.Final or later version, see this issue for more details.
You can also add -Djps.track.ap.dependencies=false
at File | Settings (Preferences on macOS) | Build, Execution, Deployment | Compiler | Build process VM options as a workaround.
answered Dec 2, 2020 at 17:55
CrazyCoderCrazyCoder
382k168 gold badges965 silver badges882 bronze badges
7
If you cannot update MapStruct (my case), details here.
You have to find the exact place where put the -Djps.track.ap.dependencies=false
setting (and I had hard time to figure out where).
So, as they say, a picture is worth a thousand words:
Preferences —> Build, Execution, Deployment —> Compiler
answered Apr 26, 2021 at 15:42
freedevfreedev
23.9k7 gold badges107 silver badges118 bronze badges
1
There are several intellij bugs here. If I change the maven version 1.3.0.Final to 1.4.1.Final the intellij don’t want to update the version.
Solution
- Upgrade the maven version to 1.4.1.Final
- Delete manually mapstruct 1.3.1.Final from External Libraries(Project Structure | Libraries)
- mvn clean package
- Click reload all maven projects
It works without -Djps.track.ap.dependencies=false
If you have swagger exclude mapstruct first:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
<exclusions>
<exclusion>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</exclusion>
</exclusions>
answered Dec 11, 2020 at 10:03
SisakSisak
5391 gold badge4 silver badges14 bronze badges
Expanding on freedev’s answer. For windows users the following will be the place to go :
- Click on the settings gear icon on the right.
- Go to settings (ctrl+A+S is a good shortcut to get here).
- Find Compiler under Build,Execution, Deployment in the left menu
- Add
-Djps.track.ap.dependencies=false
in User-local build process VM options
answered Oct 12, 2021 at 17:52
fireball.1fireball.1
1,2972 gold badges13 silver badges41 bronze badges
0
In my case, I made these changes and it works perfectly for me.
Then I just deleted the caches and rebuilt the entire project, maybe it wasn’t necessary but that worked for me.
Suraj Rao
29.3k11 gold badges96 silver badges103 bronze badges
answered Dec 1, 2021 at 16:13
After upgrading to the version 2020.3 of Idea i get a NullPointerException for the mapping processor. If anybody has a clue… Thank you!
asked Dec 2, 2020 at 16:44
The solution is to update MapStruct to 1.4.1.Final or later version, see this issue for more details.
You can also add -Djps.track.ap.dependencies=false
at File | Settings (Preferences on macOS) | Build, Execution, Deployment | Compiler | Build process VM options as a workaround.
answered Dec 2, 2020 at 17:55
CrazyCoderCrazyCoder
382k168 gold badges965 silver badges882 bronze badges
7
If you cannot update MapStruct (my case), details here.
You have to find the exact place where put the -Djps.track.ap.dependencies=false
setting (and I had hard time to figure out where).
So, as they say, a picture is worth a thousand words:
Preferences —> Build, Execution, Deployment —> Compiler
answered Apr 26, 2021 at 15:42
freedevfreedev
23.9k7 gold badges107 silver badges118 bronze badges
1
There are several intellij bugs here. If I change the maven version 1.3.0.Final to 1.4.1.Final the intellij don’t want to update the version.
Solution
- Upgrade the maven version to 1.4.1.Final
- Delete manually mapstruct 1.3.1.Final from External Libraries(Project Structure | Libraries)
- mvn clean package
- Click reload all maven projects
It works without -Djps.track.ap.dependencies=false
If you have swagger exclude mapstruct first:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger2.version}</version>
<exclusions>
<exclusion>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
</exclusion>
</exclusions>
answered Dec 11, 2020 at 10:03
SisakSisak
5391 gold badge4 silver badges14 bronze badges
Expanding on freedev’s answer. For windows users the following will be the place to go :
- Click on the settings gear icon on the right.
- Go to settings (ctrl+A+S is a good shortcut to get here).
- Find Compiler under Build,Execution, Deployment in the left menu
- Add
-Djps.track.ap.dependencies=false
in User-local build process VM options
answered Oct 12, 2021 at 17:52
fireball.1fireball.1
1,2972 gold badges13 silver badges41 bronze badges
0
In my case, I made these changes and it works perfectly for me.
Then I just deleted the caches and rebuilt the entire project, maybe it wasn’t necessary but that worked for me.
Suraj Rao
29.3k11 gold badges96 silver badges103 bronze badges
answered Dec 1, 2021 at 16:13
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:UsersbjIdeaProjectsuntitled2srcmainjavaPersistenceMapper.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
Содержание
- NullPointerException using Mapstruct 1.1.0.Final with Maven #1278
- Comments
- Idea 2020.3 Internal error #63
- Comments
- Footer
- NullPointerException using Mapstruct within eclipse + M2E #655
- Comments
- idea2020.3 mapstruct1.3.1.Final error #2290
- Comments
NullPointerException using Mapstruct 1.1.0.Final with Maven #1278
Hello,
I have faced a problem with including MappingConfiguration and extending another mapper at the same time. My mapper is pretty complicated, it contains multiple nested mappers. I have configuration collected in interface with @MapperConfig annotation. It works nicely with mapper MaperA in one project — everything is generated without any problems. But I want to use the same configutation in MaperB, that extends MaperA. When I try to do this, I receive a NullPointerException , even when MaperB does not override any Mappings. Here is a stacktrace:
Could you help me or recommend some workaround?
Thanks in advance
The text was updated successfully, but these errors were encountered:
This is the exact same problem as in #1180. The lines differ, but the content is the same at those lines.
@Alicja-Majewska I’ll close this issue, you should follow the linked one instead. @sjaakd said that the issue occurs when you have shared config and non existing properties. Did you get something else before this line? If you are able to provide us with a small example that reproduces the error we would be really grateful.
As for figuring it out. The best would be to make add the mapstruct-processor as a provided dependency, set a break point on the line that throws the NPE and catch it. With IntelliJ you can run the compile goal in debug mode. Then you can see what exactly is null there. I would presume it is either sourceParam , sourceParam.getType() or parameter
@sjaakd it looks like the issue didn’t come from 1.2.0, but it was there before 😄 .
Источник
Idea 2020.3 Internal error #63
Error:(37, 18) 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. (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:109) 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:213) at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.process(Unknown Source) at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:142) at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:124) at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:171) at org.eclipse.jdt.internal.compiler.Compiler.processAnnotationsInternal(Compiler.java:957) at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:931) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:450) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:426) at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(Main.java:4721) at org.eclipse.jdt.internal.compiler.tool.EclipseCompilerImpl.call(EclipseCompilerImpl.java:94) at org.eclipse.jdt.internal.compiler.tool.EclipseCompiler$1.call(EclipseCompiler.java:196) at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:231) at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:498) at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:350) at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:274) at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:228) at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1441) at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1100) at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1224) at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:1066) at org.jetbrains.jps.incremental.IncProjectBuilder.access$1200(IncProjectBuilder.java:67) at org.jetbrains.jps.incremental.IncProjectBuilder$BuildParallelizer$1.run(IncProjectBuilder.java:1006) at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:216) at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:27) at com.intellij.util.concurrency.BoundedTaskExecutor$1.execute(BoundedTaskExecutor.java:195) at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:208) at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:184) 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)
The text was updated successfully, but these errors were encountered:
This has nothing to do with the IntelliJ plugin. Have a look at mapstruct/mapstruct#2290 and mapstruct/mapstruct#2215. You should either update to 1.4.1.Final or do what is explained in this comment from the IntelliJ team.
© 2023 GitHub, Inc.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник
NullPointerException using Mapstruct within eclipse + M2E #655
The following error occured in a maven-project within eclipse (build via maven is working):
Internal error in the mapping processor: java.lang.NullPointerException at org.mapstruct.ap.internal.model.source.MethodMatcher.isWithinBounds(MethodMatcher.java:395) at org.mapstruct.ap.internal.model.source.MethodMatcher.matches(MethodMatcher.java:138) at org.mapstruct.ap.internal.model.source.SourceMethod.matches(SourceMethod.java:482) at org.mapstruct.ap.internal.model.source.selector.TypeSelector.getMatchingMethods(TypeSelector.java:44) at org.mapstruct.ap.internal.model.source.selector.MethodSelectors.getMatchingMethods(MethodSelectors.java:61) at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl$ResolvingAttempt.getBestMatch(MappingResolverImpl.java:437) at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl$ResolvingAttempt.resolveViaMethod(MappingResolverImpl.java:263) at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl$ResolvingAttempt.getTargetAssignment(MappingResolverImpl.java:189) at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl$ResolvingAttempt.access$100(MappingResolverImpl.java:147) at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl.getTargetAssignment(MappingResolverImpl.java:115) at org.mapstruct.ap.internal.model.PropertyMapping$PropertyMappingBuilder.build(PropertyMapping.java:180) at org.mapstruct.ap.internal.model.BeanMappingMethod$Builder.applyPropertyNameBasedMapping(BeanMappingMethod.java:426) at org.mapstruct.ap.internal.model.BeanMappingMethod$Builder.build(BeanMappingMethod.java:127) at org.mapstruct.ap.internal.processor.MapperCreationProcessor.getMappingMethods(MapperCreationProcessor.java:349) at org.mapstruct.ap.internal.processor.MapperCreationProcessor.getMapper(MapperCreationProcessor.java:143) at org.mapstruct.ap.internal.processor.MapperCreationProcessor.process(MapperCreationProcessor.java:114) at org.mapstruct.ap.internal.processor.MapperCreationProcessor.process(MapperCreationProcessor.java:73) at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:220) at org.mapstruct.ap.MappingProcessor.processMapperTypeElement(MappingProcessor.java:200) at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:166) at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:139) at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:121) at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:159) at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:134) at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:967) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:489) at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:395) at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.compile(IncrementalImageBuilder.java:331) at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:332) at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:136) at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:267) at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:195) at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:205) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:245) at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:300) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303) at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:359) at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:382) at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144) at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
The text was updated successfully, but these errors were encountered:
@dziegenbalg : can you add a reproducer to this issue?
It’s wasn’t a simple task to extract the mappings we use. But I solved it. Look at the attached maven-project, import it in eclipse (enable annotation processing) and enjoy 🙂
Ooops, how can I attach an archive?
Yeah, those can be tricky to reproduce. All the better that you found a way!
You could just create a git repo here on github and push your sample there.
Ook, repo created. Please checkout sample testmapstruct from https://github.com/dziegenbalg/mapstruct.
Check.. reproducer works. Its this Eclipse compiler again.. The Maven build works, right?
Yeah, maven build works.
Hey @dziegenbalg, running your test case (thanks for that), I actually get no NPE but the same error as in #644 (the dreaded asMemberOf() issue, but we got a solution for that now thanks to @agudian).
Could you double-check whether you really see the NPE with this set-up? Or maybe the test case does not exactly represent your original situation?
see the attached image. I already see this NPE with the actual eclipse 4.5.1.
@gunnarmorling , @dziegenbalg .. I reproduced it as well based on the example of @dziegenbalg . Somehow @agudian and myself concluded already that this was #644 . We somehow (forgot) to report back on this one.
@sjaakd So will this issue be resolved once @agudian’s fix for #644 is in?
@sjaakd So will this issue be resolved once @agudian’s fix for #644 is in?
Unfortunately not. I took a quick look and I think I identified what seems to be the problem. When collecting the methods of a type (including the superclasses), we check if a method is already overridden in a sub-class ( Executables.wasNotYetOverridden ).
In the example project, there are these types:
When collecting the methods in EnumClassMapper , the Eclipse implementation insists that EnumClassMapper#toFeKlasse(..) does not override AbstractMapper#toFeKlasse(..) when using Elements#overrides(..) .
This will then cause some trouble down the road.
I actually don’t think that we can fix that on the side within the next days before the 1.0 final. I’d say we push it to a 1.1 or perhaps a 1.0 bugfix release later on. 🙁
Ok, seems like another bug in the Eclipse APT impl then 🙁
+1 for looking into a fix for 1.0.1. I don’t consider it a blocker for 1.0 as there is the work-around of letting specific mappers not inherit from shared interfaces. I don’t think it’s needed in most cases as there are typically no polymorphic invocations of mappers. Still of course I hope we can make it work in a sub-sequent release.
Hey @agudian, do you think you could give this one another look?
Need to move that out of 1.1 as there unfortunately is no fix we can implement right now.
Источник
idea2020.3 mapstruct1.3.1.Final error #2290
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.(DefaultModelElementProcessorContext.java:50) at org.mapstruct.ap.MappingProcessor.processMapperElements(MappingProcessor.java:218) at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:156) at org.jetbrains.jps.javac.APIWrappers$ProcessorWrapper.process(APIWrappers.java:109) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.jetbrains.jps.javac.APIWrappers$1.invoke(APIWrappers.java:213) at org.springframework.boot.configurationprocessor.ConfigurationMetadataAnnotationProcessor.process(Unknown Source) at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794) at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705) at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91) at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035) at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176) at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170) at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856) at com.sun.tools.javac.main.Main.compile(Main.java:523) at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129) at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138) at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:231) at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:498) at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:350) at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:274) at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:228) at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1441) at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1100) at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1224) 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.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)
The text was updated successfully, but these errors were encountered:
Источник
Я пытаюсь подключить локальное pojo к объектам с автогенерируемым доменом, используя mapstruct. Ожидайте, что для конкретной сложной структуры все остальное похоже на карту, и класс реализации mapper получает поколение. Ниже приведена ошибка, которую я получаю.
Мой класс сопоставления:
@Mappings({
@Mapping(source = "sourcefile", target = "sourceFILE"),
@Mapping(source = "id", target = "ID"),
@Mapping(source = "reg", target = "regID"),
@Mapping(source = "itemDetailsType", target = "ItemDetailsType") //This is the structure that does not map
})
AutoGenDomainType map(LocalPojo localPojo);
@Mappings({
@Mapping(source = "line", target = "LINE"),
@Mapping(source = type", target = "TYPE")
})
ItemDetailsType map(ItemDetailsTypes itemDetailsType);
Ошибка:
Internal error in the mapping processor: java.lang.NullPointerException at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl$ResolvingAttempt.hasCompatibleCopyConstructor(MappingResolverImpl.java:547) at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl$ResolvingAttempt.isPropertyMappable(MappingResolverImpl.java:522) at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl$ResolvingAttempt.getTargetAssignment(MappingResolverImpl.java:202) at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl$ResolvingAttempt.access$100(MappingResolverImpl.java:153) at org.mapstruct.ap.internal.processor.creation.MappingResolverImpl.getTargetAssignment(MappingResolverImpl.java:121) at
.....
.....
[ERROR]
[ERROR] Found 1 error and 16 warnings.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project uwo-services: Compilation failure
Целевой объект ItemDetailsType
имеет другие свойства, которые не должны отображаться. Ошибка говорит о компиляции, но я не нахожу ее. Кроме того, я попытался добавить, попробовал unmappedTargetPolicy = ReportingPolicy.IGNORE
на моем уровне класса mapper, чтобы избежать, если это вызвано неотображаемыми свойствами, но все равно никакого решения.
Довольно часто при разработке на Java программисты сталкиваются с NullPointerException, появляющимся в самых неожиданных местах. В этой статье мы разберёмся, как это исправить и как стараться избегать появления NPE в будущем.
NullPointerException (оно же NPE) это исключение, которое выбрасывается каждый раз, когда вы обращаетесь к методу или полю объекта по ссылке, которая равна null. Разберём простой пример:
Integer n1 = null; System.out.println(n1.toString());
Здесь на первой строке мы объявили переменную типа Integer и присвоили ей значение null (то есть переменная не указывает ни на какой существующий объект).
На второй строке мы обращаемся к методу toString переменной n1. Так как переменная равна null, метод не может выполниться (переменная не указывает ни на какой реальный объект), генерируется исключение NullPointerException:
Exception in thread "main" java.lang.NullPointerException at ru.javalessons.errors.NPEExample.main(NPEExample.java:6)
Как исправить NullPointerException
В нашем простейшем примере мы можем исправить NPE, присвоив переменной n1 какой-либо объект (то есть не null):
Integer n1 = 16; System.out.println(n1.toString());
Теперь не будет исключения при доступе к методу toString и наша программа отработает корректно.
Если ваша программа упала из-за исключение NullPointerException (или вы перехватили его где-либо), вам нужно определить по стектрейсу, какая строка исходного кода стала причиной появления этого исключения. Иногда причина локализуется и исправляется очень быстро, в нетривиальных случаях вам нужно определять, где ранее по коду присваивается значение null.
Иногда вам требуется использовать отладку и пошагово проходить программу, чтобы определить источник NPE.
Как избегать исключения NullPointerException
Существует множество техник и инструментов для того, чтобы избегать появления NullPointerException. Рассмотрим наиболее популярные из них.
Проверяйте на null все объекты, которые создаются не вами
Если объект создаётся не вами, иногда его стоит проверять на null, чтобы избегать ситуаций с NullPinterException. Здесь главное определить для себя рамки, в которых объект считается «корректным» и ещё «некорректным» (то есть невалидированным).
Не верьте входящим данным
Если вы получаете на вход данные из чужого источника (ответ из какого-то внешнего сервиса, чтение из файла, ввод данных пользователем), не верьте этим данным. Этот принцип применяется более широко, чем просто выявление ошибок NPE, но выявлять NPE на этом этапе можно и нужно. Проверяйте объекты на null. В более широком смысле проверяйте данные на корректность, и консистентность.
Возвращайте существующие объекты, а не null
Если вы создаёте метод, который возвращает коллекцию объектов – не возвращайте null, возвращайте пустую коллекцию. Если вы возвращаете один объект – иногда удобно пользоваться классом Optional (появился в Java 8).
Заключение
В этой статье мы рассказали, как исправлять ситуации с NullPointerException и как эффективно предотвращать такие ситуации при разработке программ.