JDK-8322992 : Javac fails with StackOverflowError when compiling deeply nested synchronized blocks
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 20,21,22,23
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2024-01-04
  • Updated: 2025-07-22
  • Resolved: 2024-04-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21 JDK 23
21.0.9Fixed 23 b20Fixed
Related Reports
Causes :  
Relates :  
Relates :  
Description
javac JavacBug.java

The system is out of resources.
Consult the following stack trace for details.
java.lang.StackOverflowError
	at jdk.compiler/com.sun.tools.javac.jvm.Code.emitStackMapFrame(Code.java:1366)
	at jdk.compiler/com.sun.tools.javac.jvm.Code.emitStackMap(Code.java:1261)
	at jdk.compiler/com.sun.tools.javac.jvm.Code.emitop(Code.java:388)
	at jdk.compiler/com.sun.tools.javac.jvm.Code.emitop1w(Code.java:938)
	at jdk.compiler/com.sun.tools.javac.jvm.Items$LocalItem.store(Items.java:409)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genTry(Gen.java:1591)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitSynchronized(Gen.java:1489)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCSynchronized.accept(JCTree.java:1428)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genDef(Gen.java:588)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:623)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStat(Gen.java:609)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.genStats(Gen.java:660)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.doVisitBlock(Gen.java:1102)
	at jdk.compiler/com.sun.tools.javac.jvm.Gen.visitBlock(Gen.java:1095)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCBlock.accept(JCTree.java:1092)

I bisected this and it seems to be a regression in JDK 20 b27. Relevant changes to javac:
https://bugs.openjdk.org/issues/?jql=project%20%3D%20JDK%20AND%20resolution%20%3D%20Fixed%20AND%20fixVersion%20%3D%20%2220%22%20AND%20component%20%3D%20tools%20AND%20%22Resolved%20In%20Build%22%20%3D%20b27%20AND%20Subcomponent%20%3D%20javac%20ORDER%20BY%20resolved%20DESC
Comments
Fix request [21u] I backport this to fix this obvious problem and as prereq of JDK-8332106. Low risk. Limited to javac, good repro case, no bugtail. Clean backport. Test passes and reproduces the issue. SAP nightly testing passed.
21-07-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk21u-dev/pull/1992 Date: 2025-07-19 19:10:32 +0000
19-07-2025

Please note that the new SOEDeeplyNestedBlocksTest is not passing in Linux x86 (I also commented in the PR). https://github.com/vicente-romero-oracle/jdk/actions/runs/8786696145/job/24111450455#step:9:17883
23-04-2024

Changeset: 0b9350e8 Author: Vicente Romero <vromero@openjdk.org> Date: 2024-04-22 16:31:32 +0000 URL: https://git.openjdk.org/jdk/commit/0b9350e8b619bc556f36652cde6f73211be5b85b
22-04-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/18832 Date: 2024-04-18 01:24:01 +0000
18-04-2024

caused by JDK-8291769
16-04-2024