svendiedrichsen / jollyday

Jollyday - A holiday API
Other
186 stars 116 forks source link

Jollyday fails with Java 16 #148

Open alexoooo opened 3 years ago

alexoooo commented 3 years ago

Jollyday uses JAXB to read the configuration XML, this results in illegal access violations. In Java 16 some of the illegal access violations that used to be flagged as warnings have been escalated to errors.

I was able to get around the issue using XStream instead of JAXB, first exporting the config using Java 15:

ManagerParameter parameter = ManagerParameters.create(calendarPart);
Configuration configuration = HolidayManager.getInstance(parameter).getConfigurationDataSource().getConfiguration(parameter);
String export = new XStream().toXML(configuration);

Then replace the contents of Holidays_[x].xml with the XStream format, and load them back with Java 16:

HolidayManager manager = new DefaultHolidayManager();
manager.setConfigurationDataSource(new XStreamConfigurationDataSource());

ManagerParameter parameter = ManagerParameters.create(calendarPart);
new ConfigurationProviderManager().mergeConfigurationProperties(parameter);
manager.init(parameter);

private static class XStreamConfigurationDataSource implements ConfigurationDataSource {
    @Override
    public Configuration getConfiguration(ManagerParameter managerParameter) {
        URL resourceUrl = managerParameter.createResourceUrl();
        try (InputStream inputStream = resourceUrl.openStream()) {
            return (Configuration) new XStream().fromXML(inputStream);
        }
        catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
}
fanste commented 3 years ago

I'm able to run jollyday on JDK 16 and JAXB as long as a JAXB implementation is available on the classpath. In my case I used the newer implementation from Jakarta (see https://eclipse-ee4j.github.io/jaxb-ri/)

    <!--dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
        <version>3.0.0</version>
    </dependency-->
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>3.0.0</version>
        <scope>runtime</scope>
    </dependency>

The Jakarta compatible jollday artifact is produced by a fixed pom.xml which could be found in the pull request #150.

But it should also work with jaxb-impl version 2.x which still uses the legacy javax namespace (totally untested).