jollyday icon indicating copy to clipboard operation
jollyday copied to clipboard

Illegal us of internal JDK package

Open burberius opened this issue 5 years ago • 10 comments

I got the following errors when trying to run a test with openJDK 12. I guess the com.sun.xml package was removed.

Aug. 20, 2019 9:48:27 VORM. de.jollyday.util.XMLUtil unmarshallConfiguration
WARNUNG: Could not create JAXB context using the current threads context classloader. Falling back to ObjectFactory class classloader.

java.lang.IllegalStateException: Cannot instantiate configuration from URL 'jar:file:/home/me/.m2/repository/de/jollyday/jollyday/0.5.7/jollyday-0.5.7.jar!/holidays/Holidays_de.xml'.

	at de.jollyday.datasource.impl.XmlFileDataSource.getConfiguration(XmlFileDataSource.java:43)
	at de.jollyday.impl.DefaultHolidayManager.doInit(DefaultHolidayManager.java:209)
	at de.jollyday.HolidayManager.init(HolidayManager.java:319)
	at de.jollyday.caching.HolidayManagerValueHandler.createValue(HolidayManagerValueHandler.java:44)
	at de.jollyday.caching.HolidayManagerValueHandler.createValue(HolidayManagerValueHandler.java:13)
	at de.jollyday.util.Cache.lambda$get$0(Cache.java:43)
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705)
	at de.jollyday.util.Cache.get(Cache.java:43)
	at de.jollyday.HolidayManager.createManager(HolidayManager.java:166)
	at de.jollyday.HolidayManager.getInstance(HolidayManager.java:146)
[...]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.IllegalStateException: Cannot parse holidays XML file.
	at de.jollyday.util.XMLUtil.unmarshallConfiguration(XMLUtil.java:75)
	at de.jollyday.datasource.impl.XmlFileDataSource.getConfiguration(XmlFileDataSource.java:41)
	... 39 more
Caused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
 - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:177)
	at javax.xml.bind.ContextFinder.find(ContextFinder.java:364)
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:508)
	at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:465)
	at de.jollyday.util.XMLUtil$JAXBContextCreator.create(XMLUtil.java:121)
	at de.jollyday.util.XMLUtil.unmarshallConfiguration(XMLUtil.java:68)
	... 40 more
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
	at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
	at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:174)
	... 45 more

This could be related to #72

burberius avatar Aug 20 '19 08:08 burberius

Thanks for the hint. I'm working on modularizing jollyday to allow for different XML parsing framworks to be used. Please be patient as I'm doing this in my spare time.

svendiedrichsen avatar Sep 19 '19 20:09 svendiedrichsen

Why do you want to modularize it? For Android and normal systems? You can also use jackson-databind on Android, according so several posts I found. The JXB annotated class could be generated (at compile time) with xjc as described in the article I mentioned and then use those classes with Jackson Databind.

burberius avatar Sep 23 '19 06:09 burberius

I have had several different opinions on the usage of different frameworks for parsing XML.

Some cannot use JAXB classes (like on Android) or they don't want to add JAXB dependencies (for JDK >= 11). For those I think there should be an alternative without JAXB. This includes the generated classes as they carry JAXB annotations.

Some already have JAXB on their classpath and don't want additional dependencies like Jackson and its transitives to blow up their deployment size and/or have dependency collisions.

So to allow anyone to choose I think it is best to extract the XML parsing and allow each of it.

svendiedrichsen avatar Sep 23 '19 18:09 svendiedrichsen

I would suggest not to generate the classes at all but code them, I guess they will change rarely. So you don't have the JAXB annotations and are neutral for the binding implementation.

Then increase the JDK version to 9 and use Java modules for the implementation, as described here: https://labs.consol.de/development/2017/02/13/getting-started-with-java9-modules.html

So you have one maven module jollyday-base that defines an interface for a XML parser and also uses an implementation on the classpath to parse the XML data. And then for example a module jollyday-jackson that uses jackson-databind to implement the interface. Although it could be difficult to test the code then or at least it's a lot of work to change the tests accordingly.

Just shout when you need any help!

burberius avatar Sep 23 '19 19:09 burberius

thanks for your offer. i'll get back to you if i need some help then.

svendiedrichsen avatar Sep 23 '19 19:09 svendiedrichsen

Then increase the JDK version to 9 and use Java modules for the implementation

I know we are a little bit behind the update schedule, but OpenHAB (as a consument of this library) still depends on Java 8...

hakan42 avatar Sep 24 '19 11:09 hakan42

I'll keep it Java 8 compatible.

svendiedrichsen avatar Sep 24 '19 13:09 svendiedrichsen

@svendiedrichsen Is there any movement on this? I get the same error now while running 0.5.10 on JDK 12.

AlexBroadbent avatar Feb 18 '20 17:02 AlexBroadbent

@AlexBroadbent No, no progress so far. I haven't found time to do it.

svendiedrichsen avatar Feb 19 '20 22:02 svendiedrichsen

Adding "back"

<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-impl</artifactId>
  <version>2.2.3-1</version>
</dependency>

Seems to have fixed it for me

keyroii avatar Aug 17 '22 18:08 keyroii