Scala, VerifyError при реализации службы OSGI с интерфейсом Java
Java абстрактные классы:
public abstract class ActionProcessorExtensionPoint<A extends Action<?>> extends ExtensionPoint
public abstract class ActionProcessorExtensionBase<A extends Action<?>> extends ActionProcessorExtensionPoint<A> {
protected final Log log = LogFactory.getLog(getClass());
private final Set<Class<? extends A>> supportedClasses;
public ActionProcessorExtensionBase(Class<? extends A> actionClass) {
supportedClasses = computeClasses(actionClass);
}
}
Класс Scala:
@Component(immediate = true)
@Provides(specifications = Array(classOf[ActionProcessorExtensionPoint[_ <:Action[T] forSome {type T}]]))
@Instantiate
class ActionPolicyDefinitionCreateProcessorExtension(
val actionClass: Class[ActionPolicyDefinitionCreate]
) extends ActionProcessorExtensionBase[ActionPolicyDefinitionCreate](actionClass) {
def this() {
this(classOf[ActionPolicyDefinitionCreate])
}
}
Ошибка:
[ActionPolicyDefinitionCreateProcessorExtension-0] createInstance -> The POJO constructor invocation failed : Bad type on operand stack
Exception Details:
Location:
ActionPolicyDefinitionCreateProcessorExtension.<init>(Lorg/apache/felix/ipojo/InstanceManager;Ljava/lang/Class;)V @2: invokevirtual
Reason:
Type uninitializedThis (current frame, stack[0]) is not assignable to 'ActionPolicyDefinitionCreateProcessorExtension'
Current Frame:
bci: @2
flags: { flagThisUninit }
locals: { uninitializedThis, 'org/apache/felix/ipojo/InstanceManager', 'java/lang/Class' }
stack: { uninitializedThis, 'java/lang/Class' }
Bytecode:
0x0000000: 2a2c b600 f02a 2cb7 00f2 2a2b b700 f6b1
0x0000010:
java.lang.VerifyError: Bad type on operand stack Exception Details: Location: ActionPolicyDefinitionCreateProcessorExtension.<init>(Lorg/apache/felix/ipojo/InstanceManager;Ljava/lang/Class;)V @2: invokevirtual
1 ответ
Решение
Проблема заключалась в ActionPolicyDefinitionCreateProcessorExtension, у которого не должно быть конструкторов с параметрами, если это компонент IPOJO. Решение переписывает это на:
@Component(immediate = true)
@Provides(specifications = Array(classOf[ActionProcessorExtensionPoint[_ <:Action[T] forSome {type T}]]))
@Instantiate
class ActionPolicyDefinitionCreateProcessorExtension
extends ActionProcessorExtensionBase[ActionPolicyDefinitionCreate](classOf[ActionPolicyDefinitionCreate]) { ... }