Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

got java.lang.ExceptionInInitializerError when calling SQLiteConfig.Pragma.values() #1123

Closed
ianhash opened this issue Jun 5, 2024 · 8 comments
Labels
bug Something isn't working released Issue has been released

Comments

@ianhash
Copy link
Contributor

ianhash commented Jun 5, 2024

Describe the bug
i got java.lang.ExceptionInInitializerError when calling SQLiteConfig.Pragma.values(), it seems there was an issue during the static initialization phase of the Pragma enum in the SQLiteConfig class

To Reproduce

  public static void main(String[] args) {

        SQLiteConfig.Pragma[] values = SQLiteConfig.Pragma.values();

        for (SQLiteConfig.Pragma value : values) {
            System.out.println(value);
        }
    }

sqlite-jdbc version >=3.25.2,here is 3.46.0.0

Expected behavior
just like sqlite-jdbc version <=3.23.1, it should print all SQLiteConfig.Pragma enum contants.

Logs
sqlite-jdbc version = 3.46.0.0

Exception in thread "main" java.lang.ExceptionInInitializerError
        at org.sqlite.SQLiteConfig$Pragma.<clinit>(SQLiteConfig.java:380)
        at mess.javamess.sqlite.SqliteConfigInit.main(SqliteConfigInit.java:15)
Caused by: java.lang.NullPointerException
        at org.sqlite.SQLiteConfig$Pragma.values(SQLiteConfig.java:376)
        at org.sqlite.SQLiteConfig.<clinit>(SQLiteConfig.java:357)
        ... 2 more

Environment (please complete the following information):

  • OS: MacOs m1
  • CPU architecture: arm64
  • sqlite-jdbc version >=3.25.2
  • java version: adoptopenjdk-8.jdk openjdk@11/11.0.23 openjdk 21.0.3 oracel jdk-22

Additional context

@ianhash ianhash added the triage label Jun 5, 2024
@gotson
Copy link
Collaborator

gotson commented Jun 5, 2024

Interesting. I have no idea why this happens, any insights are welcome.

@ianhash
Copy link
Contributor Author

ianhash commented Jun 5, 2024

Interesting. I have no idea why this happens, any insights are welcome.

I think there is a circular dependencies in static initialization ,

SQLiteConfig.class -> SQLiteConfig static block -> SQLiteConfig.Pragma -> SQLiteConfig.OnOff -> SQLiteConfig.class

I think the private static field OnOff needs to be extracted to another class,just like this:

   static class OnOff {
        private static final String[] OnOff = new String[] { "true", "false" };
    }

@gotson
Copy link
Collaborator

gotson commented Jun 5, 2024

i tried inlining the OnOff field and remove the field altogether, but the problem remains.

@gotson gotson added bug Something isn't working and removed triage labels Jun 5, 2024
@ianhash
Copy link
Contributor Author

ianhash commented Jun 5, 2024

i tried inlining the OnOff field and remove the field altogether, but the problem remains.

inlining MUST BE OK,

public class Foo {

    public static final Set<String> FOO_TYPES = new HashSet<>();

    private static final String[] OnOff = new String[] { "true", "false" };

    static {
        for (Foo.FooType v : Foo.FooType.values()) {
            FOO_TYPES.add(v.name());
        }
    }

    public static enum FooType {
        A(null),
        B(OnOff),  // BAD
        // B(new String[] { "true", "false" }) ,  // GOOD
        ;

        public final String[] choices;

        FooType(String[] onOff) {
            this.choices = onOff;
        }
    }
}

@ianhash
Copy link
Contributor Author

ianhash commented Jun 5, 2024

BTW: My suggestion is to extract OnOff into another class。

@gotson
Copy link
Collaborator

gotson commented Jun 6, 2024

inlining MUST BE OK,

i tested this with a unit test and it still fails. I don't see how extracting the class would be any different, if inlining the array does not work.

@ianhash
Copy link
Contributor Author

ianhash commented Jun 6, 2024

inlining MUST BE OK,

i tested this with a unit test and it still fails. I don't see how extracting the class would be any different, if inlining the array does not work.

The method toStringArray has same problem. this method is only called in class Pragma, so I moved it to Pragma.

please look into my pr #1124 for the details.

@gotson gotson closed this as completed in ec0a524 Jun 11, 2024
Copy link
Contributor

🎉 This issue has been resolved in 3.46.0.1 (Release Notes)

@github-actions github-actions bot added the released Issue has been released label Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released Issue has been released
Projects
None yet
Development

No branches or pull requests

2 participants