mangstadt / biweekly

biweekly is an iCalendar library written in Java.
BSD 2-Clause "Simplified" License
320 stars 44 forks source link

GraalVM Native Image compatibility #104

Closed Hixon10 closed 3 years ago

Hixon10 commented 3 years ago

Hello! Thank you for such amazing library.

I wanted to try your library with https://www.graalvm.org/reference-manual/native-image/. However, it does not work out the box. GraalVM is too young project, so it is OK.

So, I understand, that your library does not have any problems, and it is about bugs in GraalVM. However, if you would like to support this platform, you may to fix 2 places:

  1. We got NPE in this block of code:
    static {
        InputStream in = null;
        try {
            in = Biweekly.class.getResourceAsStream("biweekly.properties");
            Properties props = new Properties();
            props.load(in);
    }
    ///
    }

The reason is graalvm cannot load Biweekly.class.getResourceAsStream("biweekly.properties").

  1. We got ClassNotFoundException because of this code:

    private final transient ResourceBundle messages;
    
    Messages() {
        messages = ResourceBundle.getBundle("biweekly/messages");
    }

So, it is about resources in both cases. When I locally fixed it, biweekly perfectly started, as part of Native image.

mangstadt commented 3 years ago

Hi, thanks for posting!

How did you fix it? Maybe I can add the fix to biweekly.

Hixon10 commented 3 years ago

I did a dirty hacks :)

For in = Biweekly.class.getResourceAsStream("biweekly.properties"); I just inlined needed settings.

For Messages I created a class, which contains all biweekly/messages values.

But If you have vision, how these problems may be fixed, I can implement it and create a PR.

mangstadt commented 3 years ago

I am glad that solution worked for you, but I'd rather not move all that stuff into the code. :)

The fact that GraalVM can't read files from the classpath seems like a major deficiency to me. It is not uncommon for Java code to do that. 😕

Hixon10 commented 3 years ago

Yeah, I totally agree with you. I will try to contact with someone connected with GraalVM. Maybe, I did something wrong, or I need to use some flags for native-image tool.


Upd. https://github.com/oracle/graal/issues/2942