JDK-8331229 : exceptions in static initializer for main class not printed
  • Type: Bug
  • Component: tools
  • Sub-Component: launcher
  • Affected Version: 22
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2024-04-28
  • Updated: 2024-04-29
  • Resolved: 2024-04-29
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
Starting with Java 22, exceptions in static initializers for the main class are no longer printed, and instead the program will fail silently.

REGRESSION : Last worked in version 21.0.3

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Expect an InternalError exception message to be printed.
ACTUAL -
Nothing is printed.

---------- BEGIN SOURCE ----------
public class StaticInitializerExceptionBug {
   static {
      if (true)
         throw new InternalError();
   }

   public static void main(String[] args) {
   }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
There is a PR in preview for JDK 23 to resolve this.
28-04-2024