2021年3月23日

PowerMock 报错:java.lang.IllegalAccessError

场景

使用 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

You may also like...

发表评论

邮箱地址不会被公开。 必填项已用*标注


*