mangstadt / biweekly

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

Crash in release build (NullPointerException: in == null) #98

Closed rt1shnik closed 4 years ago

rt1shnik commented 4 years ago

I get crash in my release build when try to use ICalendar. It works fine on debug build.

Caused by java.lang.NullPointerException: in == null
at java.util.Properties.load(Properties.java:246)
at biweekly.Biweekly.<clinit>(Biweekly.java:245)
at biweekly.property.ProductId.biweekly(ProductId.java:72)
at biweekly.ICalendar.<init>(ICalendar.java:173)

I think problem here:

static {
        InputStream in = null;
        try {
            in = Biweekly.class.getResourceAsStream("biweekly.properties");
            Properties props = new Properties();
            props.load(in);

            VERSION = props.getProperty("version");
            GROUP_ID = props.getProperty("groupId");
            ARTIFACT_ID = props.getProperty("artifactId");
            URL = props.getProperty("url");
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            IOUtils.closeQuietly(in);
        }
    }

I thnk proguard removed biweekly.properties file.

mangstadt commented 4 years ago

Yes, if the properties file can't be found, then that would cause an NPE to be thrown.

rt1shnik commented 4 years ago

@mangstadt Can you help to fix this?

mangstadt commented 4 years ago

Someone experienced a similar issue with another project of mine. See this thread:

https://github.com/mangstadt/ez-vcard/issues/98

Please let me know if this resolves your issue.

rt1shnik commented 4 years ago

@mangstadt I've added line below to proguard-rules.pro file to fix my issue. But I believe the more elegant and correct way exists to fix this.

-keep class biweekly.** { *; }
mangstadt commented 4 years ago

Thanks so much for sharing your solution!

If you discover a more elegant solution, I would love it if you would post it here, as I'm sure the Proguard/biweekly users would appreciate it. Since a solution was found, I will close this issue. Thanks again!