PowerMock 报错:java.lang.IllegalAccessError
- Java
- 2021-03-23
- 348热度
- 0评论
场景
使用 PowerMock 时,运行 UT 出错。
部分报错内容如下:
class javax.xml.parsers.FactoryFinder (in unnamed module @0x6280b1e8) cannot access class jdk.xml.internal.SecuritySupport (in module java.xml) because module java.xml does not export jdk.xml.internal to unnamed module @0x6280b1e8
java.lang.IllegalAccessError: class javax.xml.parsers.FactoryFinder (in unnamed module @0x6280b1e8) cannot access class jdk.xml.internal.SecuritySupport (in module java.xml) because module java.xml does not export jdk.xml.internal to unnamed module @0x6280b1e8
at javax.xml.parsers.FactoryFinder.<clinit>(FactoryFinder.java:69)
at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:147)
解决方案
在测试类上添加注解:
@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
参考:https://github.com/mockito/mockito/issues/1562