Annotation processing warning while running Java code
Version(s) 1.4.0
Describe the bug When running a Java class using scala-cli, it shows this warning.
Annotation processing is enabled because one or more processors were found
on the class path. A future release of javac may disable annotation processing
unless at least one processor is specified by name (-processor), or a search
path is specified (--processor-path, --processor-module-path), or annotation
processing is enabled explicitly (-proc:only, -proc:full).
Use -Xlint:-options to suppress this message.
Use -proc:none to disable annotation processing.
Warning: Error reading API from class file: JavaArgs : java.lang.UnsupportedClassVersionError: Preview features are not enabled for JavaArgs (class file version 65.65535). Try running with '--enable-preview'
To Reproduce
- Create a directory and save this content to
JavaArgs.java
//> using jvm 21
//> using javaOpt -Xmx2g, -DappName=baeldungApp, --enable-preview
//> using javaProp language=english, country=usa
//> using javacOpt --release 21 --enable-preview
public class JavaArgs {
public static void main(String[] args) {
String appName = System.getProperty("appName");
String language = System.getProperty("language");
String country = System.getProperty("country");
String combinedStr = STR."appName = \{ appName } , language = \{ language } and country = \{ country }";
System.out.println(combinedStr);
}
}
- run this code using
scala-cli JavaArgs.jav - This shows the warning
- Now create a scala file in the same dir even with empty content and run (
touch Test.scalaandscala-cli Test.scala). Obviously it fails to run - Run the other file now
scala-cli JavaArgs.java, this time it runs without any warning
Expected behaviour No warning
Metals Log:
2024.07.05 18:53:33 INFO Correctly reloaded workspace
2024.07.05 18:53:35 INFO time: indexed workspace in 2.25s
Jul 05, 2024 6:54:07 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation
WARNING: Unmatched cancel notification for request id 69
2024.07.05 18:54:13 WARN no build tool detected in workspace '/Users/yadukrishnan/scala-cli/java-args'. The most common cause for this problem is that the editor was opened in the wrong working directory, for example if you use sbt then the workspace directory should contain build.sbt.
2024.07.05 18:54:18 INFO compiling java-args_878aa6f544 (1 java source)
2024.07.05 18:54:20 INFO Note: /Users/yadukrishnan/scala-cli/java-args/JavaArgs.java uses preview features of Java SE 21.
2024.07.05 18:54:20 INFO Note: Recompile with -Xlint:preview for details.
2024.07.05 18:54:20 WARN Error reading API from class file: JavaArgs : java.lang.UnsupportedClassVersionError: Preview features are not enabled for JavaArgs (class file version 65.65535). Try running with '--enable-preview'
2024.07.05 18:54:20 INFO time: compiled java-args_878aa6f544 in 1.91s
Jul 05, 2024 6:57:51 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation
WARNING: Unmatched cancel notification for request id 95
interesting... so it seems this warning is printed somewhere in Bloop, maybe?
it goes away when using --server=false:
scala-cli JavaArgs.java --server=false
# Note: ~/IdeaProjects/scala-cli-tests-2/untitled/cli-java-repro/JavaArgs.java uses preview features of Java SE 21.
# Note: Recompile with -Xlint:preview for details.
# appName = baeldungApp , language = english and country = usa
It seems we should explicitly enable annotation processing in some cases, so that the Java compiler is satisfied... Still not sure where we introduce a processor, however.
Likely guess: this may be caused by us using the SemanticDB compiler plugin. it seems we should explicitly enable annotation processing on JDKs 21+, and possibly pass the processor path to the Java compiler. Some more investigation may be required.