shivaraju
shivaraju

Reputation: 39

Issue while upgrade from jdk1.8 to 11 com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl could not be instantiated

We are using Springboot 2.5.14 and using mockito3.11.2 and powermock core, module-junit4, api-mockito2 and api-support 2.0.2 version dependencies. After upgrading jdk8 to 11 my test cases got failed and getting below exception. Please find below. tried @PowerMockIgnore({"javax.net.ssl.", "org.slf4j.", "javax.parsers.", "ch.qos.logback.", "jdk.xml.internal.", "com.sun.org.apache.xerces.", "javax.xml.", "org.xml.", "javax.management.*"}) but not working. Please help me on this

Caused by: javax.xml.transform.TransformerFactoryConfigurationError: Provider com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl could not be instantiated: java.lang.reflect.InvocationTargetException
    at java.xml/javax.xml.transform.FactoryFinder.newInstance(FactoryFinder.java:181)
    at java.xml/javax.xml.transform.FactoryFinder.find(FactoryFinder.java:257)
    at java.xml/javax.xml.transform.TransformerFactory.newInstance(TransformerFactory.java:126)
    at org.springframework.http.converter.xml.AbstractXmlHttpMessageConverter.(AbstractXmlHttpMessageConverter.java:54)
    at org.springframework.http.converter.xml.AbstractJaxb2HttpMessageConverter.(AbstractJaxb2HttpMessageConverter.java:38)
    at org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter.(Jaxb2RootElementHttpMessageConverter.java:64)
    at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.(AllEncompassingFormHttpMessageConverter.java:86)
    at org.springframework.web.client.RestTemplate.(RestTemplate.java:161)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
    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:566)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 80 more
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at java.xml/javax.xml.transform.FactoryFinder.newInstance(FactoryFinder.java:169)
    ... 98 more
Caused by: java.lang.IllegalAccessError: class com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl (in unnamed module @0x7bf4dffe) cannot access class jdk.xml.internal.JdkXmlUtils (in module java.xml) because module java.xml does not export jdk.xml.internal to unnamed module @0x7bf4dffe
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.(TransformerFactoryImpl.java:251)
    ... 103 more


Process finished with exit code -1

And we used code like this

@PrepareForTest({SchemaRegistryAdapter.class,Validator.class})
@RunWith(PowerMockRunner.class)
@PowerMockIgnore({"javax.net.ssl.*", "org.slf4j.*", "javax.parsers.*", "ch.qos.logback.*", "jdk.xml.internal.*", "com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
@PowerMockRunnerDelegate(SpringRunner.class)
@ActiveProfiles("test")
//@PropertySources(value = { @PropertySource("classpath:/application-test.yml") })
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = { TestConfig.class, AppConfiguration.class,SchemaRegistryAdapter.class})
@ImportAutoConfiguration(RefreshAutoConfiguration.class)
public class SchemaRegistryAdapterTest {

}

Upvotes: 1

Views: 3881

Answers (1)

Thiago Henrique Hupner
Thiago Henrique Hupner

Reputation: 492

Try adding --add-exports=java.xml/jdk.xml.internal=ALL-UNNAMED to your command line

Upvotes: 0

Related Questions