当我尝试模仿JTextField
时,我收到此错误。
java.lang.LinkageError: loader constraint violation in interface itable
initialization: when resolving method
"javax.swing.text.JTextComponent$1.dropLocationForPoint(
Ljavax/swing/text/JTextComponent;Ljava/awt/Point;)Ljavax/
swing/TransferHandler$DropLocation;" the class loader (instance of
org/powermock/core/classloader/MockClassLoader) of the current
class, javax/swing/text/JTextComponent$1, and the class loader
(instance of <bootloader>) for interface
sun/swing/SwingAccessor$JTextComponentAccessor have different Class
objects for the type mponent$1.dropLocationForPoint(Ljavax/swing/text/
JTextComponent;Ljava/awt/Point;)Ljavax/swing/TransferHandler$
DropLocation; used in the signature
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:191)
at javassist.runtime.Desc.getClassObject(Desc.java:43)
我试着用这个:
@PowerMockIgnore( {"javax.management.*","javax.security.*","javax.ws.*"})
没有任何效果。
答案 0 :(得分:1)
根据cited issue的情况,我提供了一种解决方法:问题出现在javax.swing.text.JTextComponent
的静态初始值设定项中,因此我们可以使用{{ 来抑制该代码1}}。
这是一个工作测试用例(使用Powermock 1.6.4):
@SuppressStaticInitializationFor("javax.swing.text.JTextComponent")