Uploaded image for project: 'Code Tools'
  1. Code Tools
  2. CODETOOLS-7903608

Cyclic initialization leads to NPE in header class with global variable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • None
    • None
    • tools
    • None

      Consider this header:

      ```
      int global;
      ```

      Which is extracted with the option: -Djextract.decls.per.header=0
      (this forces each new declaration to be put in a different header class).

      Now consider this Java program using the generated output:

      ```
      import java.lang.foreign.ValueLayout;

      class TestGensrc {
          public static void main(String[] args) {
              ValueLayout layout = foo_h.C_INT;
          }
      }
      ```

      This program fails:

      ```
      Exception in thread "main" java.lang.ExceptionInInitializerError
      at TestGensrc.main(TestGensrc.java:5)
      Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.foreign.MemoryLayout.varHandle(java.lang.foreign.MemoryLayout$PathElement[])" because "foo_h_1.global$LAYOUT" is null
      at foo_h_1.<clinit>(foo_h_1.java:16)
      ... 1 more
      ```

            mcimadamore Maurizio Cimadamore
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: