immutables / immutables

Annotation processor to create immutable objects and builders. Feels like Guava's immutable collections but for regular value objects. JSON, Jackson, Gson, JAX-RS integrations included
http://immutables.org
Apache License 2.0
3.43k stars 274 forks source link

ClassCastException with Immutables 2.7.4 in Eclipse 4.9.0. #891

Open jezovuk opened 5 years ago

jezovuk commented 5 years ago

Using Immutables 2.7.4 with Eclipse 4.9.0 on JDK 1.8.192.

Exception:

org.immutables.value.internal.$processor$.$Processor threw java.lang.ClassCastException: class org.immutables.value.internal.$processor$.meta.$CachingElements$CachingTypeElement cannot be cast to class org.eclipse.jdt.internal.compiler.apt.model.IElementInfo (org.immutables.value.internal.$processor$.meta.$CachingElements$CachingTypeElement is in unnamed module of loader org.immutables.processor.ProxyProcessor$ProxyClassLoader @72f93012; org.eclipse.jdt.internal.compiler.apt.model.IElementInfo is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @26da9dbb)
    at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeProcessingEnvImpl.getEnclosingIFile(IdeProcessingEnvImpl.java:147)
    at org.eclipse.jdt.internal.apt.pluggable.core.filer.IdeFilerImpl.createSourceFile(IdeFilerImpl.java:179)
    at org.immutables.value.internal.$generator$.$Output$SourceFile.complete($Output.java:313)
    at org.immutables.value.internal.$generator$.$Output$7.invoke($Output.java:177)
    at org.immutables.value.internal.$generator$.$Intrinsics.$($Intrinsics.java:96)
    at org.immutables.value.internal.$processor$.$Generator_Immutables._t0__generate($Generator_Immutables.java:20)
    at org.immutables.value.internal.$processor$.$Generator_Immutables$FragmentDispatch.run($Generator_Immutables.java:19603)
    at org.immutables.value.internal.$generator$.$Templates$Fragment.invoke($Templates.java:248)
    at org.immutables.value.internal.$generator$.$AbstractGenerator.invoke($AbstractGenerator.java:57)
    at org.immutables.value.internal.$processor$.$Processor.process($Processor.java:77)
    at org.immutables.value.internal.$generator$.$AbstractGenerator.process($AbstractGenerator.java:87)
    at org.immutables.processor.ProxyProcessor.process(ProxyProcessor.java:72)
    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:162)
    at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:138)
    at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:940)
    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.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:386)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.compile(IncrementalImageBuilder.java:371)
    at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:318)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.incrementalBuildLoop(IncrementalImageBuilder.java:186)
    at org.eclipse.jdt.internal.core.builder.IncrementalImageBuilder.build(IncrementalImageBuilder.java:143)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildDeltas(JavaBuilder.java:279)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:200)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:798)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:219)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:262)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:315)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:318)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:370)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:391)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:145)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
elucash commented 5 years ago

Thank you for reporting this! It should be fixed in master, verifying before releasing

jezovuk commented 5 years ago

Great!

matt-isaman commented 5 years ago

The 2.7.4 version doesn't seem to work in eclipse 4.10.0 using jdk 11. I am not seeing any errors other than the immutables classes not being generated. Moving back to 2.7.3 fixes the issue. This is perhaps the same issue?

elucash commented 5 years ago

most probably the same, the fix is in master but not released yet

cvgaviao commented 5 years ago

I am not seeing any errors

@matt-isaman, in order to see the errors you need to open a view: "window/ show view / Error Log"

Stephan202 commented 5 years ago

Sorry to bother you about this @elucash, but I wonder when you expect a release with this fix. I'm one of the "dinosaurs" in the office that still didn't switch to IDEA.

(Unfortunately I can't just downgrade to 2.7.3, because then I'd miss out on #884 :). )

elucash commented 5 years ago

@Stephan202 sorry for delays, I expect to release it on Fri/Saturday this week. Hope you can build from the sources (or take the snapshot jar) and shove it into Eclipse project settings / factory path in a meantime

stevenschlansker commented 5 years ago

I updated to 2.7.5 and this seems fixed. Thanks!

wordlessly commented 5 years ago

Just wanted to follow the "Getting Started" part. Downloaded the latest version of Eclipse: Version: 2019-03 M2 (4.11.0 M2)

Does not work.

org.immutables.value.internal.$processor$.$Processor threw java.lang.ClassCastException: org.immutables.value.internal.$processor$.meta.$CachingElements$CachingTypeElement cannot be cast to org.eclipse.jdt.internal.compiler.apt.model.IElementInfo at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeProcessingEnvImpl.getEnclosingIFile(IdeProcessingEnvImpl.java:147) at org.eclipse.jdt.internal.apt.pluggable.core.filer.IdeFilerImpl.createSourceFile(IdeFilerImpl.java:186) at org.immutables.value.internal.$generator$.$Output$SourceFile.complete($Output.java:313) at org.immutables.value.internal.$generator$.$Output$7.invoke($Output.java:177) at org.immutables.value.internal.$generator$.$Intrinsics.$($Intrinsics.java:96) at org.immutables.value.internal.$processor$.$Generator_Immutables._t0__generate($Generator_Immutables.java:20) at org.immutables.value.internal.$processor$.$Generator_Immutables$FragmentDispatch.run($Generator_Immutables.java:19603) at org.immutables.value.internal.$generator$.$Templates$Fragment.invoke($Templates.java:248) at org.immutables.value.internal.$generator$.$AbstractGenerator.invoke($AbstractGenerator.java:57) at org.immutables.value.internal.$processor$.$Processor.process($Processor.java:77) at org.immutables.value.internal.$generator$.$AbstractGenerator.process($AbstractGenerator.java:87) at org.immutables.processor.ProxyProcessor.process(ProxyProcessor.java:72) 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.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:138) at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:940) 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.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:386) at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:214) at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:318) at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:79) at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:264) at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:182) at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:833) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:220) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:263) at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:316) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:319) at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:371) at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:392) at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:154) at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:244) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

elucash commented 5 years ago

does update to 2.7.5 fixes this?, thank you

wordlessly commented 5 years ago

Well, it was quite strange. I used 2.7.5 and I still got errors although I restarted Eclipse and cleaned and rebuild the project. Then I closed the project and reopened it late to have a look again at the classes while reading the guide and after opening the project somehow everything (class file generation) worked and consequently there were no errors. Strange.

elucash commented 5 years ago

I can be result of m2e updating .factorypath not exactly when project dependency changed. Even if jar configured manually in UI (on project settings, Java Compiler -> Annotation Processing), the change usually requires open/close project or restarting eclipse

wordlessly commented 5 years ago

I did restart several times. Both "Restart" from the "File" menu and shutting Eclipse down and starting it anew.

FYI: I used the manual configuration (although using Maven) and didn't install m2e-apt connector.

Note: the screenshots in the IDE setup guide are not up-to-date: http://immutables.github.io/apt.html For example screenshots show that you should add generate-tool-0.13.jar. I added value-2.7.5.jar instead. Also the textual description of this guide could be clearer. Subtle changes would be enough. For example point out that you have two options with Eclipse:

EITHER

  1. install m2e-apt

OR

  1. manually adding the value-2.7.5.jar which contains the annotation processor Eclipse will run every time you change your source code.
elucash commented 5 years ago

I dunno, m2e-apt only relevant for someone using maven. If not maven, then the manual option is a way to go (or generate .factorypath using some tool related to the build system). The screenshot is dated and better to be updated, of course, but the approach itself is still sound. Also, what is not mentioned in the guide, many people may prefer to just build tool to do processing and just add source directories with generated files to .classpath)