简体   繁体   中英

PowerMockito tests moved from JDK 1.6 to JDK 1.7 are getting constraint violations

We have some tests that had been working fine with JDK 1.6. We're now moving to JDK 1.7. These tests work fine in Eclipse. When we run these tests from our Ant build, we're seeing errors like this:

junit.framework.TestListener: addError(<testmethodname>, loader constraint violation:
when resolving overridden method 
"com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Lorg/w3c/dom/Node;)Ljava/lang/Object;"
the class loader (instance of org/powermock/core/classloader/MockClassLoader) of the current class,
com/sun/xml/bind/v2/runtime/unmarshaller/UnmarshallerImpl, and its superclass loader (instance of <bootloader>),
have different Class objects for the type
com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(Lorg/w3c/dom/Node;)Ljava/lang/Object; used in the signature)

We were using PowerMockito 1.5 when we first saw this. I just tried upgrading to 1.5.4 and all the relevant dependencies, and that resulted in no change.

This shows the class annotations we're using:

@RunWith(PowerMockRunner.class)
@PowerMockIgnore({ "javax.xml.*", "org.xml.sax.*" })
@PrepareForTest(<classundertest>.class)
public class <classundertest>Test extends MockServiceBase {

What might be the problem here?

Last night I finally found the workaround for this. The key was to add additional package masks to the “@PowerMockIgnore” annotation. Just about the first thing I tried was adding "com.sun.xml. ". I had thought that didn't make any difference, but I think it simply fixed the tests that referred to that package. The remaining references were to “com.sun.org. ”, and I didn't realize that. When I finally also added “com.sun.org.*”, it fixed the remaining tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM