<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Hi Eirik, this is required by the JLS 14.10 The assert Statement.</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
> Whether a top level class or interface enables assertions is determined no later than the earliest of (i) the initialization of the top level class or interface, and (ii) the initialization of any class or interface nested in the top level class or interface.
 Whether a top level class or interface enables assertions cannot be changed after it has been determined.</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
The reason why interfaces use a synthetic class to store $assertionDisabled is because interfaces cannot declare non-public static final fields.</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Regards,</div>
<div style="font-family: "Calibri Light", "Helvetica Light", sans-serif; font-size: 12pt; color: rgb(0, 0, 0);" class="elementToProof">
Chen Liang</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> compiler-dev <compiler-dev-retn@openjdk.org> on behalf of Eirik Bjørsnøs <eirbjo@gmail.com><br>
<b>Sent:</b> Wednesday, January 28, 2026 3:35 PM<br>
<b>To:</b> compiler-dev@openjdk.org <compiler-dev@openjdk.org><br>
<b>Subject:</b> Q: Why are $assertionsDisabled nested classes loaded eagerly by interface static initializers?</font>
<div> </div>
</div>
<div>
<div dir="ltr"><br>
<div>Hi,</div>
<div><br>
</div>
<div>Since interfaces cannot have private fields, javac needs to generate a synthetic inner class to hold the $assertionsDisabled field.</div>
<div><br>
</div>
<div>A static initializer is also added to the interface, eagerly initializing the nested class, see the java.util.zip.Checksum for an example:</div>
<div><br>
</div>
<div><font face="monospace"> static {};<br>
    Code:<br>
         0: getstatic     #16                 // Field java/util/zip/Checksum$1.$assertionsDisabled:Z<br>
         3: ifeq          6<br>
         6: return</font></div>
<div><font face="monospace"><br>
</font></div>
<div>What is the purpose of this eager initialization in Lower::assertFlagTest? I would presume a lazy initialization of the nested class on the first run of an assert would be sufficient?</div>
<div><br>
</div>
<div>In fact when I remove this eager initialization, assertions seem to load the nested class just fine with -esa enabled, but avoid loading the nested class with assertions disabled. </div>
<div><br>
</div>
<div>Asking because this would save class loading common scenarios where the default method is always overridden and thus the default method with the assert is never executed.</div>
<div><br>
</div>
<div>Can we load these nested synthetic classes lazily?</div>
<div><br>
</div>
<div>Cheers,</div>
<div>Eirik.</div>
</div>
</div>
</body>
</html>