gpt4 book ai didi

java.lang.LinkageError : loader constraint violation in interface itable initialization:

转载 作者:行者123 更新时间:2023-12-02 23:58:52 24 4
gpt4 key购买 nike

当我尝试模拟 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.*"}) 

没有任何作用。

最佳答案

基于cited issue的场景我想出了一个解决方法:问题出现在 javax.swing.text.JTextComponent 的静态初始化程序中,因此我们可以使用 @SuppressStaticInitializationFor("抑制该代码"javax.swing.text.JTextComponent").

这是一个工作测试用例(使用 Powermock 1.6.4):

import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mock;

import javax.swing.JOptionPane;
import javax.swing.JTextArea;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest(JOptionPane.class)
@SuppressStaticInitializationFor("javax.swing.text.JTextComponent")
public class PowerMockIssue {
@Test
public void powermockTest() {
final JTextArea textArea = mock(JTextArea.class);
when(textArea.getText()).thenReturn("test");
Assert.assertEquals("test", textArea.getText());
}
}

关于java.lang.LinkageError : loader constraint violation in interface itable initialization:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33821615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com