[英]UnsupportedOperationException when compiling a Maven project in IntelliJ
I have a Java library that I'm building with Maven and from the command line I can successfully run mvn test
but when I try to build it or run the tests from IntelliJ, it fails with this error:我有一个 Java 库,我正在使用 Maven 构建它,并且从命令行我可以成功运行
mvn test
但是当我尝试构建它或从 IntelliJ 运行测试时,它会失败并出现以下错误:
Information:java: An exception has occurred in the compiler (12.0.2). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
Information:java: java.lang.UnsupportedOperationException
Information:java: at java.compiler@12.0.2/javax.tools.JavaFileManager.getServiceLoader(JavaFileManager.java:527)
Information:java: at jdk.compiler/com.sun.tools.javac.main.DelegatingJavaFileManager.getServiceLoader(DelegatingJavaFileManager.java:158)
Information:java: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Information:java: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Information:java: at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Information:java: at java.base/java.lang.reflect.Method.invoke(Method.java:567)
Information:java: at org.jetbrains.jps.javac.JavacMain$2.invoke(JavacMain.java:290)
Information:java: at com.sun.proxy.$Proxy24.getServiceLoader(Unknown Source)
Information:java: at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.initProcessorLoader(JavacProcessingEnvironment.java:266)
Information:java: at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.<init>(JavacProcessingEnvironment.java:237)
Information:java: at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.instance(JavacProcessingEnvironment.java:193)
Information:java: at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.initProcessAnnotations(JavaCompiler.java:1136)
Information:java: at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:922)
Information:java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
Information:java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:147)
Information:java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
Information:java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
Information:java: at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:195)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:460)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:330)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:255)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:213)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1324)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1004)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1071)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:965)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:794)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:376)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:178)
Information:java: at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:139)
Information:java: at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:288)
Information:java: at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:121)
Information:java: at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:228)
Information:java: at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
Information:java: at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
Information:java: at java.base/java.lang.Thread.run(Thread.java:835)
Information:java: Errors occurred while compiling module 'projectcommon'
Information:javac 12.0.2 was used to compile java sources
Information:2019-09-28 14:44 - Build completed with 1 error and 0 warnings in 1 s 301 ms
Error:java: Compilation failed: internal java compiler error
Any ideas what's going on?有什么想法吗?
I've tried refreshing IntelliJ from the Maven project (and it's configured to auto-import).我尝试从 Maven 项目中刷新 IntelliJ(并且它被配置为自动导入)。
Both IntelliJ and the command line are using Oracle's JDK 12: IntelliJ 和命令行都使用 Oracle 的 JDK 12:
> java --version
java 12.0.2 2019-07-16
Java(TM) SE Runtime Environment (build 12.0.2+10)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.2+10, mixed mode, sharing)
The successful command line run looks like this:成功的命令行运行如下所示:
> mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] --------------------< com.example:projectcommon >--------------------
[INFO] Building projectcommon 1.0.0-beta.12
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The artifact org.hibernate:hibernate-validator:jar:6.0.17.Final has been relocated to org.hibernate.validator:hibernate-validator:jar:6.0.17.Final
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ projectcommon ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\pupeno\Documents\project\code\projectcommon\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ projectcommon ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 38 source files to C:\Users\pupeno\Documents\project\code\projectcommon\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ projectcommon ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\pupeno\Documents\project\code\projectcommon\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ projectcommon ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 16 source files to C:\Users\pupeno\Documents\project\code\projectcommon\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ projectcommon ---
[INFO] Surefire report directory: C:\Users\pupeno\Documents\project\code\projectcommon\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.example.projectcommon.crypto.AsymEncryptedDataTest
Tests run: 19, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.391 sec
Running com.example.projectcommon.crypto.EncryptedKeyPairTest
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.787 sec
Running com.example.projectcommon.crypto.HashedPasswordSpecTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 sec
Running com.example.projectcommon.crypto.HashedPasswordTest
Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.677 sec
Running com.example.projectcommon.crypto.KeyPairTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.14 sec
Running com.example.projectcommon.crypto.PasswordKeySpecTest
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running com.example.projectcommon.crypto.PasswordKeyTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.23 sec
Running com.example.projectcommon.crypto.RandomKeyTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.009 sec
Running com.example.projectcommon.crypto.SymEncryptedDataTest
Tests run: 32, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.102 sec
Running com.example.projectcommon.crypto.VerifierPayloadTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec
Running com.example.projectcommon.dto.ErrorDetailTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec
Running com.example.projectcommon.dto.ErrorTest
Sep 28, 2019 2:38:03 PM org.hibernate.validator.internal.util.Version <clinit>
INFO: HV000001: Hibernate Validator 6.0.17.Final
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.534 sec
Running com.example.projectcommon.models.AccountDtoTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.004 sec
Running com.example.projectcommon.models.RegistrationDtoTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.139 sec
Running com.example.projectcommon.models.UserDtoTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.06 sec
Results :
Tests run: 94, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.211 s
[INFO] Finished at: 2019-09-28T14:38:04+01:00
[INFO] ------------------------------------------------------------------------
You are affected by JDK-8228646 and JDK-8223942 which are fixed in Java 13. I don't see it backported to Java 12 so I guess you should update to newer version.您受到JDK-8228646和JDK-8223942的影响,它们已在 Java 13 中修复。我没有看到它向后移植到 Java 12,所以我想您应该更新到更新版本。
The root cause is explained in the JDK-8223942 bug description:根本原因在 JDK-8223942 错误描述中进行了解释:
In the module jdk.compiler the in class
com.sun.tools.javac.api.ClientCodeWrapper
the following calls are not forwarded and lead to calls to interface default which always throwsUnsupportedOperationException
在模块 jdk.compiler 中的 class
com.sun.tools.javac.api.ClientCodeWrapper
中的UnsupportedOperationException
ClientCodeWrapper.WrappedJavaFileManager
does not wrap method:default <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException
ClientCodeWrapper.WrappedJavaFileManager
不包装方法:default <S> ServiceLoader<S> getServiceLoader(Location location, Class<S> service) throws IOException
ClientCodeWrapper.WrappedStandardJavaFileManager
does not wrap method:void setLocationForModule(Location location, String moduleName, Collection<? extends Path> paths) throws IOException
ClientCodeWrapper.WrappedStandardJavaFileManager
不包装方法:void setLocationForModule(Location location, String moduleName, Collection<? extends Path> paths) throws IOException
This is true for all versions of JDK, past and present.
这适用于过去和现在的所有 JDK 版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.