Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8336965

Initializing a static Set using Set.of() causes JVM to exit before entering main

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      CPU: AMD Ryzen 9 5950X 16-Core Processor; OS: Ubuntu Linux 24.04 LTS; Java version:
      openjdk version "22.0.2" 2024-07-16
      OpenJDK Runtime Environment (build 22.0.2+9-70)
      OpenJDK 64-Bit Server VM (build 22.0.2+9-70, mixed mode, sharing)


      A DESCRIPTION OF THE PROBLEM :
      Initializing a static Set<BitSet> using Set.of() with 10 arguments causes JVM to exit with non-zero status before entering main(). There are no error messages of any sort. See code below.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compiling Bug.java with: "javac Bug.java" and running with "java Bug" causes execution to terminate immediately with no errors or output of any kind. The exit status using "echo $?" shows 1. Using fewer than 10 arguments shows the expected output e.g. "set.size = 9"

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected output "set.size = 10" and zero (successful) exit status
      ACTUAL -
      No output or error message of any kind.

      ---------- BEGIN SOURCE ----------
      // static initialization of a set is causing the JVM to exit before entering main()

      import java.util.BitSet;
      import java.util.Set;
      import java.util.stream.IntStream;

      public class Bug {
          public static BitSet toBitSet( final IntStream a ) { // convert IntStream to BitSet
              return a.collect( BitSet::new, BitSet::set, BitSet::or );
          }

          static final Set<BitSet> set = Set.of(
              toBitSet( IntStream.of( 7, 12, 19, 25, 26, 29, 55, 78, 103 ) ),
              toBitSet( IntStream.of( 7, 25, 55, 74, 78, 86, 99, 103, 111 ) ),
              toBitSet( IntStream.of( 4, 7, 20, 74, 78, 86, 107, 111, 119 ) ),
              toBitSet( IntStream.of( 7, 25, 38, 45, 55, 56, 59, 86, 111 ) ),
              toBitSet( IntStream.of( 11, 15, 23, 26, 30, 38, 107, 111, 119 ) ),
              toBitSet( IntStream.of( 11, 15, 23, 25, 26, 29, 59, 81, 107 ) ),
              toBitSet( IntStream.of( 23, 26, 48, 59, 67, 74, 81, 94, 107 ) ),
              toBitSet( IntStream.of( 7, 12, 19, 25, 26, 29, 55, 78, 103 ) ),
              toBitSet( IntStream.of( 19, 20, 23, 25, 26, 29, 103, 104, 107 ) ),
              toBitSet( IntStream.of( 7, 12, 19, 25, 38, 45, 55, 60, 67 ) ) );

          public static void main( String args[] ) {
              System.out.format( "set.size = %d%n", set.size() );
          } // main
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Explicitly adding elements to the set in a static block works.

      FREQUENCY : always


            asajeev Anjana Sajeev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: