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

Micronaut + Reactor + JAsync doesn't compile #3

Open
mojo2012 opened this issue Sep 17, 2021 · 14 comments
Open

Micronaut + Reactor + JAsync doesn't compile #3

mojo2012 opened this issue Sep 17, 2021 · 14 comments
Labels
bug Something isn't working

Comments

@mojo2012
Copy link

Hi,

I tried to implement my first demo project with micronaut/reactor. Unfortunately this error pops up during compilation:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project test: Fatal error compiling: java.lang.IllegalAccessError: class io.github.vipcxj.jasync.core.javac.JAsyncContext (in unnamed module @0x42ed89da) cannot access class com.sun.tools.javac.api.JavacTrees (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.api to unnamed module @0x42ed89da -> [Help 1]

This is the sample project: https://github.com/mojo2012/async-test

I hope you can help me fix this :-)

cheers, matthias

@vipcxj
Copy link
Owner

vipcxj commented Sep 18, 2021

I will check it today. I have a quick look at your project. I think it may cause by the new key word var. If it's the cause of the problem, I will fix it in the next release. On the other hand, I found some problem in your project.
here

	@Async
	private JPromise<String> getDataInternal() {
		try {
			Thread.sleep(2000);
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}

		return JAsync.just(Thread.currentThread().getName());
	}

This method is blocked by Thread.sleep. I think it should be

	@Async
	private JPromise<String> getDataInternal() {
            Promises.from(Mono.delay(Duration.ofSeconds(2))).await();
            return JAsync.just(Thread.currentThread().getName());
	}

@Async is optional if no await is used in the method.

@vipcxj
Copy link
Owner

vipcxj commented Sep 18, 2021

@mojo2012 I have try your project, I found your target java release is 15, My highest installed jdk is 11. So I change it to 11, The project is compiled successfully. So perhaps JAsync does not support jdk 15 yet.
Uhm, I download a jdk 15 and try, it compiled.

I found the problem. issues2681
The current workaround is using jdk 15 instead.
Thought some one said add export also work.

<compilerArgs>
    <arg>--add-exports</arg><arg>jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
    <arg>--add-exports</arg><arg>jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
</compilerArgs>

But the reality is more complicated. jasync-core is compiled with java 8 which not support module system. And using compilerArgs in pom will raise a error target 8 not permit --add-exports.
I will try to find a perfect solution from lombok project.

@mojo2012
Copy link
Author

mojo2012 commented Sep 18, 2021

Promises.from(Mono.delay(Duration.ofSeconds(2))).await(); probably needs a shortcut like JAsync.sleep(2).
I know it's a little bit constructed but nevertheless I almost always see it at least once in every codebase 😅.

I think targeting or even using java 8 is not the way to go for any new project.
I'd rather target at least java 11!

@vipcxj
Copy link
Owner

vipcxj commented Sep 18, 2021

@mojo2012 You don't need to target java 8, java 15 also work. This issue is caused by JEP 396 from java 16.
And changing target does not work currently. You must change jdk to jdk 15 or lower. But I will try to find a more perfact solution from lomok, it face the same issue, to

@vipcxj
Copy link
Owner

vipcxj commented Sep 18, 2021

@mojo2012
The version 0.1.2 is released, it support java 17 now. You should update the dependencies according readme. The central repository is scyning, so perhaps you need wait a moment.
The new switch syntax introduced in java 17 is not supported yet, it may be supported in the next release.

@vipcxj vipcxj added the bug Something isn't working label Sep 18, 2021
@mojo2012
Copy link
Author

Should this be compatible with the eclipse compiler?
On the command line with maven the build runs fine now.
But in vscode I get these build errors:

!ENTRY org.eclipse.jdt.ls.core 4 0 2021-09-18 19:58:57.132
!MESSAGE Failed to build workspace.
!STACK 1
org.eclipse.core.internal.resources.ResourceException: Errors occurred during the build.
	at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:533)
	at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:406)
	at org.eclipse.jdt.ls.core.internal.handlers.BuildWorkspaceHandler.buildWorkspace(BuildWorkspaceHandler.java:59)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$27(JDTLanguageServer.java:838)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$53(JDTLanguageServer.java:1017)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
Contains: Errors running builder 'Java Builder' on project 'test'.
java.lang.IllegalArgumentException
	at jdk.compiler/com.sun.tools.javac.api.JavacTrees.instance(JavacTrees.java:199)
	at io.github.vipcxj.jasync.core.javac.JAsyncContext.<init>(JAsyncContext.java:34)
	at io.github.vipcxj.jasync.core.AsyncProcessor.init(AsyncProcessor.java:36)
	at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.discoverNextProcessor(IdeAnnotationProcessorManager.java:97)
	at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:119)
	at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:172)
	at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:138)
	at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:950)
	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:377)
	at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:214)
	at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:309)
	at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:79)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:272)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:192)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:853)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:232)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:281)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:334)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:337)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:389)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:410)
	at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:516)
	at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:406)
	at org.eclipse.jdt.ls.core.internal.handlers.BuildWorkspaceHandler.buildWorkspace(BuildWorkspaceHandler.java:59)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$27(JDTLanguageServer.java:838)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$53(JDTLanguageServer.java:1017)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
!SUBENTRY 1 org.eclipse.core.resources 4 75 2021-09-18 19:58:57.132
!MESSAGE Errors occurred during the build.
!SUBENTRY 2 org.eclipse.jdt.core 4 75 2021-09-18 19:58:57.132
!MESSAGE Errors running builder 'Java Builder' on project 'test'.
!STACK 0
java.lang.IllegalArgumentException
	at jdk.compiler/com.sun.tools.javac.api.JavacTrees.instance(JavacTrees.java:199)
	at io.github.vipcxj.jasync.core.javac.JAsyncContext.<init>(JAsyncContext.java:34)
	at io.github.vipcxj.jasync.core.AsyncProcessor.init(AsyncProcessor.java:36)
	at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.discoverNextProcessor(IdeAnnotationProcessorManager.java:97)
	at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:119)
	at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:172)
	at org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeAnnotationProcessorManager.processAnnotations(IdeAnnotationProcessorManager.java:138)
	at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:950)
	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:377)
	at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:214)
	at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:309)
	at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:79)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:272)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:192)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:853)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:232)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:281)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:334)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:337)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:389)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:410)
	at org.eclipse.core.internal.resources.Workspace.buildInternal(Workspace.java:516)
	at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:406)
	at org.eclipse.jdt.ls.core.internal.handlers.BuildWorkspaceHandler.buildWorkspace(BuildWorkspaceHandler.java:59)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$27(JDTLanguageServer.java:838)
	at org.eclipse.jdt.ls.core.internal.handlers.JDTLanguageServer.lambda$53(JDTLanguageServer.java:1017)
	at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
	at java.base/java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:479)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)

!ENTRY org.eclipse.jdt.ls.core 1 0 2021-09-18 19:59:00.279
!MESSAGE >> workspace/executeCommand vscode.java.resolveBuildFiles

@vipcxj
Copy link
Owner

vipcxj commented Sep 18, 2021

@mojo2012 Yes, eclipse compiler cause it. Many ide do some hack about JDK's ProcessingEnvironment object. I think this may be the reason. I will check it today.
What plugins installed with your vscode?

@mojo2012
Copy link
Author

just the regular java extension from redhat

@vipcxj
Copy link
Owner

vipcxj commented Sep 19, 2021

@mojo2012 I found ecj use its own compiler. JAsync only support javac currently.

@mojo2012
Copy link
Author

so developing with Eclipse and vscode is not supported? I really don't want to use the java compiler, because it lacks a lot of features compared to ejc. Especially build output and diagnostics features.
Overall I'm not a fan of hooking into the compiler and hack stuff into it. It's not very future proof. That's the reason why I always avoided lombok.
I'd rather prefer a post-compiler like ajc do the job. It could be integrated into the maven build cycle and there would be used by eclipse as well.

@vipcxj
Copy link
Owner

vipcxj commented Sep 20, 2021

@mojo2012 An imperfect solution would be using Maven or Gradle to compile the project fist, then debugging using ejc. but in current versions JAsync throws exceptions during initialization, causing debugging to fail. This will be fixed in the next version.
Supporting ejc is a long-term task. But I will try my best to do it.

@mojo2012
Copy link
Author

Have you ever considered to just use the regular ecj through the maven-compiler-plugin and a post processor to process the .class files afterwards. It's actually quite straight forward to do and doesn't possibly break with every java update.
I did that implementing a ClassFileTransformer with bytebuddy and javassist that could be loaded on runtime through a java generic agent (injected dynamically/programmatically) or during compilation.
https://github.com/vsilaev/tascalate-async-await does it that way I think.

Anyway, I think I'm not the only one who would only be interested into this project if it works for all major IDEs without any drawbacks, so supporting ecj/eclipse/vscode/(netbeans?) is a must.
Hope to see that happening :-)

@vipcxj
Copy link
Owner

vipcxj commented Oct 12, 2021

@mojo2012
Sorry for the late reply. The feasibility of using asm is being studied recently. An asm branch is currently opened. I have implemented a Promise that does not depend on Reactor, supports Context and Loop, and will also support Lock in the future. And successfully injected code into the compiler to make it run my asm transformer. However, only javac is currently supported. But the advantage of using asm is that I only need to maintain the code of the injected part of the different compilers, and the most important transform logic only needs to be written once.

@qw623577789
Copy link

Vscode-java is based on eclipse JDT, it use ecj to compile. When you debug the program in normal mode, the classpath set by vscode is ${workspaceFolder}/bin(which compile by ecj). Vscode supports debugging programs in a customized way,so we can create a custom task to debug.

First, create a vscode task in .vscode/tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "gradle build" // or you can use maven build command
        }
    ]
}

Second, create debug task in .vscode/launch.json

{
    "type": "java",
    "name": "to debug",
    "request": "launch",
    "mainClass": "com.example.demo.DemoApplication",
    "classPaths": [
        "${workspaceFolder}/build/classes/java/main", // set the gradle/maven compile output dir
        "${workspaceFolder}/build/libs/java_modules/*" // set dependent jars dir 
    ],
    "preLaunchTask": "build" // to run build task before launching.
}

Now you can debug by choosing task in vscode Run And Debug tab or pressing F5 in main class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants