3

我想使用 Powermock 模拟 GSSManager 进行单元测试。由于这个错误,当我做 mockStatic(GSSManager.class) 时它失败了:

java.lang.VerifyError: Bad return type
Exception Details:
  Location:
    org/ietf/jgss/GSSManager.getInstance()Lorg/ietf/jgss/GSSManager; @157: areturn
  Reason:
    Type 'sun/security/jgss/GSSManagerImpl' (current frame, stack[0]) is not assignable to 'org/ietf/jgss/GSSManager' (from method signature)
  Current Frame:
    bci: @157
    flags: { }
    locals: { 'java/lang/Object', null, 'sun/security/jgss/GSSManagerImpl', 'java/lang/Object' }
    stack: { 'sun/security/jgss/GSSManagerImpl' }

我不明白为什么。GSSManager 中的 getInstance 返回新的 GSSManagerImpl

我认为这可能是链接错误:

java.lang.LinkageError: loader constraint violation: when resolving overridden method "sun.security.jgss.GSSManagerImpl$$EnhancerByCGLIB$$3bcb7afc.getMechs()[Lorg/ietf/jgss/Oid;" the class loader (instance of org/powermock/core/classloader/MockClassLoader) of the current class, sun/security/jgss/GSSManagerImpl$$EnhancerByCGLIB$$3bcb7afc, and its superclass loader (instance of <bootloader>), have different Class objects for the type [Lorg/ietf/jgss/Oid; used in the signature
4

0 回答 0