IntelliJ IDEA 告诉我“错误: java: 编译失败: 内部 java 编译器错误想法”

当我使用 IntelliJ IDEA 编译一个 Java 项目时,它会给我以下输出(和错误) :

Information:Eclipse compiler 4.6.2 was used to compile java sources
Information:Module "sinoWeb" was fully rebuilt due to project configuration/dependencies changes
Information:2017/3/23 11:44 - Compilation completed with 1 error and 0 warnings in 5m 32s 949ms
Error:java: Compilation failed: internal java compiler error

我对此感到非常困惑! 下面是我的设置:

enter image description

enter image description here

122198 次浏览

I changed my compiler to Eclipse and run my project. Afterwards changed back to Javac and problem solved. I don't know exact problem but it can help who is looking for solution.

intellij java compiler

I solved this issue by increasing the default value(700) of Build process heap size on IntelliJ's compiler settings.

enter image description here

Changing the Language Level in the Project Settings (Ctrl + Alt + Shift + S) to Java 8 solved the problem for me

  1. On Intellij IDEA Ctrl + Alt + S to open settings.
  2. Build, Execution, Deployment -> Compiler -> Java Compiler
  3. choose your java version from Project bytecode version
  4. Uncheck Use compiler from module target JDK when possible
  5. click apply and ok.

You have to disabled the Javac Options: Use compiler from module target JDK when possible. enter image description here

In my case, using Java 11, I had:

 public List<String> foo() {
...
return response.readEntity(new GenericType<List<String>>() {});

and Intellij suggested I should use <> instead of GenericType<List<String>>, as such:

 public List<String> foo() {
...
return response.readEntity(new GenericType<>() {});

I did that in four functions and the project stopped compiling with an internal compiler error, reverted and it compiled again. Looks like a bug with type inference.

In my case it was because of lombok library with intellij 2019.2 & java11.

According to this IDEA bug after workaround idea works again:

Disable all building from intelliJ and dedicate the build to Maven.

enter image description here

For me the module's target bytecode version was set to 5. I changed it to 8 and the error is gone:

module's bytecode version setting

In my case, it was response type in restTemplate: enter image description here

ResponseEntity<Map<String, Integer>> response = restTemplate.exchange(
eurl,
HttpMethod.POST,
requestEntity,
new ParameterizedTypeReference<>() { <---- this causes error
}
);

Should be like this:

ParameterizedTypeReference<Map<String, Integer>> responseType = new ParameterizedTypeReference<>() {};


ResponseEntity<Map<String, Integer>> response = restTemplate.exchange(
url,
HttpMethod.POST,
requestEntity,
responseType
);

I had the same problem. I fixed changing my settings. Target bytecode version for equals Project bytecode version.

enter image description here

What worked for me is to update the Open JDK version

In JIdea 2020.1.2 and above,

This is may be the language-level set in Project Structure is not compatible with the target byte-code version.

You have to change the target bytecode version .

  1. Go to Settings [ Ctrl+Alt+S ]
  2. Select Java Compiler
  3. Select module in the table
  4. Change the byte-code version to map what you selected in the previous step for language-level

enter image description here

NOTE : How to check the language-level

  1. Go to Project Structure [ Ctrl+Alt+Shift+S ]
  2. Select Modules sub section
  3. Select each module
  4. Under sources-section, check Language Level

enter image description here

Per-module bytecode version settings

I met the same problem

I solved it by changing the Target bytecode error from 1.5 to 8

I got the same error with Community edition 2020.3 on Windows 10 with an older version of the JDK (openjdk version "11" 2018-09-25).

Updating the JDK to javac 11.0.10 fixed the issue.

Here's the stack trace that showed up with the error when using openjdk version "11" 2018-09-25:

java: compiler message file broken: key=compiler.misc.msg.bug arguments=11, {1}, {2}, {3}, {4}, {5}, {6}, {7}
java: java.lang.AssertionError
java:   at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
java:   at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
java:   at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$2$1.setOverloadKind(DeferredAttr.java:172)
java:   at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.visitReference(ArgumentAttr.java:283)
java:   at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMemberReference.accept(JCTree.java:2190)
java:   at jdk.compiler/com.sun.tools.javac.comp.ArgumentAttr.attribArg(ArgumentAttr.java:197)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:653)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.attribArgs(Attr.java:751)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:1997)
java:   at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1634)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.attribTree(Attr.java:655)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3573)
java:   at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCFieldAccess.accept(JCTree.java:2110)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.visitApply(Attr.java:2006)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.visitReturn(Attr.java:1866)
java:   at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCReturn.accept(JCTree.java:1546)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStat(Attr.java:724)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.attribStats(Attr.java:743)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.visitBlock(Attr.java:1294)
java:   at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1020)
java:   at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:498)
java:   at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculative(DeferredAttr.java:481)
java:   at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr.attribSpeculativeLambda(DeferredAttr.java:456)
java:   at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredAttrNode$StructuralStuckChecker.canLambdaBodyCompleteNormally(DeferredAttr.java:900)
java:   at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredAttrNode$StructuralStuckChecker.visitLambda(DeferredAttr.java:878)
java:   at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCLambda.accept(JCTree.java:1807)
java:   at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredAttrNode$StructuralStuckChecker.complete(DeferredAttr.java:832)
java:   at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:335)
java:   at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredAttrNode.process(DeferredAttr.java:779)
java:   at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredAttrContext.complete(DeferredAttr.java:626)
java:   at jdk.compiler/com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:214)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve.rawInstantiate(Resolve.java:605)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve.selectBest(Resolve.java:1563)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve.findMethodInScope(Resolve.java:1733)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1802)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve.findMethod(Resolve.java:1776)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve$10.doLookup(Resolve.java:2654)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve$BasicLookupHelper.lookup(Resolve.java:3293)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve.lookupMethod(Resolve.java:3543)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2651)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve.resolveQualifiedMethod(Resolve.java:2645)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.selectSym(Attr.java:3721)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3601)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2598)
java:   at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$4.complete(DeferredAttr.java:374)
java:   at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredType.check(DeferredAttr.java:321)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve$MethodResultInfo.check(Resolve.java:1060)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve$4.checkArg(Resolve.java:887)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve$AbstractMethodCheck.argumentsAcceptable(Resolve.java:775)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve$4.argumentsAcceptable(Resolve.java:896)
java:   at jdk.compiler/com.sun.tools.javac.comp.Infer.instantiateMethod(Infer.java:181)
java:   at jdk.compiler/com.sun.tools.javac.comp.Resolve.checkMethod(Resolve.java:644)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethod(Attr.java:4120)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.checkIdInternal(Attr.java:3913)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.checkMethodIdInternal(Attr.java:3814)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.checkId(Attr.java:3803)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.visitSelect(Attr.java:3696)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.visitLambda(Attr.java:2595)
java:   at jdk.compiler/com.sun.tools.javac.comp.DeferredAttr$DeferredAttrNode.process(DeferredAttr.java:811)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.visitIdent(Attr.java:3553)
java:   at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCIdent.accept(JCTree.java:2243)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.attribExpr(Attr.java:702)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.visitExec(Attr.java:1773)
java:   at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCExpressionStatement.accept(JCTree.java:1452)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.visitMethodDef(Attr.java:1098)
java:   at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:866)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:4683)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4574)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4523)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:4503)
java:   at jdk.compiler/com.sun.tools.javac.comp.Attr.attrib(Attr.java:4448)
java:   at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.attribute(JavaCompiler.java:1341)
java:   at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:973)
java:   at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
java:   at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:147)
java:   at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
java:   at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
java:   at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:231)
java:   at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:501)
java:   at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:353)
java:   at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:277)
java:   at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:231)
java:   at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1441)
java:   at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1100)
java:   at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1224)
java:   at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:1066)
java:   at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:832)
java:   at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:419)
java:   at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:183)
java:   at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:132)
java:   at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:302)
java:   at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:132)
java:   at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:219)
java:   at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
java:   at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
java:   at java.base/java.lang.Thread.run(Thread.java:834)
java: Compilation failed: internal java compiler error
java: Errors occurred while compiling module 'project'
javac 11 was used to compile java sources
Finished, saving caches...
Compilation failed: errors: 1; warnings: 100

Updated Java compiler to correct "Target bytecode version" which in my case is 8 :

enter image description here

enter image description here

Setting -> Build -> Compiler -> Java Compiler The Target bytecode version of the module is wrong. I set it to 1.8, then it worked.

one reason may be jdk version donot macth minimal version of your project.

Be aware of JDK-8177068 issue, which leads to internal error like

java.lang.NullPointerException
at jdk.compiler/com.sun.tools.javac.comp.Flow$FlowAnalyzer.visitApply(Flow.java:1233)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1628)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.scan(TreeScanner.java:49)
at jdk.compiler/com.sun.tools.javac.comp.Flow$BaseAnalyzer.scan(Flow.java:393)
at jdk.compiler/com.sun.tools.javac.tree.TreeScanner.visitExec(TreeScanner.java:213)
...

It was fixed in JDK 11.0.12 and JDK 14 b14, so upgrade helped.

In my case Information:java: java.lang.OutOfMemoryError: GC overhead limit exceeded intellij.

increased compiler -> build process heap size.

enter image description here

Ref: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003315120-GC-overhead-limit-exceeded

In my case I had to go to help > show logs in files which opens up the idea.log and build-log folders something like

/home/user/.cache/JetBrains/IntelliJIdea2021.2/log/build-log/ where I set the log level to DEBUG in the log4j.rootLogger=debug, file in build-log.properties

I then ran build again and saw

2021-11-27 19:59:39,808 [ 133595]  DEBUG - s.incremental.java.JavaBuilder - Compiling chunk [module] with options: "-g -deprecation -encoding UTF-8 -source 11 -target 11 -s /home/user/project/target/generated-test-sources/test-annotations", mode=in-process
2021-11-27 19:59:41,082 [ 134869]  DEBUG - s.incremental.java.JavaBuilder - java:ERROR:Compilation failed: internal java compiler error

which lead me to see that this might me related to junit test compilation failing. It turns out I had an older/mismatching of the vintage engine and the jupiter engine which are likely to have different java versions relating in the error above. Changing them to be the same ${version.junit} removed the error.

  <dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>

In short some of your dependency jars may have mismatching java versions.

It May is not be relevant to this case, but:

I got this error when I change the Explicit type argument List of:

new ParameterizedTypeReference<List<SomeDtoObject>>()

to <> :

new ParameterizedTypeReference<>()

in restTemplate call after Intellij gave the warning to use <> instead.

It got fixed when I undo my changes back into the Explicit type argument.

Was facing the same issue with Java 11. Solved by changing language level

File -> Project Structure -> Project

Change "Language Level" to SDK Default

enter image description here

I switched across to the cmd line mvn compile build and it showed a more meaningful error.

Fatal error compiling: error: invalid target release: 17 -> [Help 1]

Checking my JAVA_HOME it was set to 11. Once I adjust my project to use 11 as well I got past this and onto another error (which was solved separately).

Otherwise you can remove .m2 folder. Try to reload project.